Hi all,
I'm a real beginner with python but have what I think is a simple question.
I am writing some simple modules and would like to place them into a
subdirectory. But then I cannot seem to import them. I have tried the
following.
I wrote a module called fibo.py with some definitions in it (one called
fibo). In the same directory, I wrote another file (test.py) and began with
import fibo. This worked fine and I was able to use the function fibo as
fibo.fibo. Then, I made a directory called test and placed the file fibo.py
in this directory. I also placed a blank file called _init_.py into this
directory. I went back to the original directory and tried to import
test.fibo but this fails. I get the following error message:
Traceback (innermost last)
File "...test.py", line 1, in ?
import test.fibo
File "...test.py", line 1, in ?
import test.fibo
ImportError: No module named fibo
Any help would be greatly appreciated. If it makes any difference, I'm
working on a Mac, OSX 10.3.9
Thanks,
David 3 3504
that should be __init__.py [TWO underscores].
and you might want to import sys and check sys.path [the list of
directories searched by the import mechanism].
David Jackson wrote:
Hi all,
I'm a real beginner with python but have what I think is a simple question.
I am writing some simple modules and would like to place them into a
subdirectory. But then I cannot seem to import them. I have tried the
following.
I wrote a module called fibo.py with some definitions in it (one called
fibo). In the same directory, I wrote another file (test.py) and began with
import fibo. This worked fine and I was able to use the function fibo as
fibo.fibo. Then, I made a directory called test and placed the file fibo.py
in this directory. I also placed a blank file called _init_.py into this
directory. I went back to the original directory and tried to import
test.fibo but this fails. I get the following error message:
Traceback (innermost last)
File "...test.py", line 1, in ?
import test.fibo
File "...test.py", line 1, in ?
import test.fibo
ImportError: No module named fibo
Any help would be greatly appreciated. If it makes any difference, I'm
working on a Mac, OSX 10.3.9
Thanks,
David
David Jackson wrote:
Hi all,
I'm a real beginner with python but have what I think is a simple question.
I am writing some simple modules and would like to place them into a
subdirectory. But then I cannot seem to import them. I have tried the
following.
I wrote a module called fibo.py with some definitions in it (one called
fibo). In the same directory, I wrote another file (test.py) and began with
import fibo. This worked fine and I was able to use the function fibo as
fibo.fibo. Then, I made a directory called test and placed the file fibo.py
in this directory. I also placed a blank file called _init_.py into this
directory. I went back to the original directory and tried to import
test.fibo but this fails. I get the following error message:
Traceback (innermost last)
File "...test.py", line 1, in ?
import test.fibo
File "...test.py", line 1, in ?
import test.fibo
ImportError: No module named fibo
python is trying to import fibo from test.py not test directory. since
you have both test.py and test directory, it is using the first one.
try to rename your directory name to something else and try. that
should work.
Also you should do
from test import fibo
Anand
Indeed you are correct...that is indeed TWO underscores and everything works
fine now. Thanks for pointing out the obvious...I thought it was a simple
problem. --DJ
"faulkner" <fa*********@comcast.netwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
that should be __init__.py [TWO underscores].
and you might want to import sys and check sys.path [the list of
directories searched by the import mechanism].
David Jackson wrote:
>Hi all,
I'm a real beginner with python but have what I think is a simple question. I am writing some simple modules and would like to place them into a subdirectory. But then I cannot seem to import them. I have tried the following.
I wrote a module called fibo.py with some definitions in it (one called fibo). In the same directory, I wrote another file (test.py) and began with import fibo. This worked fine and I was able to use the function fibo as fibo.fibo. Then, I made a directory called test and placed the file fibo.py in this directory. I also placed a blank file called _init_.py into this directory. I went back to the original directory and tried to import test.fibo but this fails. I get the following error message:
Traceback (innermost last) File "...test.py", line 1, in ? import test.fibo File "...test.py", line 1, in ? import test.fibo ImportError: No module named fibo
Any help would be greatly appreciated. If it makes any difference, I'm working on a Mac, OSX 10.3.9
Thanks, David
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Stian Søiland |
last post by:
all examples performed with:
Python 2.3+ (#2, Aug 10 2003, 11:09:33)
on linux2
(2, 3, 0, 'final', 1)
This is a recursive import:
|
by: Vio |
last post by:
Hi,
I've been trying to embed (statically) wxPy alongside an embedded py
interpreter on a linux/gtk box.
At one point, for some reason misc.o linking reported "multiple
definitions of...
|
by: Steve Holden |
last post by:
This is even stranger: it makes it if I import the module a second time:
import dbimp as dbimp
import sys
if __name__ == "__main__":
dbimp.install()
#k = sys.modules.keys()
#k.sort()
#for...
|
by: Ron Adam |
last post by:
from __future__ import absolute_import
Is there a way to check if this is working? I get the same results with or
without it.
Python 2.5 (r25:51908, Sep 19 2006, 09:52:17)
on win 32
...
|
by: rsoh.woodhouse |
last post by:
Hi,
I'm trying to work out some strange (to me) behaviour that I see when
running a python script in two different ways (I've inherited some
code that needs to be maintained and integrated with...
| |
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,...
|
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,...
|
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: 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...
|
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...
|
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...
| |
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
| |