473,465 Members | 1,458 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

module placeholder

Once again I'm working on code that has several 'providers' of
different features, and I thought I'd ask the list what better
solutions it has to this other than what I've come up with.

Currently, the cleanest way I can find is to say

import foo
foo.config(bar='baz')
# from this point on, foo.bar is provided by foo.bars.baz

this could be widget sets, database connectors, persistance layers,
RPC, you name it. This is very easy to do:

# foo.py
def config(bar_name=DEFAULT_BAR_NAME):
global bar
bar = __import__('foo.' + bar_name, globals(), locals(),
bar_name)

This would work fine if people wanted to use this (once its configured)
as 'import foo; foo.bar.funkyFunction()', but no! they want to be able
to do 'from foo.bar import funkyFunction', which is reasonable really
because I'm just as lazy as they are.

So what I've come up with is

def config(bar_name=DEFAULT_BAR_NAME):
global bar
barModule = __import__('foo.' + bar_name, globals(), locals(),
bar_name)
bar.faultFrom(barModule)

class proxyModule(new.module):
def faultFrom(self, other):
self.__other = other
self.__name__ = other.__name__
self.__file__ = other.__file__ + ' [proxied]'
def __getattr__(self, attr):
return getattr(self.__other, attr)

bar = proxyModule('bar proxy')

and this is the bit that feels ugly: is there a better way to have an
object that can be imported from a file and that behaves like a module,
but that isn't filled in until some point down the road?

Jul 19 '05 #1
0 1157

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

Similar topics

0
by: Markus Franz | last post by:
Hi. Some URLs are passed to a python script as command line options like the following command ../script.py http://www.websites1.com http://www.website2.com (The number of passed URLs...
2
by: Markus Franz | last post by:
Hi. Some URLs are passed to a python script as command line options like the following command ../script.py http://www.websites1.com http://www.website2.com (The number of passed URLs...
0
by: John Lenton | last post by:
Once again I'm working on code that has several 'providers' of different features, and I thought I'd ask the list what better solutions it has to this other than what I've come up with. ...
2
by: Mike Speak | last post by:
I have a user control that I want to use to render 4 menu items (retrieved from db) on the top of each of my asp.net pages. The user control defines a table, with one TR and one TD. Within the...
0
by: shark | last post by:
I have a placeholder in a control that is in turn, used as a control in a placeholder in a form. I am getting a viewstate error so I believe I have to clear my placeholder before I load the...
1
by: Angel | last post by:
I have added controls to the placeholder control. All the controls that were added have EnableViewState = true including the placeholder. One of the controls has a button that performs a postback. My...
6
by: David Colliver | last post by:
Hi, using vb.net 1.1 I am trying to add a control to a placeholder but am having problems with it. I do it practically the same way as i do in C# (I have more C# skill than VB.NET)and I...
13
by: André | last post by:
Hi, i'm developping asp.net applications and therefore i use VB.net. I have some questions about best practises. According what i read about class and module and if i understand it right, a...
40
by: rjcarr | last post by:
Sorry if this is a completely newbie question ... I was trying to get information about the logging.handlers module, so I imported logging, and tried dir(logging.handlers), but got: ...
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
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,...
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
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...
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: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.