[Python-de] Re: local variable referenced before assignment?

[email protected] (Stefan Ram)
Newsgroups gmane.comp.python.general.german
Organization Stefan Ram
Message-ID <[email protected]>
Ulli Horlacher <[email protected]> writes:
>Ich bekomme diesen Fehler und verstehe ihn nicht:

>    config()
>  File "./fextasy.py", line 496, in config
>    sg.I(server,key='server',tooltip='F*EX server',size=80)],
>UnboundLocalError: local variable 'server' referenced before assignment

>Der Sourcecode dazu ist:

>def read_config():
>  global server,user,aid,tmpdir,ddir
>  server = user = aid = ''
>(...)

>def config():
>  read_config()

>  col = [
>    [sg.I(server,key='server',tooltip='F*EX server',size=80)],


>Die globale Variable server wird also in read_config() gesetzt.
>Wieso wird die dann in config() als lokale variable behandelt?

  Weil in der Funktion "config" hinter der letzten zitierten
  Zeile (mit "size=80") eine Zuweisung an "server" enthalten
  ist, ohne daß in "config" "server" vor der ersten Verwendung
  in "config" mit "global server" deklariert wurde.

_______________________________________________
python-de Mailingliste -- [email protected]
Zur Abmeldung von dieser Mailingliste senden Sie eine Nachricht an [email protected]
https://mail.python.org/mailman3/lists/python-de.python.org/
Mitgliedsadresse: [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.