Function - How do I get global variables in Python

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

   This question already has an answer here:
    * /questions/10814452/how-can-i-access-global-variable-inside-class-in-python /questions/10814452/how-can-i-access-global-variable-inside-class-in-python 3 answers

Answers

You should use global:

def aFunction():
    global aVariable
    aVariable = 5

aVariable = 9
aFunction()
print aVariable #print 5

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/23686622/how-do-i-get-global-variables-in-python

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils