Python Gotcha's?

Cameron Simpson cs at zip.com.au
Thu Apr 5 20:02:35 EDT 2012


On 05Apr2012 19:13, Alain Ketterlin <alain at dpt-info.u-strasbg.fr> wrote:
| Miki Tebeka <miki.tebeka at gmail.com> writes:
| > (Note that I want over http://wiki.python.org/moin/PythonWarts already).
| 
| The "local variable and scoping" is, imho, something to be really
| careful about. Here is an example:
| 
| class A(object):
|     def __init__(self):
|         self.x = 0
|     def r(self):
|         return x # forgot self
| 
| a = A()
| x = 1
| print a.r() # prints 1
| 
| I know there is "no remedy". It's just really tricky.

Whoa!

I presume this jost happens with globals and not with one function
calling another... (I guess I should test that instead of asking such a
dumb question).
-- 
Cameron Simpson <cs at zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/

You see, wire telegraph is a kind of a very, very long cat. You pull his tail
in New York and his head is meowing in Los Angeles. Do you understand this?
And radio operates exactly the same way: you send signals here, they receive
them there. The only difference is that there is no cat.
- Albert Einstein, when asked to describe radio



More information about the Python-list mailing list