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...
#8
Well, I'm no expert, but I often need to do the same thing to various XL files, so I make a list of the files, then choose 1 from the list. Then I either loop, or offer myself the choice of file again.

Something like this:

import os
import glob

mypath = '/home/pedro/myPython/openpyxl/xlsx_files/'
# can add files from various paths to xlfiles if needed
xlfiles = glob.glob(mypath + '*.xlsx')
for x in xlfiles:
    print('The XL files are', x)

myfile = input('Copy and paste the whole path to the file you want from above ... ')

while not os.path.isfile(myfile):
    print('Something wrong with this path or file. Choose another file.')
    myfile = input('Copy and paste the whole path to the file you want from above ... ')
If myfile is not a valid file, os.path.isfile(myfile) returns False. However, this does not check if it is a valid XL file, just a valid file. Could be any type of file.

Maybe check if it is a zip file and ends in .xlsx Not sure how to check if it is a zip file! Big Grin Big Grin Big Grin

But the experts here will know how to do that! Have fun!
Reply


Messages In This Thread
RE: Unable to get function to do anything... - by Pedroski55 - Nov-07-2023, 07:38 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  unable to use result of solver in another function ross1993hall 0 1,432 Aug-10-2020, 10:29 AM
Last Post: ross1993hall
  Passing Values of Dictionaries to Function & Unable to Access Them firebird 3 2,640 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