Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if an argv refers to an existing file in python2.7? [duplicate]

Tags:

I know how to check whether required arguments are given on the command line. But how do I check whether the given argument on the command line actually refers to an existing file in the folder I'm running the code in?

I'm trying to incorporate this verification in order to save time by skipping parts of my code in case the file cannot be referenced to.

like image 981
Marlen Avatar asked Jul 17 '17 14:07

Marlen


1 Answers

import os
os.path.exists(path)

Will return True, if the path exists.

os.path.isfile(path)

Will return True, if the path is a file.

like image 103
Maaaaa Avatar answered Sep 22 '22 11:09

Maaaaa