Python Forum
Python help w/ .txt file - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Python help w/ .txt file (/thread-16486.html)



Python help w/ .txt file - chicks4 - Mar-02-2019


  1. Hi so my assignment asks that I use text saved under 'numbers.txt'
  2. I am using Windows, so I used notepad to write the text and save it under the name
  3. However, when I go to run the code, I get the error Errno 2 no such file or directory.
Here is the code I have.

def main():
    infile = open('numbers.txt', 'r')

    file_contents = infile.read()
    infile.close()

    print(file_contents)

main()
I hope I used the tags correctly!!! I am new!


RE: Python help w/ .txt file - ichabod801 - Mar-02-2019

You need to run the program from the same folder that numbers.txt is in.


RE: Python help w/ .txt file - chicks4 - Mar-02-2019

I see, I had it saved on the desktop instead of the same folder. That worked. Seriously, thank you for all your help,
ichabod801! :)