intricated functions: how to share a variable

TP Tribulations at Paralleles.invalid
Wed Aug 5 08:33:03 EDT 2009


Bearophile wrote:

> So probably a better solution is to just use the normal function
> semantics: you pass them an argument and you take an argument as
> return value. Such return value will be the new version of the value
> you talk about.

Thanks for your answer.
Yes, it is better like this. My problem is that I cannot get the return
values of the function and affect it to some variable, because the function
is called via a "signal-slot" connection of PyQt4, not by an explicit
inline function call.

For example:
#########
def tutu():

    def toto():

        print a
        a = 4
        print a

    a=2

    # ...
    # definition of some graphical QPushButton "button"
    # ...
    # ...

    self.connect( button, SIGNAL( "clicked" ), toto )

tutu()
##########

Then, as advised Diez, perhaps the best solution is to have "true" global
variables by using a class and defining the variable a as a member self.a
of the class. By doing like this, a will be known everywhere.

Julien
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\
9&1+,\'Z4(55l4('])"

"When a distinguished but elderly scientist states that something is
possible, he is almost certainly right. When he states that something is
impossible, he is very probably wrong." (first law of AC Clarke)



More information about the Python-list mailing list