Search code examples
pythonxmltodict

xmltodict throwing errors when used in a .py file


I want to get xmltodict in python2.7 up and running for a project I have, so I started by copy-pasting from the only example I was able to find

import xmltodict

with open ('test.xml') as fd:
    doc = xmltodict.parse(fd.read())

print doc

Trying to run this results in the error: AttributeError: 'module' object has no attribute 'parse'

Same thing when trying to convert a dict to xml using the xmltodict.unparse function.

However, it works if I do this line by line in IDLE... Any idea why this fails when trying to run it in a .py file, but works when I use the interpreter line by line?


Solution

  • Just don't name your script xmltodict.py. It is getting imported instead of an installed into the Python environment xmltodict package.