Python Forum
Python help w/ .txt file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python help w/ .txt file
#1

  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!
Reply


Messages In This Thread
Python help w/ .txt file - by chicks4 - Mar-02-2019, 02:09 AM
RE: Python help w/ .txt file - by ichabod801 - Mar-02-2019, 04:56 AM
RE: Python help w/ .txt file - by chicks4 - Mar-02-2019, 12:35 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020