This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2012年08月11日 00:19 by Mark.Janssen, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Messages (2) | |||
|---|---|---|---|
| msg167928 - (view) | Author: zipher (Mark.Janssen) | Date: 2012年08月11日 00:19 | |
>>> num = 1 >>> def t1(): print num >>> t1() 1 >>> def t2(): ... num+=1 ... print num >>> t2() UnboundLocalError: local variable 'num' referenced before assignment It seems num is bound in t1, but not t2, even though they are the same scope. Am I missing something? |
|||
| msg167929 - (view) | Author: R. David Murray (r.david.murray) * (Python committer) | Date: 2012年08月11日 01:01 | |
In t2, you assign to num. That makes it local. In t1, you don't, so num is picked up from the global scope. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:34 | admin | set | github: 59826 |
| 2012年08月11日 01:01:08 | r.david.murray | set | status: open -> closed nosy: + r.david.murray messages: + msg167929 resolution: not a bug stage: resolved |
| 2012年08月11日 00:19:20 | Mark.Janssen | create | |