Why can't I import this?

J

John Henry

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

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,
 
D

Diez B. Roggisch

John said:
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

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.

How do these complaints *look* - we can't read your mind nor your
screen, as you might imagine....
What's going on? (Running Python2.5 under WinXP).

What do you think is more probable - pythons import-mechanism, the
foundation of nearly all libraries, is broken - or you make a mistake?

Diez
 
J

John Henry

How do these complaints *look* - we can't read your mind nor your
screen, as you might imagine....


What do you think is more probable - pythons import-mechanism, the
foundation of nearly all libraries, is broken - or you make a mistake?

Diez

Thumper's dad always told him: If you don't have anything nice/useful/
garbage to say, then don't say noth'ng at all.

Next.
 
G

Gary Herron

John said:
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.
 
D

Diez B. Roggisch

Thumper's dad always told him: If you don't have anything nice/useful/
garbage to say, then don't say noth'ng at all.

You mean it's not useful to tell you


- to give more information on *what* acutally goes wrong?

- in the meantime, to look harder for your mistake, because it's
unlikely to be python's failure?


Can't help you then. Won't happen again.

Diez
 
J

John Henry

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.

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

Gary Herron

John said:
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.
 
J

John Henry

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top