473,473 Members | 2,164 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

dynamically adding some of one module's functions to another

Hello everyone,

I'm trying to import some modules into another's namespace (network_utils)

network_utils.py:

import utils
import constants as main_const
from services import constants as srv_const
from plugins import constants as plg_const

#
# Import all the message creation functions
#
f = dict([ (f, eval("utils." + f)) for f in dir(utils) if
f.startswith("create") ])
__builtins__.update(f)
del utils

#
# Create a virgin namespace
#
class constants:
"""
An aggragation of L{constants},
L{services.constants}, &
L{plugins.constants}
"""
pass

#
# Import all the constants into the new namespace
#
f = dict([ (f, eval("main_const." + f)) for f in dir(main_const) if
f.isupper() ])
constants.__dict__.update(f)
del main_const
f = dict([ (f, eval("srv_const." + f)) for f in dir(srv_const) if
f.isupper() ])
constants.__dict__.update(f)
del srv_const
f = dict([ (f, eval("plg_const." + f)) for f in dir(plg_const) if
f.isupper() ])
constants.__dict__.update(f)
del plg_const
now, if I import network_utils somewhere, and try to call
network_utils.myFunction() I get :
>>import network_utils
network_utils.myFunction
Traceback (most recent call last):
File "<console>", line 1, in <module>
AttributeError: 'module' object has no attribute 'myFunction'

but if I try to access the constants class:
>>from network_utils import constants
constants.NO_DATA_TYPE
'none'

it works, how come?

Thank you,
Gabriel

Aug 26 '08 #1
0 724

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

Similar topics

11
by: Steven D'Aprano | last post by:
Suppose I create a class with some methods: py> class C: .... def spam(self, x): .... print "spam " * x .... def ham(self, x): .... print "ham * %s" % x .......
4
by: Bas Groeneveld | last post by:
I am developing an ASP.NET application part of which consists of a data entry wizard defined by entries in a data table - ie the controls on each page of the wizard are determined by definitions in...
15
by: Amit D.Shinde | last post by:
I am adding a new picturebox control at runtime on the form How can i create click event handler for this control Amit Shinde
7
by: Steve_Black | last post by:
Hello, I'm toying with the idea of loading a MenuStrip (VB.Net 2005) dynamically based on who is logged into my system. Every user has different security settings and I want to customize the...
4
by: Bill Nguyen | last post by:
I would like to include a module from another project. When I added existing item, VS copied the module to the current project's folder so that whatever I did to this module doesn't reflect in the...
7
by: Bob Stearns | last post by:
Is there an option in php to do a 'require xxx.php' if, when a function call to xxx is encountered, it is not defined? It would look in all the standard places.
94
by: smnoff | last post by:
I have searched the internet for malloc and dynamic malloc; however, I still don't know or readily see what is general way to allocate memory to char * variable that I want to assign the substring...
11
by: Nadeem | last post by:
Hello all, I'm trying to write a function that will dynamically generate other functions via exec. I then want to be able to import the file (module) containing this function and use it in other...
1
by: semomaniz | last post by:
I have a form where i have created the form dynamically. First i manually added a panel control to the web page. Then i added another panel dynamically and inside this panel i created tables. I have...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
1
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.