Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Need a hint on customizing import of modules

Reply
Thread Tools

Need a hint on customizing import of modules

 
 
F. GEIGER
Guest
Posts: n/a
 
      06-08-2004
Hi all,

I use Leo for programming. Among other goodies Leo provides it let's me
easily share code between different Python apps. When I have an app
consisting of more than one file, they usually do

from other import AClassOfIt
import yetanother

When I then want to investigate a specific problem I share code with a
lab file, e.g. LabByOpenGL.py. This app is flat then, i.e. it does not
need to

from other import AClassOfIt
import yetanother

because all classes of other are flattened into LabPyOpenGL.py.

So I have to write within LabPyOpenGL.py

try:
from other import AClassOfIt
except ImportError:
pass # Assume it being w/i this module

Instantiation of AClassOfIt now works in both worlds, i.e. in the
"structured" app and in the flat app.

But what should I do with

import yetanother ?

When code is used from yetanother, it is ref'ed like so:

myUseful = yetanother.UseFullClass()

This does not work in the flat file, because yetanother could not be
imported.

So I thought of something like

try:
import yetanother
except ImportError:
yetanother = __module__ # alas, does not work

which then would make calls like

myUseful = yetanother.UseFullClass()

possible as before.

Any hint how I shall proceed? Should I consider writing an import hook?
How would such a beast look like?

Many thanks in advance
Franz GEIGER
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
need hint for refactoring GHUM Python 1 08-09-2006 01:16 PM
need a hint Podrzut_z_Laweczki C++ 5 08-06-2006 06:09 AM
First ruby code, need hint on iterator Gerr Ruby 4 07-17-2006 07:46 PM
imputils - import problem modules from sys.modules Remy Cool Python 1 08-27-2003 02:25 PM



Advertisments