Phyton Opening files on windows C: pc - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Phyton Opening files on windows C: pc (/thread-39705.html) |
Phyton Opening files on windows C: pc - EddieG - Mar-29-2023 Hello, A newbie here. I am into my lesson opening files on Python. The lesson is to copy a poem on the text editor (note++) . I saved the poem on my desktop for easy locating when required. Actual Windows path (C:\User\hp\desktop\Poem.txt) However following the open() function example to pass the file into a variable as object. poem=open("/home/pi/Document/Poen.txt") results in a error no file found. using the textbook example to open the file as poem=open("C:/User/hp/desktop/Poem.txt") When the code was written in the shell, pressing enter returns a file not error: Python Version 3.11.2 What is the correct way to tell Python where to find the file in this situation. A spoon fed code (written full code) using the windows C: path answer is most welcome. Thank you for your response in advance. RE: Phyton Opening files on windows C: pc - buran - Mar-29-2023 For start, Windows has Users folder (plural), not User . Also is user really hp ?So, It should be r'C:\Users\<user name>\Desktop\Poem.txt' or 'C:/Users/<user name>/Desktop/Poem.txt'
RE: Phyton Opening files on windows C: pc - EddieG - Mar-29-2023 (Mar-29-2023, 12:01 PM)buran Wrote: For start, Windows has YES!!!, Thanks a lot Buran my man... The example is using ("....") instead of the ('...") and here is the screen shot of the code. [attachment=2304] RE: Phyton Opening files on windows C: pc - buran - Mar-29-2023 the syntax error is because you miss closing quote for the filename string |