Forums

trying to learn text files

I’m trying to learn to use text files with python. I have uploaded a text file to pythonanywhere. The text file is in the same file that I would like to use. /home/wavemose/python_for_everybody/practice.py The text file should be /home/wavemose/python_for_everybody/mbox.txt I have used various code to attempt to open the mbox txt file. Nothing seems to work. I have looked on Pythonanywhere help and can’t find what I need. What do you suggest?

you'd be better off reading the python files tutorial but in summary

# reading
with open('path/to/file') as f:
  contents = f.read()
print(contents)

# writing
with open('path/to/file', 'w') as f:
  f.write('contents')

you may also want to check the open() documentation