List Info

Thread: Why can't I import this?




Why can't I import this?
user name
2006-11-28 23:45:14
I just discovered something for Tkinter that I want to use.
It's a 
Tooltip class, at <http:/
/tkinter.unpythonic.net/wiki/ToolTip> .

I've copied it to a file I named toolTipDemo.py and put it
with a 
couple of other files I use as modules. They're in
E:Python25Libsite-packagesmine. One file there is
intSpell.py, 
and I can import it by

from mine.intSpell import intSpell

With no problem:
 >>> from mine.intSpell import intSpell
 >>>
However, the same method of importing doesn't work with
toolTipDemo:
 >>> from mine.toolTipDemo import toolTipDemo
Traceback (most recent call last):
   File "<string>", line 1, in
<string>
ImportError: cannot import name toolTipDemo

I've tried various things, such as remarking out the whole
demo at 
the bottom, but leaving

if __name__ == '__main__':
     #demo()
     pass

Any ideas on what I've done wrong?

BTW, toolTipDemo.py runs fine at the command line. I.e., the
demo 
shows up nicely, with 2 tooltips.

Thanks,

Dick Moores

_______________________________________________
Tutor maillist  -  Tutorpython.org
http://
mail.python.org/mailman/listinfo/tutor
Why can't I import this?
user name
2006-11-29 03:20:05
Dick Moores wrote:
> I just discovered something for Tkinter that I want to
use. It's a 
> Tooltip class, at <http:/
/tkinter.unpythonic.net/wiki/ToolTip> .
> 
> I've copied it to a file I named toolTipDemo.py and put
it with a 
> couple of other files I use as modules. They're in
> E:Python25Libsite-packagesmine. One file there is
intSpell.py, 
> and I can import it by
> 
> from mine.intSpell import intSpell
> 
> With no problem:
>  >>> from mine.intSpell import intSpell
>  >>>
> However, the same method of importing doesn't work with
toolTipDemo:
>  >>> from mine.toolTipDemo import toolTipDemo
> Traceback (most recent call last):
>    File "<string>", line 1, in
<string>
> ImportError: cannot import name toolTipDemo

Try
from mine.toolTipDemo import demo

mine.toolTipDemo points to the module, then you need to
reference a name 
defined in the module. (You must have something called
intSpell in 
intSpell.py.)

Kent

_______________________________________________
Tutor maillist  -  Tutorpython.org
http://
mail.python.org/mailman/listinfo/tutor
Why can't I import this?
user name
2006-11-29 03:32:54
At 07:20 PM 11/28/2006, Kent Johnson wrote:
>Dick Moores wrote:
> > I just discovered something for Tkinter that I
want to use. It's a
> > Tooltip class, at <http:/
/tkinter.unpythonic.net/wiki/ToolTip> .
> >
> > I've copied it to a file I named toolTipDemo.py
and put it with a
> > couple of other files I use as modules. They're in
> > E:Python25Libsite-packagesmine. One file there
is intSpell.py,
> > and I can import it by
> >
> > from mine.intSpell import intSpell
> >
> > With no problem:
> >  >>> from mine.intSpell import intSpell
> >  >>>
> > However, the same method of importing doesn't work
with toolTipDemo:
> >  >>> from mine.toolTipDemo import
toolTipDemo
> > Traceback (most recent call last):
> >    File "<string>", line 1, in
<string>
> > ImportError: cannot import name toolTipDemo
>
>Try
>from mine.toolTipDemo import demo
>
>mine.toolTipDemo points to the module, then you need to
reference a name
>defined in the module. (You must have something called
intSpell in
>intSpell.py.)

Interestingly (or not) it just hit me that I should try
that, and it 
worked. So I suppose that if I want to use tooltips in a
Tkinter 
program, I can just use  "from mine.toolTipDemo import
*" and use 
what I need. (Haven't tried that yet, however.)

Thanks, Kent.

Dick

_______________________________________________
Tutor maillist  -  Tutorpython.org
http://
mail.python.org/mailman/listinfo/tutor
Why can't I import this?
user name
2006-11-29 03:48:50
Dick Moores wrote:
> At 07:20 PM 11/28/2006, Kent Johnson wrote:
>> Try
>>from mine.toolTipDemo import demo
>> mine.toolTipDemo points to the module, then you
need to reference a name
>> defined in the module. (You must have something
called intSpell in
>> intSpell.py.)
> 
> Interestingly (or not) it just hit me that I should try
that, and it 
> worked. So I suppose that if I want to use tooltips in
a Tkinter 
> program, I can just use  "from mine.toolTipDemo
import *" and use 
> what I need. (Haven't tried that yet, however.)

Yes, you can do that but in general that style is not
recommended. It 
makes it hard to figure out where names are defined and you
can import 
more than you really want. Better is to just import what you
want, e.g.
from mine.toolTipDemo import A, b, CC

or import the module with an alias:
import mine.toolTipDemo as TTD

then refer to e.g.
TTD.demo()

Kent

_______________________________________________
Tutor maillist  -  Tutorpython.org
http://
mail.python.org/mailman/listinfo/tutor
Why can't I import this?
user name
2006-11-29 06:44:43
At 07:48 PM 11/28/2006, Kent Johnson wrote:
>Dick Moores wrote:
> > At 07:20 PM 11/28/2006, Kent Johnson wrote:
> >> Try
> >>from mine.toolTipDemo import demo
> >> mine.toolTipDemo points to the module, then
you need to reference a name
> >> defined in the module. (You must have
something called intSpell in
> >> intSpell.py.)
> >
> > Interestingly (or not) it just hit me that I
should try that, and it
> > worked. So I suppose that if I want to use
tooltips in a Tkinter
> > program, I can just use  "from
mine.toolTipDemo import *" and use
> > what I need. (Haven't tried that yet, however.)
>
>Yes, you can do that but in general that style is not
recommended. It
>makes it hard to figure out where names are defined and
you can import
>more than you really want. Better is to just import what
you want, e.g.
>from mine.toolTipDemo import A, b, CC

Thanks, Kent. Turns out all I needed was the class, ToolTip.
So just

from mine.toolTipDemo import ToolTip

will do it.

>or import the module with an alias:
>import mine.toolTipDemo as TTD
>
>then refer to e.g.
>TTD.demo()

A good trick.

Thanks very much, Kent.

Dick



_______________________________________________
Tutor maillist  -  Tutorpython.org
http://
mail.python.org/mailman/listinfo/tutor
[1-5]

about | contact  Other archives ( Real Estate discussion Medical topics )