473,570 Members | 2,862 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help: Trouble with imp.load_module

I'm not entirely sure what's going on here, but I suspect it's related
to my general lack of knowledge of the python import internals.

Here's the setup:

module: tester.py:
-----------------
import imp
def loader(mname, mpath):
fp, pathname, description = imp.find_module (mname,[mpath])
try:
m = imp.load_module (mname, fp, pathname, description)
finally:
if fp:
fp.close()
return m

module = loader("testA", "/path/to/testA/)
print module.test_fun c("/path/to/something")

module = loader("test.B" ,"/path/to/test.B/")
print module.test_fun c("/path/to/something")
------------------
module: testA.py:
---------------
def test_func(v):
import os
return os.path.exists( v)
---------------

module: test.B.py:
---------------
def test_func(v):
import os
return os.path.exists( v)
---------------
Okay, so modules "testA.py" and "test.B.py" are functionally identical,
except for the name of the module files themselves, and this is the
important part. The tester.py module is a really simple rig to run
"imp.load_modul e" on those two files.

You should get no problem running the first test of module "testA.py"
but you should get a traceback when attempting to run the second module
"test.B.py" :

Traceback (most recent call last):
File "tester.py" , line 15, in ?
print module.test_fun c("/path/to/something")
File "./test.B.py", line 2, in test_func
import os
File "/usr/lib/python2.4/os.py", line 131, in ?
from os.path import curdir, pardir, sep, pathsep, defpath, extsep,
altsep
ImportError: No module named path
So this must have something to do with the "." in the name of module
"test.B.py" but what is the problem, exactly? And how do I solve it? I
will sometimes need to run load_module on filenames which happen to have
"." in the name somewhere other than the ".py" extension. Is the
find_module somehow thinking this is a package?

Any help would be appreciated,
-Dave

--
Presenting:
mediocre nebula.
Dec 11 '07 #1
0 2281

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

Similar topics

0
1920
by: Jim | last post by:
I need some help getting started with a .NET web project for a commercial site. I am new to .NET and my understanding of some (but not all) of its concepts is a little sparse. I apologize for the length of this message, but hopefully it will help someone here give me the most concise and useful information, and perhaps help others out as...
20
5619
by: andy.rich | last post by:
I am getting the following error and I do not know why. Can anyone help? -------------------------------------------------------- this is what appears on the screen -------------------------------------------------------- 2Sports 'trouble shooting illustrated 'trouble shooting Newsstand 'trouble...
4
2104
by: Josh | last post by:
Howdy i am newb somewhat to programing and i was just for fun trying to compile a program that asks the user for an odd int less than 22 and then returns this ***************** ******* ********* ****** ******** ***** ******* etc. the first line reps. the number enterd by user but i am having trouble i can get the first line but am...
6
508
by: Don Sealer | last post by:
I've written this expression for a DLookup function. It works almost alright. What I'm trying to do is type in a description and the ID field (number) populates automatically. It works almost as I've said. It doesn't populate until I go to a new record. Then if I go back to the record the number is in the field. Instead of populating...
15
2272
by: carr4895 | last post by:
Hello. I was wondering if someone could help me too with a login form. Upon startup, I have to display a password screen and it should accept a user name and password. User name can be anything non-blank. If there is no user name, an appropriate error message must be displayed. All of the following passwords are valid IT160, VB2Manager,...
4
1659
by: Tim Chase | last post by:
Trying to get my feet wet with wxPython (moving from just command-line apps), I tried the obvious (or, at least to me was obvious): Start python, "import wx" and then do a "help(wx)" to see what it can tell me. Unfortunately, it spewed back a handful of errors, gasped, wheezed and died semi-hideously.
1
8559
by: JWest46088 | last post by:
I am having trouble figuring out how to add, subtract, multiply, and divide fractions in my Java program. First off I will tell you what I already did. At first, the assignment was to: Define a class called Rational. This class is used to represent a ratio of two integers. Include mutator functions that allow the user to set the numerator...
3
2398
by: mikemcleod | last post by:
Hello everyone, Long time lurker, first time poster. I'm trying to implement an AJAX inline editor and am having some trouble. I want to use this editing field several times on the same page, and was hoping to make the JavaScript reusable, passing it the name of the fields that need to change, but I'm having some trouble. In particular,...
1
1848
by: Paul Sijben | last post by:
I am running into a problem with the python interpreter's internals. For some reason imp.load_module insists on getting a real open file as the second parameter. I have not able to fool it with stringIO or overloaded file objects. So now I have two questions: 1) why does load_module insist on a real file 2) is there a way around it that...
0
7948
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8150
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7700
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8000
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6329
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5523
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5247
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2131
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 we have to send another system
1
1238
muto222
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.