0

I am working on an assignment for my fundamentals class and we have to create a program that is going to write/read/ and append a file. I wanted to set it up to check and see if example.txt exists. If so then append, else write. My question would be how do I check to see if a file exists or not?

Edited by nUmbdA

3
Contributors
3
Replies
4
Views
4 Years
Discussion Span
Last Post by ZZucker
0

Generally:

import os

filename = "example.txt"
if os.path.exists(filename):
    print("file %s exists" % filename))
    # now do something with the file
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.