Whitespace not/required

dn PythonList at DancesWithMice.info
Sat Aug 15 20:06:53 EDT 2020


On 15/08/2020 08:01, Dennis Lee Bieber wrote:
> On Fri, 14 Aug 2020 16:29:18 +1200, dn via Python-list
> <python-list at python.org> declaimed the following:
> 
> 
>> it is ignored by Python. (yes, this discussion disdains comments!) For
>> example, whitespace is no problem when it comes to defining a list:
>>
>> month_names = ['Januari', 'Februari', 'Maart',      # These are the
>>                 'April',   'Mei',      'Juni',       # Dutch names...
>>
> 
> 	Concepts: First, you have an open [ though ( and { behave the same.
> Python takes anything in intervening lines to be included until the closing
> ]/)/} is reached.

Exactly! (BTW this taken from 'the manual')


> 	Second, for things like lists, the only important (parsed content) are
> the "words" [in your example] separated by commas.

Agreed - and IMHO a positive attribute when coding in Python making a 
solid contribution to readability.


> 	Whitespace in Python controls /scope/ of logic structures (function
> definition, loop bodies, conditional bodies).

Hence my surprise/how do we explain:

 >>> f'{ one:03 }'
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
ValueError: Unknown format code '\x20' for object of type 'int'

where the final space does not act as a separator by terminating the 
format-specification. The err.msg is in itself confusing, because the 
format-specification 03 is NOT a (valid) Python integer:

 >>> i = 3
 >>> i
3
 >>> i = 03
   File "<stdin>", line 1
     i = 03
          ^
SyntaxError: leading zeros in decimal integer literals are not 
permitted; use an 0o prefix for octal integers

Perhaps I'm mis-interpreting the err.msg?


Otherwise let's march on City Hall: "white space just wants to be free!"...
-- 
Regards =dn


More information about the Python-list mailing list