Spaces in object attribute

Alex Martelli aleax at aleax.it
Thu Jan 10 15:02:05 CET 2002


"Emile van Sebille" <emile at fenx.com> wrote in message
news:a1k5nr$qp6bs$1 at ID-11957.news.dfncis.de...
> Shouldn't this cause an SyntaxError?
>
> >>> sys.version
> '2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)]'
>
> >>> class Test:pass
>
> >>> obj=Test()
> >>> obj. attr = 1 # note the space
> >>>
>
> In particular, I ran across this while printing out debugging info when I
> typoed in a period for a comma.  I was surprised to get an attribute error
> at run time instead of a syntax error at compile time.
>
> Is there a reason to allow spaces like this?

Current Python rule is that whitespace _between_ tokens is always OK -- it
may be mandatory (when the tokens would otherwise "run into each other" and
become a single one -- e.g. "forxin" vs "for x in") or optional (otherwise),
but it's never forbidden.  Quite a simple rule.

What would you like to see this rule replaced with?  Always forbidden
except where mandatory?  Apart from breaking existing programs, this
would tend to produce very "crunched-up" lines in many cases.  Forbidden
in some cases, still optional in others?  I suspect it would be very hard
to formulate the rule about those "some cases" so that simplicity is
kept while obtaining the effect you desire (whatever, in detail, that is).


Alex






More information about the Python-list mailing list