question about python "casting"
"Martin v. Löwis"
martin at v.loewis.de
Mon Feb 9 07:47:51 CET 2004
sang park wrote:
> name :
> Traceback (most recent call last):
> File "ProjectParser.py", line 63, in ?
> print "name : ", p.name
> AttributeError: 'NoneType' object has no attribute 'name'
> i was wondering what the proper way to accomplish this would be. any help
> would be appreciated.
Could it be that you have been executing a code different from
the one you were posting? In your posted code, you have a variable
called "proj", whereis from your exception, it appears the variable
is called "p".
> if nodes.nodeType == nodes.ELEMENT_NODE:
> datanodes = info.childNodes
> dataStr = getText(datanodes)
> # print info.nodeName, ":", dataStr
> if dataStr == "name":
> project.name = dataStr
> if dataStr == "email":
> project.email = dataStr
> if dataStr == "admin":
> project.admin = dataStr
> if dataStr == "description":
> project.description = dataStr
It is unlikely that this does what you want: Most likely, you
have elements "name", "email", etc in your XML document.
You need to look at some node's nodeName, to find out whether
it is a "name" node - looking at the text inside the node
E.g. in your code above, if dataStr equals "email", you do
project.email = dataStr
Since dataStr is email, this is the same as
project.email = "email"
which is not what you want.
More information about the Python-list