python3 open winodos file problem

1. The solution
 "C: \\ Users \\ Darkness-02 \\ Desktop \\ test.txt"

is to add one more backslash.

2. The solution
r "C:\Users\Darkness-02\Desktop\txt. txt"
becomes a string

 

Toy

with open("C:\\Users\\Darkness-02\\Desktop\\test.txt","r") as txt:
    print(txt.read())

with open(r"C:\Users\Darkness-02\Desktop\txt.txt","r") as txt:
    print(txt.read())

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324585991&siteId=291194637
Recommended