How to call xml while in the Lib \ xml folder?

1

Doing an exercise that starts with the following code:

import xml.etree.ElementTree as ET

tells me when executing it that it can not find the module.

  

Traceback (most recent call last):       File "C: \ Python27 \ xml1.py", line 1, in       import xml.etree.ElementTree as ET       File "C: \ Python27 \ xml.py", line 1, in       import xml.etree.ElementTree as ET       ImportError: No module named etree.ElementTree

The module exists in the Lib \ xml \ etree folder. Maybe I need to have it installed, not just hosted? Am I calling it in the wrong way?

Thank you.

    
asked by juanluisjt 21.06.2017 в 12:58
source

1 answer

1

Python resolves the import first search for the module in your current working directory , if it does not find it, it goes to the standard library.

A module called xml.py or package called xml will cause you to try to import from here and not from the standard library. You must change the name of your module or package to something else.

You should add the structure of your project (folders and files that compose it), it is very possible that the cause is this. You do not have to install anything, xml belongs to the standard library.

Editing: if your problem is due to the previous thing it is possible that you also have to delete the xml.pyc generated.

    
answered by 21.06.2017 / 13:04
source