Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #100901
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2015-12-26 20:11 -0800 |
| References | <d070aa0d-e80f-4efb-a424-351737ddb2fc@googlegroups.com> <mailman.17.1451101449.11925.python-list@python.org> <701dd0e6-a9c1-4aa9-a3a2-6607cd3f3759@googlegroups.com> <mailman.19.1451123395.11925.python-list@python.org> <661a13a1-8084-41ca-b458-297462dc3367@googlegroups.com> |
| Message-ID | <0bf611ba-c4d9-4465-8d61-6a94bcee79a4@googlegroups.com> (permalink) |
| Subject | Re: A newbie quesiton: local variable in a nested funciton |
| From | jfong@ms4.hinet.net |
Last night I noticed that Python does not resolve name in "def" during import, as C does in the compile/link stage, it was deferred until it was referenced (i.e. codes was executed). That's OK for Anyway codes has to be debugged sooner or later. I just have to get used to this style.
But check these codes, it seems not.
-------
x = 1 # a global variable
print(x)
class Test:
x = 4 # a class attribute
print(x)
def func(self):
print(x)
x1 = Test()
x1.x = 41 # a instance's attribute
x1.func() # it's 1 but 41 was expect:-(
--------
--Jach
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
A newbie quesiton: local variable in a nested funciton jfong@ms4.hinet.net - 2015-12-25 19:06 -0800
Re: A newbie quesiton: local variable in a nested funciton Ben Finney <ben+python@benfinney.id.au> - 2015-12-26 14:41 +1100
Re: A newbie quesiton: local variable in a nested funciton jfong@ms4.hinet.net - 2015-12-26 00:56 -0800
Re: A newbie quesiton: local variable in a nested funciton Ben Finney <ben+python@benfinney.id.au> - 2015-12-26 20:37 +1100
Re: A newbie quesiton: local variable in a nested funciton Chris Angelico <rosuav@gmail.com> - 2015-12-26 14:44 +1100
Re: A newbie quesiton: local variable in a nested funciton jfong@ms4.hinet.net - 2015-12-26 01:07 -0800
Re: A newbie quesiton: local variable in a nested funciton Chris Angelico <rosuav@gmail.com> - 2015-12-26 20:49 +1100
Re: A newbie quesiton: local variable in a nested funciton jfong@ms4.hinet.net - 2015-12-26 20:05 -0800
Re: A newbie quesiton: local variable in a nested funciton jfong@ms4.hinet.net - 2015-12-26 20:11 -0800
Re: A newbie quesiton: local variable in a nested funciton Chris Angelico <rosuav@gmail.com> - 2015-12-27 17:32 +1100
Re: A newbie quesiton: local variable in a nested funciton jfong@ms4.hinet.net - 2015-12-27 17:02 -0800
Re: A newbie quesiton: local variable in a nested funciton Chris Angelico <rosuav@gmail.com> - 2015-12-27 17:22 +1100
csiph-web