global variable not assigned, newbie question

Diez B. Roggisch deetsNOSPAM at web.de
Mon Nov 1 09:52:04 EST 2004


You need myNum to be declared global:
 
def setNum():
    global myNum
    myNum = 10
    print myNum

Apart from that, its usually considered bad style using global variables -
better use this:

def calcNum():
    myNum = 10
    return myNum

myNum = calcNum()


-- 
Regards,

Diez B. Roggisch



More information about the Python-list mailing list