[python-uk] TDD stuff in London, next two weeks (and list comprehension scoping)

John Pinner funthyme at gmail.com
Sun Jun 1 02:12:01 CEST 2014


Hello All,

On 31 May 2014 23:02, Michael Foord <fuzzyman at voidspace.org.uk> wrote:
>
> On 31 May 2014, at 11:13, Jonathan Hartley <tartley at tartley.com> wrote:
>
>> That's what I thought too, but:
>>
>> $ python3
>> Python 3.4.0 (default, Apr 19 2014, 12:20:10)
>> [GCC 4.8.1] on linux
>> Type "help", "copyright", "credits" or "license" for more information.
>> >>> class Some(object):
>> ...   tokens = ['a', 'b', 'c']
>> ...   untokenized = [Some.tokens.index(a) for a in ['b']]
>> ...
>> Traceback (most recent call last):
>>   File "<stdin>", line 1, in <module>
>>   File "<stdin>", line 3, in Some
>>   File "<stdin>", line 3, in <listcomp>
>> NameError: name 'Some' is not defined
>>
>
> The name Some is not bound until the class body has finished executing.

or maybe (correct me if I'm wrong) until the interpreter has finished
compiling the class (which does not happen until the end of the class
definition has been reached).

> You should just be able to access the name "tokens" from inside the class body though:
>
<snips>

All the best,

John
--


More information about the python-uk mailing list