Nov-06-2023, 03:06 PM
Hello,
I am a novice at Python, i using Thonny on Raspberry OS with Python 3.9.2
The def in question is listed below( I hope) and to simplify things i have removed it from the main code i am creating an just isolated to make it simpler to Troubleshoot.
the code is below:-
>>> %Run deftest.py
but my limited experience does not give me any insight into the real issue here.
Any help would be appreciated
Thanks
JohnW
I am a novice at Python, i using Thonny on Raspberry OS with Python 3.9.2
The def in question is listed below( I hope) and to simplify things i have removed it from the main code i am creating an just isolated to make it simpler to Troubleshoot.
the code is below:-
def up_msg_log(): # Load the workbook and select the sheet & next row fpath=os.path.join('/','home','john','NEWRPi4MoistureFiles','msglog.xlsx') wb = load_workbook(fpath) sheet = wb['Sheet1'] alignment=Alignment(horizontal='center') ins_row = str(len(sheet['A']) + 1 ) if (drywet)=="Wet": row = (cdate,ctime,drywet,"N/A","N/A") else: row = (cdate,ctime,drywet,opentime1,valveonoff) sheet.append(row) wb.save(fpath) # End Def print('start') up_msg_log() print('OK')The errors i get are :-
>>> %Run deftest.py
Output:start
Traceback (most recent call last):
File "/home/john/NEWRPi4MoistureFiles/deftest.py", line 23, in <module>
up_msg_log()
File "/home/john/NEWRPi4MoistureFiles/deftest.py", line 9, in up_msg_log
wb = load_workbook(fpath)
File "/home/john/.local/lib/python3.9/site-packages/openpyxl/reader/excel.py", line 344, in load_workbook
reader = ExcelReader(filename, read_only, keep_vba,
File "/home/john/.local/lib/python3.9/site-packages/openpyxl/reader/excel.py", line 123, in __init__
self.archive = _validate_archive(fn)
File "/home/john/.local/lib/python3.9/site-packages/openpyxl/reader/excel.py", line 95, in _validate_archive
archive = ZipFile(filename, 'r')
File "/usr/lib/python3.9/zipfile.py", line 1257, in __init__
self._RealGetContents()
File "/usr/lib/python3.9/zipfile.py", line 1324, in _RealGetContents
raise BadZipFile("File is not a zip file")
zipfile.BadZipFile: File is not a zip file
>>>
The first line of code in def is line 8 and it reads:
fpath=os.path.join('/','home','john','NEWRPi4MoistureFiles','msglog.xlsx')
This line works OK when used in the main code stream, but i suspect there are issue with it when i move it to the function.but my limited experience does not give me any insight into the real issue here.
Any help would be appreciated
Thanks
JohnW