AttributeError

A

Ajay Brar

hi!

i have the following code that doesn't work
contextForm = {"contextName":"test2","contextDescription":"test22","number":"1","contextName1":"test1","contextDescription1":"test11"}

if contextForm.has_key("number"):
num=contextForm["number"].value

the error i get is
AttributeError: 'str' object has no attribute 'value'

the trace is
bash$ python
Python 2.3.4 (#3, May 28 2004, 13:31:19)
[GCC 2.95.2 19991024 (release)] on sunos5
Type "help", "copyright", "credits" or "license" for more information..... num=contextForm["number"].value
....
Traceback (most recent call last):
File "<stdin>", line 2, in ?
AttributeError: 'str' object has no attribute 'value'

any ideas why it isn't working?

thanks

Ajay Brar
CS Honours 2004
Smart Internet Technology Research Group

http://www.it.usyd.edu.au/~abrar1
 
R

Reinhold Birkenfeld

Ajay said:
hi!

i have the following code that doesn't work
contextForm =
{"contextName":"test2","contextDescription":"test22","number":"1","contextName1":"test1","contextDescription1":"test11"}

if contextForm.has_key("number"):
num=contextForm["number"].value

the error i get is
AttributeError: 'str' object has no attribute 'value'

What do you want to retrieve? If you want to get the string "1" which is
assigned to the key "number", a simple contextForm["number"] is enough.

If you want to get the integer 1 in the string, use
int(contextForm["number"]).

Reinhold
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top