This line is wrong on a few levels:
if os.C:\Users\\Casper\Desktop\headfirstpython\chapter 3.exits('sketch.txt')
You need to use:
if os.path.exists(r'C:\Users\Casper\Desktop\headfirstpython\chapter 3\sketch.txt'):
I changed three things:
- it's
os.path.exists(path)
. The path isn't a valid function name. It's a string, passed as an argument. - The backslashes need to be handled in one of three ways:
- Escaped as two backslashes, which means one literal baclshash.
- Use a forward slash (
/
). This does work even on Windows. - With
r'string'
notation, where ther
tells Python to interpret it literally, without any characters escaped.
- You need to end your
if
statements with a colon (:
). Further, you'll need to indent the code under it so Python knows what precisely to execute in the case theif
is True.
As noted in the comments, be sure you've added import os
to the top as well, or os
will be undefined!