Morpheus Tutorial #20 : Gültigkeit von Variablen
Verfasst: Dienstag 12. November 2019, 16:42
Hallo @ all,
bei mir ( Windows 10, Python 2.7 ) funktioniert das hier nicht ( so wie bei Morpheus ) :
195 def fvartest():
196 def tstlocal():
197 tstvar = "local text "
198 def do_nonlocal():
199 nonlocal tstvar = 'non local text'
200 tstvar = 'non local text'
201 def do_global():
202 global tstvar
203 tstvar = 'global text'
204 tstvar = "text "
205 tstlocal()
206 do_nonlocal()
207 do_global()
208 print("after init:" , tstvar )
fvartest()
print("global", tstvar )
File "First_Try_with_comments.py", line 199
nonlocal tstvar = 'non local text'
^
SyntaxError: invalid syntax
Die Einrückungen werden nicht angezeigt, sind aber richtig !
Offensichtlich gibt es "nonlocal" als Schlüsselwort nicht.
Kann mir jemand helfen warum ? Geht das bei der Version 2.7 nicht ?
Wie geht es dann ?
Gruß, HLech65730
bei mir ( Windows 10, Python 2.7 ) funktioniert das hier nicht ( so wie bei Morpheus ) :
195 def fvartest():
196 def tstlocal():
197 tstvar = "local text "
198 def do_nonlocal():
199 nonlocal tstvar = 'non local text'
200 tstvar = 'non local text'
201 def do_global():
202 global tstvar
203 tstvar = 'global text'
204 tstvar = "text "
205 tstlocal()
206 do_nonlocal()
207 do_global()
208 print("after init:" , tstvar )
fvartest()
print("global", tstvar )
File "First_Try_with_comments.py", line 199
nonlocal tstvar = 'non local text'
^
SyntaxError: invalid syntax
Die Einrückungen werden nicht angezeigt, sind aber richtig !
Offensichtlich gibt es "nonlocal" als Schlüsselwort nicht.
Kann mir jemand helfen warum ? Geht das bei der Version 2.7 nicht ?
Wie geht es dann ?
Gruß, HLech65730