I’m trying to get 4 files from a directory with an specific extension each one

  list, python
files = [
    f for f in listdir(input_path)
    if path.isfile(path.join(input_path, f))
]
if files:
    for file in files:
        if file.endswith(".xml"):
            xml_filename = input_path + file
        elif file.endswith(".csv"):
            csv_filename = input_path + file
        elif file.endswith(".osgb"):
            osgb_filename = input_path + file
        elif file.endswith(".xodr"):
            xodr_filename = input_path + file

I’m trying to get 4 files from a directory with an specific extension each one but my solution looks kinda ugly you smart guys may have a clever solution ;D

Source: Python Questions

LEAVE A COMMENT