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
olamundo
  • 23,991
  • 34
  • 108
  • 149

1 Answers1

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

or

cat.name = 'mittens'
Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
  • 2
    @FogleBird: Sure, but not if you don't know that "global scope" is the same as "module scope". – Ignacio Vazquez-Abrams Mar 09 '10 at 04:15
  • 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) – olamundo Mar 09 '10 at 04:23
  • Lots of things are obvious once you know them -- if you don't know, ask! :) – Ethan Furman Oct 07 '11 at 00:46