473,387 Members | 3,750 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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
Jul 18 '05 #1
5 1834
> 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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: oom | last post by:
I am a bit of a newbie when it comes to python, when working with lists today I noticed some very odd behaviour, any suggestions welcome: Python 2.2.3 (#1, Nov 6 2003, 14:12:38) on linux2...
17
by: Pierre Fortin | last post by:
Hi, Is the following a reasonable generic approach for converting python returned tuples/lists into dicts...? I'm not advocating library functions also return dicts (I'd probably spend more...
9
by: seguso | last post by:
Hello, For the sake of efficiency, I have chosen C++ as the language for a "Free Adventure Construction Kit" I am developing (http://fack.sf.net). I am looking for a way to simulate list...
6
by: dam_fool_2003 | last post by:
Hai, I thank those who helped me to create a single linked list with int type. Now I wanted to try out for a void* type. Below is the code: #include<stdlib.h> #include<stdio.h>...
0
by: Mythran | last post by:
I wrote some code that is supposed to enumerate through the specified file's win32 resources and return a string-array of all icon names. When it runs, it returns a string-array with a bunch of...
1
by: Little | last post by:
Could someone help me figure out how to put my project together. I can't get my mind wrapped around the creation of the 4 double Linked Lists. Thank your for your insight. 1. Create 4 double...
5
by: Little | last post by:
I have this program and I need to work on the test portion, which tests if a Val is in the list. It returns false no matter what could you look at the part and see what might need to be done to fix...
2
by: k1ckthem1dget | last post by:
I need to display the unsorted list of names and display the sorted list of names. My program is getting a bunch of errors though, and i dont know why. I am getting the following errors. 28:...
8
by: Mike Copeland | last post by:
I am trying to learn/use the STL <listto implement a small application. I didn't get very far before I got a compile error that befuddles me. Here's the code: struct GENCHECK ...
5
by: JvC | last post by:
Background Access 2003. MDB Front End. I am populating a list box with the names of queries in the system. I am searching for strings in the query names and then creating a value list for users...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.