problem in the compiler ?

Glauco Silva glauco.silva at cenpra.gov.br
Tue May 3 11:19:06 EDT 2005


The call of MyClass isn´t in this order... i only want to explain that i´m
calling the class 'MyClass' and when i do this the function "Function" is
call when the compiler pass for the RadioButton.
The same happened when i used Pmw.RadioSelect.
I solve this problem now using this:
radio = Pmw.RadioSelect()
radio.bind('<ButtonRelease>', self.Function)

if i use :
Pmw.RadioSelect(command = self.Function)

the 'Function' is call.
And i think that this is wrong and i only want to tell to help solve this
bug.

so, my code is this:
file : MyClass.py
    import Pmw
    class MyClass:
        def __init__(self):
            radio = Pmw.RadioSelect()
            radio.bind('<ButtonRelease>', self.Function)
            #Pmw.RadioSelect(command = self.Function)

        def Funciton(self):
            print "Enter in the Function"

    if __name__ == '__main__' :
        MyClass()

when i call in the console like this:
    C:\python MyClass.py

if i using in the __init__ this :
    Pmw.RadioSelect(command = self.Function)

so the string "Enter in the Function"  is print

Thank you
Glauco





----- Original Message ----- 
From: "Scott David Daniels" <Scott.Daniels at Acm.Org>
To: <python-list at python.org>
Sent: Tuesday, May 03, 2005 11:21 AM
Subject: Re: problem in the compiler ?


Glauco Silva wrote:
> python : 2.3.5
> os: win 2K
This part is good enough (though sometimes it helps to mention the
service pack number
on windows systems).

> My code is like this:
>
> MyClass()
>
> class MyClass:
>      def __init__(self):
>          btn = RadioButton(command=self.Function)
>      def Function(self):
>          print "Enter in the function"

This is not good enough.  Show us a small actual example that exhibits
the problem behavior on your machine.  Often in the course of doing this
distillation, the original problem will become clear to you.  The code
above fails with:

Traceback (most recent call last):
   File "<pyshell#0>", line 1, in -toplevel-
     MyClass()
NameError: name 'MyClass' is not defined

on the initial call to MyClass().  I suspect this is not what you care
about.

Don't make people trying to help you do any work you cannot do yourself.
Imagine yourself browsing the newsgroup and trying to decide whether to
spend some time trying to help someone with a problem.  Would _you_ want
to spend time trying to guess what the code was with the problem as well
as what the problem was, or would you decide to help someone else out?

--Scott David Daniels
Scott.Daniels at Acm.Org




-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.11.2 - Release Date: 2/5/2005




More information about the Python-list mailing list