[python-win32] Dictionary command
Larry Bates
lbates at syscononline.com
Wed Nov 17 15:55:15 CET 2004
Nak,
Another suggestion that will help you in the future.
It is a REALLY bad idea to use built-in functions
like dict, list, str, etc. as variable names. Once
you have made an assignment like:
dict={}
You do have an empty dictionary called 'dict' but
you have rebound the built-in dict function so it
can no longer be used in your program (I'll let you
refer to documentation on dict function).
A mistake we see a lot is the following:
str="abcdefg"
then later in the program you want to coerce something
to a string so you write
a=1.0
x=str(a)
You get traceback because str function has been kidnapped
(e.g. it is now a string variable that contains "abcdefg".
Good luck on learning programming/Python.
Regards,
Larry Bates
Syscon, Inc.
Message: 5
Date: Wed, 17 Nov 2004 11:07:26 +0500
From: "Naveed Ahmed Khan" <naveed48 at wol.net.pk>
Subject: [python-win32] Dictionary command
To: "PYTHON TUTOR" <tutor at python.org>, "Python For Windows"
<python-win32 at python.org>
Cc: Paul Weimer <Paul.Weimer at harlandfs.com>, Kerry Oliphant
<knoliphant at earthlink.net>, Alex Willmer <alex at moreati.org.uk>, Mark
Brown <mark.brown at rogers.com>
Message-ID: <200411170604.iAH64i5w009916 at svmout.wol.net.pk>
Content-Type: text/plain; charset="us-ascii"
Dear friends,
Thanks a lot for your help my problem is solved. Though I am afraid to tell
you of my real blunder. I mean you must understand that it's my first time
with programming.
I was trying to achieve the following:
>>> dict = {}
>>> dict['boolean'] = "A value which is either true or false"
>>> dict['integer'] = "A whole number"
>>> print dict['boolean']
A value which is either true or false
What I was doing was that I was writing dict = () instead of dict = {}, got
it, I was using the wrong bracket.
It's really embarrassing, but true.
For the next time I will try to figure out how to copy the "Python command
line screen" so that you can see exactly what I have done there.
Thanks a lot again.
Regards,
NAK
More information about the Python-win32
mailing list