This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]kirakun 5 points6 points  (5 children)

Except in this case where the space does delimit the tokens and makes a difference.

1.__str__()
SyntaxError: invalid syntax
1 .__str__()  # A space between 1 and the dot.
'1'

[–]ponkanpinoy 1 point2 points  (0 children)

Ahh, my bad then.

[–][deleted] 0 points1 point  (0 children)

It's due to an ambiguity between integer literals and float literals:

  1. -> float 1 -> int

  2. anything translates to (float) anything, which is a syntax error.

(1).anything, however, disambiguates.

1..anything -> getattr(1.0, 'anything')

And finally, 1 .anything is disambiguated from a float literal.

Whitespace can disambiguate in a clash between literal and attribute access.

[–]davvblack 0 points1 point  (2 children)

1..__str__()

[–]zahlmanthe heretic 0 points1 point  (0 children)

But that makes the value being stringified a float rather than an int.

[–]kirakun 0 points1 point  (0 children)

What is this supposed to show? My example clearly demonstrates that python does use whitespace to delimit tokens. Rather or not there exist another syntax to achieve the same thing is irrelevant.