list of all type names
Hello, Python has one feature that I really hate: There are certain special names like 'file' and 'dict' with a predefined meaning. Yet, it is allowed to redefine these special names as in dict = [1:'bla'] In order to avoid problems in the future, I tried to get the list of all those names, but I could not find it. (The Python Reference Manual only says that there is the type Dictionary in Python, but not that 'dict' is a semi-reserved word.) Can you point me to such a list? Klaus -- http://mail.python.org/mailman/listinfo/python-list
Re: list of all type names
Python has one feature that I really hate: There are certain special names like 'file' and 'dict' with a predefined meaning. Yet, it is allowed to redefine these special names as in dict = [1:'bla'] dir(__builtins__) Yes, rebinding builtin names accidentally is an annoying and I think everyone has made that mistake at least once. Maybe PyChecker can issue a warning? -- mvh Björn -- http://mail.python.org/mailman/listinfo/python-list
Re: list of all type names
Klaus Neuner schrieb: Python has one feature that I really hate: There are certain special names like 'file' and 'dict' with a predefined meaning. Yet, it is allowed to redefine these special names as in This is not a specific Python feature: If you include a header file in C that redefines fopen(), wou will probably also run into problems. dict = [1:'bla'] I would avoid the use of generic names for variables but rather use dict1 or aDict etc. If you want to avoid a name collision without the use of naming conventions you could rename __builtins__: bi = __builtins__ del __builtins__ Then you can define what you like but you will have to reference dict, list etc. as bi.dict, bi.list, ... For a fast check simply type e.g. dict in the interactive Interpreter. If you get a NameError it is not built-in. :) -- --- Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0 E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64') --- -- http://mail.python.org/mailman/listinfo/python-list
Re: list of all type names
Of course, remember that there are benefits to this, as well. Redefining the built-ins can be useful in some interesting cases. Klaus Neuner wrote: Hello, Python has one feature that I really hate: There are certain special names like 'file' and 'dict' with a predefined meaning. Yet, it is allowed to redefine these special names as in dict = [1:'bla'] In order to avoid problems in the future, I tried to get the list of all those names, but I could not find it. (The Python Reference Manual only says that there is the type Dictionary in Python, but not that 'dict' is a semi-reserved word.) Can you point me to such a list? Klaus -- -- http://mail.python.org/mailman/listinfo/python-list
Re: list of all type names
Peter Maas wrote: I would avoid the use of generic names for variables but rather use dict1 or aDict etc. If you want to avoid a name collision without the use of naming conventions you could rename __builtins__: bi = __builtins__ del __builtins__ Then you can define what you like but you will have to reference dict, list etc. as bi.dict, bi.list, ... Except that you should never access __builtins__, and the module is actually called __builtin__. See this thread for what should probably be considered the canonical comment on this topic: http://groups.google.ca/groups?threadm=mailman.1021141460.1004.python-list%40python.org -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: list of all type names
In [EMAIL PROTECTED], Klaus Neuner wrote: In order to avoid problems in the future, I tried to get the list of all those names, but I could not find it. Typing ``dir(__builtins__)`` in the interpreter was already mentioned. Next advice is: make sure all those names are highlighted in your text editor. If I type ``dict`` it's immediatly colored differently than normal names and I know it's probably not a good idea to rebind this name to something else. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list