Python Forum
I must be missing something simple?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I must be missing something simple?
#1
To start - I am a novice at Python.
I have a created a "tool" I use for my work daily. It includes the ability to create Excel workbooks that I use for notes etc. I am updating this tool by simply adding the ability to create update and show a third excel workbook. The first two work well and have for years. This new third (createQstn) gives me an tkinter attribute error that "worksheet has no attribute 'save'". However I am defining it as "Workbook()". The "filepath3" variable works for every other function that uses it, AND if I create the workbook in excel and save it correctly, I will get my print response "exists" when I hit my "createQstn" button. The only issue is that it will not create this workbook and gives me the error, if it does not already exist. The two previous functions create workbooks without error, and I can't see what I may have done different. Any help would be much appreciated. I am including the code section that produces the error. If it is possible the issue is earlier or later somehow, please let me know and I will post the full code.

def createQstn():
    print(filepath3)
    isFile = os.path.isfile(filepath3)
    if isFile == False:
        QstnsWB = Workbook()
        QstnsWB = QstnsWB.active
        QstnsWB['A1'] = '#'
        QstnsWB['B1'] = 'Date'
        QstnsWB['C1'] = 'Question'
        QstnsWB['D1'] = 'Answer'
        QstnsWB['E1'] = 'Done'
        QstnsWB.save(filepath3)
        print("created")
    print("exists")
the error:
Error:
Exception in Tkinter callback Traceback (most recent call last): File "C:\Program Files\Lib\tkinter\__init__.py", line 1948, in __call__ return self.func(*args) ^^^^^^^^^^^^^^^^ File "C:\Users\SeanL\Python Scripts\360Helper5.0.py", line 102, in createQstn QstnsWB.save(filepath3) ^^^^^^^^^^^^ AttributeError: 'Worksheet' object has no attribute 'save'
Thanks for any help.
Sean
Reply
#2
I am confused. Why do you have a C"\Program Files\Lib\tkinter folder? The tkinter folder should be something like C:\Program Files\Python311\Lib\tkinter. It is installed as part of the Python install. This is odd, but I don't know if it is a problem.

I think the problem is that you save a Workbook, not a Worksheet.
def createQstn():
    print(filepath3)
    isFile = os.path.isfile(filepath3)
    if isFile == False:
        wb = Workbook()
        ws = wb.active
        ws['A1'] = '#'
        ws['B1'] = 'Date'
        ws['C1'] = 'Question'
        ws['D1'] = 'Answer'
        ws['E1'] = 'Done'
        wb.save(filepath3)
        print("created")
    print("exists")
Reply
#3
I don't know why Python is installed where it is. I may have chosen the location. BUT THANK YOU! My cut and paste mindlessness burned me again. I knew it had to me something simple, I just couldn't see it. Works great now. Thank you, thank you.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Not able to crack a simple visualization – missing something basic – plz guide darpInd 4 2,825 Mar-27-2020, 09:26 AM
Last Post: darpInd

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020