list of all type names

  • Thread starter Calvin Spealman
  • Start date
C

Calvin Spealman

Of course, remember that there are benefits to this, as well. Redefining the
built-ins can be useful in some interesting cases.

Klaus said:
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

--
 
K

Klaus Neuner

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
 
?

=?ISO-8859-1?Q?BJ=F6rn_Lindqvist?=

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?
 
P

Peter Maas

Klaus said:
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. :)
 
P

Peter Hansen

Peter said:
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/[email protected]

-Peter
 
M

Marc 'BlackJack' Rintsch

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,222
Messages
2,571,137
Members
47,753
Latest member
LilianMcIl

Latest Threads

Top