Procedures and functions [was Re: Why not allow empty code blocks?]

D'Arcy J.M. Cain darcy at Vex.Net
Sun Jul 31 00:01:33 EDT 2016


On Sun, 31 Jul 2016 13:32:16 +1000
Steven D'Aprano <steve at pearwood.info> wrote:
> Many beginners make the mistake of writing:
> 
> mylist = mylist.sort()
> 
> or try to write:
> 
> mylist.sort().reverse()
> 
> If we had procedures, that would be an obvious error (possibly even a
> compile-time syntax error) instead of a perplexing source of mystery
> bugs.

While neither is a syntax error, the latter is definitely a run-time
error:

>>> mylist.sort().reverse()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'reverse'

-- 
D'Arcy J.M. Cain
System Administrator, Vex.Net
http://www.Vex.Net/ IM:darcy at Vex.Net
VoIP: sip:darcy at Vex.Net



More information about the Python-list mailing list