Writing the Path to a file properly - 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: Writing the Path to a file properly (/thread-19486.html) |
Writing the Path to a file properly - dcw9996 - Jul-01-2019 Hello, I am 64 years old but new to Python and brand new to this forum. If I due something wrong please let me know. I purchased a book on python and I'm working through it. I am trying to work on opening/reading/writing to files. I just cannot open a file in another directory from my python script location. I have followed every direction and googled until my fingers are bleeding. I am obviously missing something. My computer is Windows 10 My python file is saved in Dropbox (I sometimes study from different locations) Here is my code: import csv import os path = "This PC/Windows(C:)/Users/dcw99/Documents/Python_basics_work_files/python-basics-exercises-master" \ "/ch11-file-input-and-output/practice_files/" with open(os.path.join(path, "wonka.csv"), "r") as my_file: reader = csv.reader(my_file) for row in reader: print(row) I keep getting the error: I have typed the path exactly as it appears. I've placed an r immediately in front of the path, as instructed. No joy.I apologize for asking about something this simple but I am just so frustrated. Any help you can offer would be very appreciated. Thanks, Don RE: Writing the Path to a file properly - Yoriz - Jul-01-2019 Try the following as the path path = ("C:/Users/dcw99/Documents/Python_basics_work_files/python-basics-exerci" "ses-master/ch11-file-input-and-output/practice_files/") RE: Writing the Path to a file properly - dcw9996 - Jul-01-2019 Yoriz!! Worked like a charm!!! Thank you so much. |