Python Forum
Unable to get function to do anything...
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unable to get function to do anything...
#1
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:-

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
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.
Reply


Messages In This Thread
Unable to get function to do anything... - by ejwjohn - Nov-06-2023, 03:06 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  unable to use result of solver in another function ross1993hall 0 1,428 Aug-10-2020, 10:29 AM
Last Post: ross1993hall
  Passing Values of Dictionaries to Function & Unable to Access Them firebird 3 2,622 Aug-03-2019, 10:25 PM
Last Post: firebird

Forum Jump:

User Panel Messages

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