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
On 30/05/14 16:07, Sven Marnach wrote:
On 30 May 2014 15:49, Harry Percival <[email protected] <mailto:[email protected]>> wrote:I had the problem outside of a class body, in a normal function...The particular problem mentioned in the StackOverflow quesiton you linked only ever occurs inside class bodies. They are the only enclosing scopes that are skipped in name lookups. You can still access class attributes of the class by using ClassName.attribute inside the list comprehension, like you would have to do to access class attributes from inside methods.Cheers, Sven _______________________________________________ python-uk mailing list [email protected] https://mail.python.org/mailman/listinfo/python-uk
-- Jonathan Hartley [email protected] http://tartley.com Made of meat. +44 7737 062 225 twitter/skype: tartley
_______________________________________________ python-uk mailing list [email protected] https://mail.python.org/mailman/listinfo/python-uk
