From: Thomas Jollans on 4 Jul 2010 11:08 On 07/04/2010 03:49 PM, jmfauth wrote: > On 4 juil, 12:35, Carl Banks <pavlovevide...(a)gmail.com> wrote: >> On Jul 4, 1:31 am, jmfauth <wxjmfa...(a)gmail.com> wrote: >> > > > Thanks for having explained in good English my feelings. > > >> >> Some other places were keyword can follow a number: >> > > Note, that this does not envolve numbers only. > >>>> ['z' for c in 'abc'] > ['z', 'z', 'z'] >>>> 'z'if True else 'a' > z >>>> > > > >>> Side effect: If this behaviour is considered as correct, >>> it makes a correct Python code styling (IDLE, editors, ...) >>> practically impossible to realise. >> >> I'm not sure why an odd corner of the grammar would mess the whole >> thing up. Most code stylers only approximate the actual grammar >> anyway. >> > > I guess, most editors (so do I) are mainly using > a "re" engine for their styling. > > --- > > Not a keyword, but space related, what should I thing > about this? > >>>> print9 looks like an identifier > Traceback (most recent call last): > File "<psi last command>", line 1, in <module> > NameError: name 'print9' is not defined >>>> print+9 can't be a single identifier. Maybe it's a print statement followed by stuff? (stop being a statement, print!) > 9 >>>> print'abc' can't be an identifier or string literal. Maybe it's a print statement followed by stuff? > abc >>>> print9.0 looks like getattr(print9, '0') - but '0' is not a valid name. Impossible. Error! > File "<psi last command>", line 1 > print9.0 > ^ > SyntaxError: invalid syntax >>>> somewhat strange, yes.
From: John Machin on 4 Jul 2010 18:02 On Jul 5, 1:08 am, Thomas Jollans <tho...(a)jollans.com> wrote: > On 07/04/2010 03:49 PM, jmfauth wrote: > > File "<psi last command>", line 1 > > print9.0 > > ^ > > SyntaxError: invalid syntax > > somewhat strange, yes. There are two tokens, "print9" (a name) and ".0" (a float constant) -- looks like SyntaxError to me.
From: Mark Dickinson on 5 Jul 2010 03:44 On Jul 4, 11:02 pm, John Machin <sjmac...(a)lexicon.net> wrote: > On Jul 5, 1:08 am, Thomas Jollans <tho...(a)jollans.com> wrote: > > > On 07/04/2010 03:49 PM, jmfauth wrote: > > > File "<psi last command>", line 1 > > > print9.0 > > > ^ > > > SyntaxError: invalid syntax > > > somewhat strange, yes. > > There are two tokens, "print9" (a name) and ".0" (a float constant) -- > looks like SyntaxError to me. Yep. Looks that way to me, too. Python 2.7.0+ (release27-maint:82569, Jul 5 2010, 08:35:08) [GCC 4.0.1 (Apple Inc. build 5490)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from cStringIO import StringIO >>> import tokenize, token >>> for tok in tokenize.generate_tokens(StringIO("print9.0").readline): .... print token.tok_name[tok[0]], tok[1] .... NAME print9 NUMBER .0 ENDMARKER -- Mark
From: jmfauth on 5 Jul 2010 14:12 Thank you all for the discussion and the explanations. > Mark Dickinson I toyed a littled bit this afternoon and I wrote a colouriser (British spelling?) with the tokenize module. It is quite simple and easy. BTW, if I understand correctly the module tokenize import the module token. So your example becomes: >>> from cStringIO import StringIO >>> import tokenize >>> for tok in tokenize.generate_tokens(StringIO("print9.0").readline): print tokenize.tok_name[tok[0]], tok[1] NAME print9 NUMBER .0 ENDMARKER >>>
From: Mark Dickinson on 5 Jul 2010 15:56 On Jul 5, 7:12 pm, jmfauth <wxjmfa...(a)gmail.com> wrote: > BTW, if I understand correctly the module tokenize import > the module token. So your example becomes: > > >>> from cStringIO import StringIO > >>> import tokenize > >>> for tok in tokenize.generate_tokens(StringIO("print9.0").readline): > > print tokenize.tok_name[tok[0]], tok[1] Ah yes; you're right. Thanks! Mark
First
|
Prev
|
Pages: 1 2 Prev: How to disable readline when building Python? Next: [ANN] eric 5.0.0 released |