Consequences of shadowing built-in types/functions

泄露秘密 提交于 2020-02-02 05:28:08

问题


I'm wondering what could be some consequences of reusing the names of built-in types or functions. To illustrate what I mean, read the following example:

list() is a built-in function. If I create another list() method I suppose it will override the original one so that the mine will be executed instead of the built-in one. But what happen if i do list=[a,z,e,r,t,y]? Is there a risk for the built-in list type or list() function?

I know it's not good to do such a thing. But my goal is only to understand what could happen in these cases...


回答1:


No, you will not damage the built-in list in any way. It will just confuse everyone.

You can still get the original list via __builtin__.list. Assigning to __builtin__.list will, however, break list for everyone.



来源:https://stackoverflow.com/questions/11263502/consequences-of-shadowing-built-in-types-functions

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!