Nov-06-2023, 03:06 PM
(This post was last modified: Nov-06-2023, 03:10 PM by deanhystad.)
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:-
The errors i get are :-
>>> %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:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
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' ) |
>>> %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
deanhystad write Nov-06-2023, 03:10 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.