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

Playing with modules

I know that this is not particularly "pythonic", but I would like to
mess with modules a bit.

I would like to develop a modular module which allows different
services to plug themselves into the module and become the
implementation for a named module.

Say I have a suite of "cassidy.blah.blah.blah...." modules. As it's not
really my intention to brand everything, I want to remap all these
modules as "home....". Thus if someone (eventually) likes my code for
x, but does not want the whole cassidy avalanche, and just wants
something simple to do home.x, they can provide their own
implementation or create a wrapper class to existing functionality
which does the work.

My problem is that this code fails all the time that I have tried to do
this.

import home.base

Does anybody know of a way to "fool" python into thinking that my suite
is actually this neutrally named suite called "home"?

Thanks,

John

Feb 24 '06 #1
4 993
You're going to have to create the home.base module somewhere. If you
want to put in that some code that basically imports another module's
namespace into the home.base module's namespace, then that may do what
you want.

Feb 25 '06 #2
> You're going to have to create the home.base module somewhere. If you
want to put in that some code that basically imports another module's
namespace into the home.base module's namespace, then that may do what
you want.


Thanks, Jonathon, but I think I've tried what you are saying. I've
tried doing this a couple different ways.

I suppose that what I could do is go somewhat explicit, and instead of
trying to exploit the natural import language, create a method for this
such as home.use('base') which could use even use the tracestack, get
the current frame's globals and stick the entry { 'base': <module
'cassidy.base' from 'C:\Dev\Python24\lib\cassidy\base\__init__.pyc'> }
into the currect scope and just make that part of the "API".

But I was wondering whether I could fool or "backend" the normal import
mechanism. Even in Java, I can write my own class loader which can
quick compile Java snippets and load the anonymous byte code.

Thanks,

John

Feb 25 '06 #3
jj*******@gmail.com wrote:
You're going to have to create the home.base module somewhere. If you
want to put in that some code that basically imports another module's
namespace into the home.base module's namespace, then that may do what
you want.

Thanks, Jonathon, but I think I've tried what you are saying. I've
tried doing this a couple different ways.


What did you try? You should be able to write home/__init__.py to import
whatever parts of cassidy.blah... you like and define the name base to
be a reference to some part of cassidy.

But I was wondering whether I could fool or "backend" the normal import
mechanism. Even in Java, I can write my own class loader which can
quick compile Java snippets and load the anonymous byte code.


See http://www.python.org/doc/2.3/whatsn...on-pep302.html

Kent
Feb 25 '06 #4
Kent Johnson wrote:
jj*******@gmail.com wrote:
But I was wondering whether I could fool or "backend" the normal import
mechanism. Even in Java, I can write my own class loader which can
quick compile Java snippets and load the anonymous byte code.


See http://www.python.org/doc/2.3/whatsn...on-pep302.html

Kent


Thanks. That one helped. Just to get me started looking at
test_importhooks.py in the dist.
Mar 15 '06 #5

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

Similar topics

4
by: Brian Basquille | last post by:
Hello all, What is the syntax for simply playing a WAV file in your program? Am learning VB and have two VB books but don't wanna root through them to find the code. Any help would be much...
3
by: Rob Andrews | last post by:
I'm on a Red Hat 9 system, which has Python 2.2.2 installed, and I installed 2.3 separately into /home/rob/Python-2.3/ (creating the symbolic link "py23" to point to my 2.3 installation). Now I'm...
15
by: Nick Coghlan | last post by:
Python 2.4's -m command line switch only works for modules directly on sys.path. Trying to use it with modules inside packages will fail with a "Module not found" error. This PEP aims to fix that...
1
by: Peter Schmitz | last post by:
Hi, I'm just trying to play a *.wav file, making use of the unmanaged function "sndPlaySoundA" in winmm.dll, but I still got one question: How can I avoid, that the sound file itself has to be...
4
by: Misto . | last post by:
Hi folks! Short: There is a way to dumplicate a module ? I tried copy.deepcopy(module) but hangs with an error (also with standard modules ).. The only solution that I have by now is...
6
by: MLH | last post by:
I've followed the instructions found on Microsoft's site... http://support.microsoft.com/default.aspx?scid=kb;en-us;149119&Product=acc97 Here are those instructions... To play and record...
7
by: Lauren Quantrell | last post by:
At running the risk of asking how big is too big... Is there a rule of thumb or a best practice that says I may have too many modules? I currently have a Access2K app with about 30 code modules,...
7
by: Lee Moody | last post by:
I just want quick and easy way to play a .wav file out the standard sound device. It could even be as simple as activating a sound assigned to an existing windows sound event. Any suggestions?...
14
by: askMe | last post by:
I developed a web page that plays an mpg using the simple embed tag. When the page loads, the video starts, but then stops after a few seconds. I use the embed tag because I want the user's...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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...
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
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...

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.