globals: a dirty little secret?

Michal Wallace (sabren) sabren at manifestation.com
Thu Apr 20 03:29:59 EDT 2000


Globals have come up a couple times recently.. If someone posted the
following approach, I missed it...


### step 1: globals.py #######################

import __builtin__

def setGlobal(key, value):
   __builtin__.__dict__[key] = value

__builtin__.setGlobal = setGlobal # makes the above function global



## step 2: your program ######################

import globals
setGlobal("x", 5)

print x

##############################################


Whatcha think?


Cheers,

- Michal
-------------------------------------------------------------------------
http://www.manifestation.com/         http://www.linkwatcher.com/metalog/
-------------------------------------------------------------------------





More information about the Python-list mailing list