[Python] I get an error whenever I try to read a file in Python, how can I fix this?

Discussão em 'Python' iniciado por Stack, Agosto 8, 2025.

  1. Stack

    Stack Membro Participativo

    My code:

    String = open(r"C:\Users\user\OneDrive\Documents\...\file.py", "r").read()
    print(String)


    I have the file stored in the exact folder, but I got an error:``

    Traceback (most recent call last):
    File "C:\Users\user\OneDrive\Documents\...\program.py", line 47, in <module>
    VerbTo = ReadFile("VerbTo")
    File "C:\Users\user\OneDrive\Documents\...\program.py", line 41, in ReadFile
    string = open(w[variable][0], "r").read()
    FileNotFoundError: [Errno 2] No such file or directory: 'C'


    Why is this? Can Python not access OneDrive?

    Continue reading...

Compartilhe esta Página