Reputation: 311
I am trying to open a file.Here is the screenshot of what i have done till now:
The first two lines runs error-free but the third or the fourth line(bordered) reports an error even though the statement is syntactically correct and Why does it report "invalid mode" ?
Upvotes: 1
Views: 119
Reputation:
You set the filepath as c:\baby1990.html
, but the error says it is c:\x08aby1990.html
.
This is because the \b
is being interpreted as an escape sequence:
>>> "\b"
'\x08'
>>>
Hence, you need to use a raw-string:
file=open(r"c:\baby1990.html")
Or, more simply, a forwardslash:
file=open("c:/baby1990.html")
Both raw-strings and escape sequences are explained here.
Upvotes: 5