I want to create a file; if it already exists I want to delete it and create it anew. I tried doing it like this but it throws a Win32 error. What am I doing wrong?
Try this:
from os import path,
PATH = os.path.expanduser('~') + '\Desktop\input.txt'
if path.isfile(PATH):
try:
os.remove(os.path.expanduser('~') + '\Desktop\input.txt')
except OSError:
pass
edited :
from os import path,
PATH = os.path.expanduser('~') + '\Desktop\input.txt'
try:
os.remove(os.path.expanduser('~') + '\Desktop\input.txt')
except OSError:
pass