473,397 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Using the __builtins__ module to assign new global variables

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.
Jul 18 '05 #1
1 1783
Opinder wrote:
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).

--
-Scott David Daniels
Sc***********@Acm.Org
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Rasjid Wilcox | last post by:
Hi, I found references on Google to a discussion a little while ago about using RestrictedPython instead of rexec and Bastion. But I've had trouble finding documentation. Below is my test...
0
by: Mathieu Fenniak | last post by:
Good day, I'm writing an application which creates modules and runs Python code on the fly, embedding Python. The main function of the code is loaded into the __main__ module: (Error checking...
1
by: Matteo Merli | last post by:
Hi, is there a way to save objects in the __builtins__ namespace? the goal is to make them available in all the modules of my app, without reimporting all the things and keep references... The...
4
by: Collin Winter | last post by:
Hallo all, As it currently stands, the type of the global __builtins__ differs depending on whether you're in the __main__ namespace (__builtins__ is a module) or not (its a dict). I was...
1
by: Adam Hupp | last post by:
I've noticed some unexpected behavior with __builtins__ during module import. It seems that during module import __builtins__ is a dict but at all other times it is a module. For example, if...
4
by: carl.dhalluin | last post by:
Hello I am completely puzzled why the following exec code does not work: mycode = "import math\ndef f(y):\n print math.floor(y)\nf(3.14)" def execute(): exec mycode execute()
3
by: loquehumaine | last post by:
Hi there, I'm a newby in python (I know a little in programmation) and I have a lot of questions on builtins but my first one is about modules... I have seen that if I type help() at a prompt,...
1
by: cokofreedom | last post by:
if __name__ == '__main__': print "Globals (For Loop):" try: for i in globals(): print "\t%s" % i except RuntimeError: print "Only some globals() printed\n" else: print "All globals()...
0
by: Lie Ryan | last post by:
On Tue, 30 Sep 2008 16:04:34 -0500, William Purcell wrote: when you pass mydict, it is used as the global variables in the eval, right? Then, you passed a code to eval('...', mydict), sometimes...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.