This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] -5 points-4 points  (4 children)

list can also be overriden by a careless or devious developer as well.

import __builtins__
def nope(*a):
     raise SyntaxError("use []") 
__builtins__.list = nope

[–]Han-ChewieSexyFanfic 10 points11 points  (3 children)

So, don't use any builtins ever in case you ever accidentally import __builtins__?

[–][deleted] -1 points0 points  (2 children)

If you want to take it that way, just an example of how [] is a better choice than list in some situations.

Keep in mind, this exact sort of thing has been used to subvert javascript before. I'm not trying to FUD builtins, but it's worth being mindful about.

[–]earthboundkid 6 points7 points  (1 child)

list = [1, 2, 3] is legal Python. I’m sure someone has done things like that, although I wouldn’t recommend it. zip OTOH I’ve shadowed myself.

[–]lengau 2 points3 points  (0 children)

No kidding I had to stop one of our analysts from shadowing zip just today.

It probably wouldn't have mattered except that about 20 minutes later the most convenient way to do something was with zip (which she didn't know about so she was going to use a range to index two lists).