1

I am reading a book about Python and along I'm doing some experimentations on the interactive prompt.

During those experimentations I have noticed that if I code 1.bit_length() (or any other type specific method) it doesn't work.

Yes, I know that the reason is that Python doesn't get the number and I need to type (1).bit_length(), but my question is: why? Why did they do so? I mean there are so many developers and they couldn't develop a parser that gets 1.bit_length()?

zer0uno
  • 7,521
  • 13
  • 57
  • 86
  • `1 .bit_length()` also works. – pts Jun 26 '14 at 14:58
  • Probably the same reason why you needed a space in `vector >` in C++ for a long time: because the tokenizer returned `>>` as a single token, and it was hard to split in in a LALR(1) parsers. – pts Jun 26 '14 at 15:00
  • 2
    `1.bit_length` is parsed as `1.` followed by `bit_length`. As `1.` is interpreted as a float, the following stuff is a syntax error (because there is no separator). In general, it works though: `1..hex()` correctly calls the `hex` method on the float `1.`. – poke Jun 26 '14 at 15:00

0 Answers0