473,395 Members | 1,496 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,395 software developers and data experts.

Adding objects to __builtins__


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 curious thing is that when i try from the interactive interpreter the
thing just works:
def a(): .... print "ciao"
.... a() ciao __builtins__.b = a
b() ciao


But i've tried inside a script, recalling objects from other imported
modules, they cannot see them.
Does exist a way to do this, or is just a stupid thing?

Thank you
matteo merli

Jul 18 '05 #1
1 1766
Matteo Merli wrote:
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 curious thing is that when i try from the interactive interpreter the
thing just works:


Does this help?
import __builtins__ Traceback (most recent call last):
File "<stdin>", line 1, in ?
ImportError: No module named __builtins__ import __builtin__


By the way, you *really* shouldn't use this as a "convenient"
way of getting global variables or other things around to your
various modules. That would be almost the worst thing for
code maintainability that you could do. You'll come to hate
yourself for doing it, down the road.

There are some valid use cases for doing such a thing, but
sticking just any old function in there is not it.

-Peter
Jul 18 '05 #2

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

Similar topics

0
by: David M. Wilson | last post by:
Hello, I have a C program embedding the Python interpreter, and loading a new module like so: exim_module = PyImport_ExecCodeModule("__exim__", compiled_module); The program then forks a...
1
by: Michael Hohn | last post by:
Hi, using the file builtin_check.py with content # Module builtin_check # Inconstency in the binding of __builtins__ def get_binding(name): return locals() def get_global_binding(name):
26
by: Uwe Mayer | last post by:
Hi, I've been looking into ways of creating singleton objects. With Python2.3 I usually used a module-level variable and a factory function to implement singleton objects. With Python2.4 I...
5
by: Negroup | last post by:
Hi all. I'm writing a simple Python module containing functions to process strings in various ways. Actually it works importing the module that contains the function I'm interested in, and calling...
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...
5
by: dananrg | last post by:
In PythonWin, is there any way to bulk-delete all objects without using "del object" for each, and without having to exit out of PythonWin?
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...
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,...
0
by: Patrick Maupin | last post by:
__builtins__ in 2.5.2 doesn't seem to behave like I remember it did the last time I did some custom stuff with it, a very long time ago. This isn't surprising, because of ongoing optimization,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...

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.