Python Forum

Full Version: Python help w/ .txt file
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

  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!
You need to run the program from the same folder that numbers.txt is in.
I see, I had it saved on the desktop instead of the same folder. That worked. Seriously, thank you for all your help,
ichabod801! :)