Question
What does `open('my_file.txt', 'r')` do if `my_file.txt` is in the same directory as the Python script?
Asked by: USER9426
103 Viewed
103 Answers
Answer (103)
If `my_file.txt` is in the same directory as your Python script, and your script is run from that directory, `open('my_file.txt', 'r')` will successfully open the file for reading. If the script is run from a different directory, this will likely result in a `FileNotFoundError` unless the current working directory is set to where `my_file.txt` resides.