tim.golden at viacom-outdoor.co.uk
Mon Jun 28 16:58:07 CEST 2004
Ajay> i have the following code that doesn't work
Ajay> contextForm =
Ajay> if contextForm.has_key("number"):
Ajay> the error i get is
Ajay> AttributeError: 'str' object has no attribute 'value'
Thanks for producing the output. It's clear enough to me
what's going on, but what I'm wondering is: why isn't it
clear to you? Are you maintaining someone else's code, or
are you translating directly from VB?
In this case, you have a dictionary of key-value pairs
called contextForm. A lookup on that dictionary using
"number" as the key will give its corresponding value "1".
Since "1" is a python string, attempting to get its
attribute .value will fail, as it doesn't have one. (Try
doing dir ("1") at a python prompt). Which is what the
error message is telling you.
Your line should read (something like):
num=contextForm["number"] # note: no .value
Not to appear rude, you might be advised to understand a
little better some of the fundamentals of Python's objects
and structures before continuing with this project. There
are several on-line tutorials and guides for programmers
and non-programmers. And also, python.org hosts a tutor
mailing list, aimed at people less familiar with Python.
Have a look here:
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
More information about the Python-list