Status of side-effecting functions in python

wxjmfauth at wxjmfauth at
Sun Oct 26 08:45:49 CET 2014

Le samedi 25 octobre 2014 23:42:42 UTC+2, Wolfgang Maier a écrit :
> As Chris and Steven have pointed out, picking print() as an example does 
> not make too much sense since it returns None.

This is precisely the Rusy's point. Why does "print" returns something
when such a function/statement should in fact returns nothing, not even
a "void", a "nil", a "None".

> A quick example that's not quite as silly as all your print() ones:
>  >>> with open('longnumber.txt', 'w') as out:
> 	print(sum(out.write(str(x)) for x in range(100)), 'characters written.')
> 190 characters written.

Ditto for <fileobj>.write(). Why should it return "something" ?

>>> with open('z.txt', 'w') as f:
...     f.write('abc')

More information about the Python-list mailing list