2

I know this is very evil, but is it possible to add an object to another module's globals, something like:

#module dog.py
import cat
cat.globals.addVar('name','mittens')

and

#module cat.py
print name #mittens

1 Answer 1

2
setattr(cat, 'name', 'mittens')

or

cat.name = 'mittens'
Sign up to request clarification or add additional context in comments.

3 Comments

@FogleBird: Sure, but not if you don't know that "global scope" is the same as "module scope".
now that you write it, it seems so obvious I feel a little embarrassed :) but yes, it wasn't clear to me that if you define cat.name then you can access it from inside cat (though in retrospect it's obvious)
Lots of things are obvious once you know them -- if you don't know, ask! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.