ImportError: cannot import name - newbie
Steven Bethard
steven.bethard at gmail.com
Sat May 21 13:46:11 EDT 2005
qwejohn at hotmail.com wrote:
> """box.py"""
>
> class box:
> def __init__(self):
> print "in box"
>
> This program passes running "python box.py".
>
> I had put this program under /work/dev/mytests/new
>
> Now I want to use it from a second python program, which
> resides in a totally different path.
>
> I had tried , in a program named test.py,
> """test.py"""
> sys.path = [ '/work/dev/mytests' ] + sys.path
> from new import box
When you say "from new import box", you're saying something like "from
the package new, import the module box". Which means that you need to
indicate that the "new" directory is a package. To do this, place an
empty file called "__init__.py" in the "new" directory (along with
"box.py"). Python should then be able to identify "new" as a package,
and find the "box" module inside of it.
HTH,
STeVe
More information about the Python-list
mailing list