473,327 Members | 2,055 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,327 software developers and data experts.

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 3488
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
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
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
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
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
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
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.