Using the __builtins__ module to assign new global variables

O

Opinder

Hi,

For the Python experts out there:

Are there any side effects in assigning new variables to the
__builtins__ module for the purpose of exposing variables to imported
modules.

For example.

#/ main file

class Test: pass

mytest = Test() #/ instance of a class
__builtins__.mytest = mytest

import abc


#/ -----------------------
#/ This is the abc.py module file
#/ This should work because of the __builtins__ above
print mytest

Thanks.
 
S

Scott David Daniels

Opinder said:
Are there any side effects in assigning new variables to the
__builtins__ module for the purpose of exposing variables to imported
modules.

Generally, Guido frowns at you very sternly. Also, you could
cause a disaster if there is a conflict between your idea of what
should be a global and some other module's idea. You will be in
big trouble if a builtin is added that you over-write (actually
a form of the same problem).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top