In code, list.clear doesn't throw error - it's just ignored

Dennis Lee Bieber wlfraed at ix.netcom.com
Mon Nov 14 19:15:22 EST 2022


On Tue, 15 Nov 2022 09:11:10 +1100, Cameron Simpson <cs at cskk.id.au>
declaimed the following:

>On 13Nov2022 22:23, DFS <nospam at dfs.com> wrote:
>>This is an easy check for the interpreter to make.
>
>It really isn't, given that (a) this isn't known by the interpreter to 
>be a `list` until runtime and (b) that would need embedding special 
>knowledge that looking up an attribute on a `list` has no side effects 
>(versus some other things, where it is not the case).
>

	There is also the minor facet that "x.clear" can be bound to a
different name...

>>> x = [1, 2, 3.145926536, "Pie"]
>>> clearx = x.clear
>>> x
[1, 2, 3.145926536, 'Pie']
>>> clearx()
>>> x
[]
>>> 



-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
	wlfraed at ix.netcom.com    http://wlfraed.microdiversity.freeddns.org/


More information about the Python-list mailing list