Why can't I import this?

John Henry john106henry at hotmail.com
Tue May 13 20:22:59 EDT 2008


On May 13, 3:42 pm, Gary Herron <gher... at islandtraining.com> wrote:
> John Henry wrote:
> > 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.
>
> Actually I should have added that there ways to import such things, and
> PythonCard must be using some such method itself.  You can manipulate
> the sys.path variable, or directly call the import mechanism using the
> builtin __import__, or use a suppled "imp" module.    However, you
> should not have to do any such thing to use PythonCard.  It should do
> them in for you.

I tried to call __import__ directly and didn't work neither.

What I was doing is to invoke their codeEditor directly into my
application.  Their codeEditor was designed to be a stand alone
application and that's why it didn't include the file you cited.

I never quite understood what they were saying about __init__.py but
now I understand.  Learn something new every day.

Thanks again.



More information about the Python-list mailing list