Re: [Tutor] Command statement work well on interactive mode, which running as pf file it throws error object has no attribute '__getitem__'
On 09/06/16 10:03, Joseph John wrote: > itsupport@Server-A:~$ cat ReadingDataFrom1X.py > #!/usr/bin/python > import openpyxl > wb = openpyxl.load_workbook('1XDataUserMDN.xlsx') > wb.get_sheet_names() > sheet= wb.get_sheet_by_name('SQL Results') > sheet.title > print sheet.title > print sheet['A1'] I can't see anything obvious and since this is not part of the standard library I suggest you try asking on the support site for openpyxl. http://groups.google.com/group/openpyxl-users hopefully they can figure out what's happening. -- 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@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Command statement work well on interactive mode, which running as pf file it throws error object has no attribute '__getitem__'
On Thu, Jun 9, 2016 at 12:49 PM, Joseph John wrote: > > > On Thu, Jun 9, 2016 at 12:07 PM, Alan Gauld via Tutor > 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 >> > 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 > 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 > > Tired it on a fresh install of Ubuntu 14.04 64 bit , Python version 2.7.6 Same error I am getting File "./ReadingDataFrom1X.py", line 8, in print sheet['A1'] TypeError: 'Worksheet' object has no attribute '__getitem__ for the code itsupport@Server-A:~$ cat ReadingDataFrom1X.py #!/usr/bin/python import openpyxl wb = openpyxl.load_workbook('1XDataUserMDN.xlsx') wb.get_sheet_names() sheet= wb.get_sheet_by_name('SQL Results') sheet.title print sheet.title print sheet['A1'] #sheet['A1'].value #c = sheet['A1'] #'The user id is ' + c.value Thanks Joseph John > 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@python.org >> To unsubscribe or change subscription options: >> https://mail.python.org/mailman/listinfo/tutor >> > > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Command statement work well on interactive mode, which running as pf file it throws error object has no attribute '__getitem__'
On Thu, Jun 9, 2016 at 12:07 PM, Alan Gauld via Tutor 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 > > 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 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@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Command statement work well on interactive mode, which running as pf file it throws error object has no attribute '__getitem__'
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 > 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 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Command statement work well on interactive mode, which running as pf file it throws error object has no attribute '__getitem__'
Dear All, I am taking my initial steps to interact Python with excel files. I was success in importing the needed modules, and executing steps in interactive mode . All my initial commands such as 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'] All worked fine 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 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'] If the statement worked in the interactive mode, it should all work while executing the file created. Did some google search, did not come across any valid reason why the error message is showing. Would like to request for guidance and feed back, please let me know why all my command statements work on interactive mode and when I run it in a py file some commands throws error Thanks Joseph John ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor