Why can't I import this?

Gary Herron gherron at islandtraining.com
Tue May 13 16:49:44 EDT 2008


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
>   




More information about the Python-list mailing list