-1

I want to search a CSV-File with python2 on the Raspberrry Pi. If the file is not found the program should generate it. How I can search a file and can decide with an if-statment if there is CSV-file or not?

Mgm
  • 5
  • 3
  • 1
    Welcome to Stackoverflow. Did you try anything yourself? Python does have great csv support, also csv is basically a txt-file so it shouldn't be hard either way. Read also: https://stackoverflow.com/help/mcve – Bernhard Aug 08 '18 at 06:58
  • `os.path.exists('path/to/csvfile')` will return False if the specified file does nor exist. – John Anderson Aug 08 '18 at 07:01

1 Answers1

0

as @John Anderson said you can use the os module's os.path.

if os.path.exists('path/to/your/csvfile/') is True:
    print("Do something")
Yon P
  • 206
  • 1
  • 9