Jack Jackson
Jack Jackson

Reputation: 3

Python not opening the file i selected

Code:

os.startfile("C:\finished.py")

Return:

FileNotFoundError: [WinError 2] The system cannot find the file specified: 'C:\**x0cinished**.py'

Expectation: take C:\finished.py

What could be causing python to change my input like this?

Upvotes: 0

Views: 232

Answers (2)

DeepSpace
DeepSpace

Reputation: 81614

'\f' is a special character (see Table of escape sequences). You should make it a habit to use r (raw strings) when working with hard-coded paths:

os.startfile(r"C:\finished.py")

Upvotes: 5

Peter Branforn
Peter Branforn

Reputation: 1677

You need to escape the "\" character. Write "C:\\finished.py" in your startfile statement.

Upvotes: 3

Related Questions