Why can't I import this?

John Henry john106henry at hotmail.com
Tue May 13 18:22:44 EDT 2008


On May 13, 1:49 pm, Gary Herron <gher... at islandtraining.com> wrote:
> John Henry wrote:
> > Hi list,
>
> > I can't understand this.  The following import statement works fine:
>
> >     from PythonCard.templates.dialogs import runOptionsDialog
>
> > but this one fails:
>
> >     from PythonCard.tools.codeEditor.codeEditor import CodeEditor
>
> This kind of "dotted" name import only works for packages, and a
> directory is considered a package only if it contains a file name
> __init__.py.    Looking around my installation of PythonCard (on Linux)
> I see that most of those directories *do NOT* have a __init__.py, so
> they are not packages and cannot be imported that way.
>
> Of course this leaves unanswered the question of *how* you are supposed
> to import that code.   I've never used PythonCard so I can't help
> further, but I suggest looking at the documentation and examples
> supplied.  And perhaps waiting for someone with experience with
> PythonCard to answer.
>
> Gary Herron
>
> P.S. It is usually a waste of time to tell us that something fails
> without telling us *how* it fails.  (Cut and paste the error message
> always, and the traceback usually.)  If you don't, you will usually get
> a request to supply that information, and then have wast3ed the time for
> one full round of message to the group.  Even in this case, I'm only
> guessing how it failed for you.
>
> > I've checked and rechecked to make sure that the spellings are proper
> > and that the tools, the codeEditor directory, and codeEditor.py, and
> > the class CodeEditor all exists and yet idle keep complaining that it
> > can't import from PythonCard.tools.
>
> > What's going on?  (Running Python2.5 under WinXP).
>
> > Regards,
> > --
> >http://mail.python.org/mailman/listinfo/python-list

Thank you very much.  I didn't know about the __init__.py
requirement.  Appreciate it.



More information about the Python-list mailing list