FHPythonUtils / Cli2Gui

Use this module to convert a cli program to a gui
MIT License
88 stars 6 forks source link

FileNotFoundError(2, 'No such file or directory') when file argument is empty #7

Closed milahu closed 2 years ago

milahu commented 2 years ago

why do we call open here?

the run function just needs the file path path should be validated with os.path.exists(path)

https://github.com/FHPythonUtils/Cli2Gui/blob/6b378034a5ade5dc06109c98814d18f6e6c2717e/cli2gui/application/pysimplegui2args.py#L11-L18

in my case values[key] == "" so open throws FileNotFoundError(2, 'No such file or directory')

my parser looks like

    parser = argparse.ArgumentParser()

    extra_args.add_argument(
        "--somefile",
        type=argparse.FileType("r"),
        required=False,
    )
FredHappyface commented 2 years ago

Thanks for this - there's no way of perfectly emulating argparse behaviour here but I've tweaked the function to avoid throwing an error here

FredHappyface commented 2 years ago

Fixed in 2022.1 let me know if that has solved things for you

milahu commented 2 years ago

argparse behaviour

aah, because when i say type=argparse.FileType("r") then argparse will open the file, and return the file handle as value

should be fixed ... thanks : )