473,513 Members | 2,661 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

import

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
Jul 5 '06 #1
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
Jul 5 '06 #2

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

Jul 6 '06 #3
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

Jul 7 '06 #4

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

Similar topics

0
6893
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:
0
2557
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...
5
2456
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...
7
20533
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 ...
9
2097
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...
0
7257
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
7379
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,...
0
7535
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...
1
7098
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...
1
5084
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...
0
4745
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...
0
3232
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...
0
3221
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1591
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 ...

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.