static variables

BartC bc at freeuk.com
Mon Nov 30 15:32:26 EST 2015


On 30/11/2015 17:15, Ulli Horlacher wrote:
> def main():
>    a(1)
>    a(2)
>    a()
>    print(a.x)
>    if 'a.x' in globals(): print('global variable')
>    if 'a.x' in locals():  print('local variable')

Try this:

    if 'x' in a.__dict__:  print('attribute of a')

-- 
Bartc



More information about the Python-list mailing list