Python Forum

Full Version: Please help me error "AttributeError: 'module' object has no attribute 'ElementTree'"
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi everyone,
I have trouble when I code python as below.
I have a simple code:
import xlrd
file_location = "D:\Training\Python\Email\aa.xlsx"
workbook = xlrd.open_workbook(file_location)
sheet = workbook.sheet_by_index(0)
print sheet
After I run the program, it shows error:
Error:
workbook = xlrd.open_workbook(file_location) File "C:\Python27\lib\site-packages\xlrd-1.0.0-py2.7.egg\xlrd\__init__.py", li ne 422, in open_workbook ragged_rows=ragged_rows, File "C:\Python27\lib\site-packages\xlrd-1.0.0-py2.7.egg\xlrd\xlsx.py", line 7 84, in open_workbook_2007_xml ensure_elementtree_imported(verbosity, logfile) File "C:\Python27\lib\site-packages\xlrd-1.0.0-py2.7.egg\xlrd\xlsx.py", line 5 2, in ensure_elementtree_imported Element_has_iter = hasattr(ET.ElementTree, 'iter') AttributeError: 'module' object has no attribute 'ElementTree'
I tried installing xlrd 1.10 (latest version)and xlrd 1.0.0 version. Please help me to fix this problem. Thank all.
Your file location string looks like it might be a problem. The backslashes will generally try to make the next character into a special character. Try one of the following: double all the backslashes (\\), switch to forward slashes (/), or make it a raw string by putting an r before it (r"D:\Training\...").

Otherwise that code is working for me in 2.7.
(Nov-09-2018, 02:42 PM)ichabod801 Wrote: [ -> ]Your file location string looks like it might be a problem. The backslashes will generally try to make the next character into a special character. Try one of the following: double all the backslashes (\\), switch to forward slashes (/), or make it a raw string by putting an r before it (r"D:\Training\...").

Otherwise that code is working for me in 2.7.

Hi,
I tried but it shows error as
Error:
un(shallow)copyable object of type <type 'element'>
This class is C:\Program Files (x86)\Python\2_7_11\Lib\xml\etree\cElementTree.py
Thanks
Please post the full error text when posting tracebacks.
(Nov-11-2018, 03:30 AM)ichabod801 Wrote: [ -> ]Please post the full error text when posting tracebacks.



Thanks for your support. I unchecked break exception. :( and my program is still running normally. I can't understand but I accepted :(