473,405 Members | 2,160 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,405 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 3492
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
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...

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.