[Tutor] Command statement work well on interactive mode, which running as pf file it throws error object has no attribute '__getitem__'

Alan Gauld alan.gauld at yahoo.co.uk
Thu Jun 9 04:07:40 EDT 2016


On 09/06/16 08:33, Joseph John wrote:

> Now when I create a *.py  file with all the above steps and run it, I am
> getting error
> Traceback (most recent call last):
>   File "./ReadingDataFrom1X.py", line 10, in <module>
>     c = sheet['A1']
> TypeError: 'Worksheet' object has no attribute '__getitem__'
> 
> 
> The contents of  “ReadingDataFrom1X.py” is as follows
>  #!/usr/bin/python
> import openpyxl
> wb = openpyxl.load_workbook('MyTutor.xlsx')
> wb.get_sheet_names()
> sheet= wb.get_sheet_by_name('SQL Results')
> sheet.title
> print sheet.title
> print sheet['A1']

Not according to the error message. It says the error
is on the line:

c = sheet['A1']

But you don't have such a line.

So the code you sent us is not the code you are running.
Why that may be is the puzzle.
Do you have more than one file called ReadingDataFrom1X.py?

How are you running the code? Is it from an IDE such as IDLE?
Or from the OS command line? That might make a difference.



-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list