python statements are (or rather can be) messy
September 15th, 2007
I recently realized something about python that I wasn’t aware about. Python statements doesn’t force you to use whitespace before or after them.
When it comes to the = statement, this is rather obvious I guess… I sometimes write stuff like
foo="bar"
In other cases I had no idea it worked like this… for an example this is perfectly valid
print"hello"
In a language that uses indentation to block statements for nice readability, it feels kind of weird to allow this since it can make your code really really messy. How about these examples that are all perfectly valid:
"foo"if"bar"else"foobar"
for(x,y)in[(1,2),(3,4)]:print(x,y)
[(y)for(x,y)in[("foo",2),("bar",4)]if"foo"in(x)]
Simply forcing whitespace before and after statements in python would in my opinion be wise… even though you really REALLY shouldn’t write code like this anyways.
Yes, exactly what python needs, another arbitrary formatting rule.
I’m glad you agree.
Also, I’m immune to irony.
Your post would read better after this fix:
s/statement/expression/g