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

Need a hint on customizing import of modules

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
Jul 18 '05 #1
0 1009

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

Similar topics

10
by: Jeff Wagner | last post by:
I am in the process of learning Python (obsessively so). I've been through a few tutorials and read a Python book that was lent to me. I am now trying to put what I've learned to use by rewriting...
3
by: Peter Schwalm | last post by:
I'd like to modify the python search path depending on the source directory of the script being started. The reason is: I use a version control system, and the python scripts and modules are...
0
by: John Roth | last post by:
I've found a case where it seems that Python is importing two copies of a module without any reason or indication. It took me a while to verify that this is what is occuring: I had to write a...
4
by: Nicolas Fleury | last post by:
Hi, I'm trying to support two Python versions at the same time and I'm trying to find effective mechanisms to support modules compiled in C++ transparently. All my code in under a single...
5
by: passion_to_be_free | last post by:
Okay, so in my li'l python script I'm importing a few 3rd party modules that I have installed on my comp. I need to distribute this script to several other people, but I won't have access to...
3
by: praveenkumar.117 | last post by:
Hi All, What is the difference between import string and from string import * Regards, Praveen
11
by: Connelly Barnes | last post by:
Hi, I wrote the 'autoimp' module , which allows you to import lazy modules: from autoimp import * (Import lazy wrapper objects around all modules; "lazy modules" will turn into normal...
10
by: Jia Lu | last post by:
Hi all: I try to do things below: import i Traceback (most recent call last): File "<pyshell#67>", line 2, in <module> import i ImportError: No module named i But it seems that import...
10
by: Thomas Guettler | last post by:
If you look at this code, you see there are two kind of ImportErrors: 1. app_name has no attribute or file managment.py: That's OK. 2. managment.py exists, but raises an ImportError: That's not...
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: 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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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.