[issue20692] Tutorial section 9.4
New submission from Jon Shemitz: The tutorial says "Each value is an object, and therefore has a class (also called its type). It is stored as object.__class__." So, I tried >>> 3.__class__ File "", line 1 3.__class__ ^ SyntaxError: invalid syntax Yet, "foo".__class__ worked, as did 3j.__class__ and 3.5.__class__. When my son (!) suggested that I try (3).__class__, I did indeed get , while (3,).__class__ gave . This *looks like* a minor error in the parser, where seeing \d+\. puts it in a state where it expects \d+ and it can't handle \w+ This may be the sort of thing that only a newbie would even think to try, so may not be worth fixing. If so, it may be worth mentioning in the tutorial. -- assignee: docs@python components: Documentation, Interpreter Core messages: 211670 nosy: Jon.Shemitz, docs@python priority: normal severity: normal status: open title: Tutorial section 9.4 type: behavior versions: Python 2.7 ___ Python tracker <http://bugs.python.org/issue20692> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20692] Tutorial section 9.4
Jon Shemitz added the comment: That makes sense. Perhaps, then, the tutorial should include the FAQ? (I can't be the only person who thought to try this.) On Wed, Feb 19, 2014 at 3:59 PM, R. David Murray wrote: > > R. David Murray added the comment: > > It's actually almost a FAQ at this point. The answer is that because of > the way the parser works (it's a relatively simple parser, and we want to > keep it that way), the tokenizer sees the '.' as making the token a float, > and '3.__class__' is not a valid float token. So you have to precede the > period by something that allows the tokenizer to know it isn't a decimal > point. Parens is one way. Believe it or not, a space is another: > > >>> 3 .__class__ > > > -- > nosy: +r.david.murray > resolution: -> invalid > stage: -> committed/rejected > status: open -> closed > > ___ > Python tracker > <http://bugs.python.org/issue20692> > ___ > -- ___ Python tracker <http://bugs.python.org/issue20692> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com