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

Joseph John jjk.saji at gmail.com
Thu Jun 9 04:49:43 EDT 2016


On Thu, Jun 9, 2016 at 12:07 PM, Alan Gauld via Tutor <tutor at python.org>
wrote:

> 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.
>
> Hi Alan,
Thanks for the reply.
I have only the same file, what happened is that I was editing the file in
a editor for troubleshooting  and when I run the file it was not saved, I
was trimming the code to the minimum
Now the program file has only the
#!/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']

and when I run it from the command line, it gets this error
Traceback (most recent call last):
  File "./ReadingDataFrom1X.py", line 8, in <module>
    print sheet['A1']
TypeError: 'Worksheet' object has no attribute '__getitem__'

I also suspect that my  user python installation has issues.   I will test
it
I will test it on another user environment and see how it comes and give
the feedback on a separate thread

Thanks a lot
Joseph John



>
>
> --
> 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
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list