[Tutor] Calling a module function in another class..........

Magnus Lyckå magnus@thinkware.se
Fri May 2 06:01:01 2003


At 20:34 2003-05-01 -0700, perl lover wrote:
>hi,
>    How to call a member function of one module from
>another class function?

Just like you did. But functions in a module are
typically not called "member functions". For me, a
member function sounds like a function in a class,
what we usually call a method. A function defined
globally in a module is just a function, plain and
simple.

>def print_mousepos(self,event):
>         print self.canvas.event.x,self.canvas.event.y

But this you should change to "print event.x,event.y"
Right? self.canvas has no event attribute. You (or rather
Tkinter) passes the event in as parameter, right?

>         Now how can i rectify this error and call a member
>function of a module in another calss?

Remove that other "classtest.py" that "import" finds before
it finds your file. Or do a reload (see the previous thread
about that) if that's what you need. After the fix above,
your program works for me.

If the code you mailed is the complete program, the imported
classtest is not the code you showed. It's either another
file, or a different version of that file. I still feel it's
better to run programs from the command line than from inside
an ide...

If you are in fact only showing an excerpt of a file, you might
have slipped in a "classtest = ..." somewhere, so that it now
refers to something different than the module.

So, when will it say "python lover" in that email address? ;)

/Magnus

P.S. "Python-tutor lover" is fully acceptable. It will probably
give you priority in the mail queue... ;^)


--
Magnus Lycka (It's really Lyckå), magnus@thinkware.se
Thinkware AB, Sweden, www.thinkware.se
I code Python ~ The shortest path from thought to working program