By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,995 Members | 1,079 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,995 IT Pros & Developers. It's quick & easy.

list of all type names

P: n/a
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
Jul 18 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
> 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
Jul 18 '05 #2

P: n/a
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')
-------------------------------------------------------------------
Jul 18 '05 #3

P: n/a
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


--
Jul 18 '05 #4

P: n/a
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?threa...t%40python.org

-Peter
Jul 18 '05 #5

P: n/a
In <3e**************************@posting.google.com >, 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
Jul 18 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.