Trying to load data/text file

Hello,

I am trying to enter the code below from a really simple text file. As you can in the output below, it prints the first line of the file and stops before printing the other two lines. (The text file by the way is located with the working Pycharm file).

Any clues as to what I am doing wrong?

file=open('scratch.txt','r')

contents=file.read()
file.close()
print(contents)

 

 

Output

C:\Users\ahitc\PycharmProjects\Python revision\venv\Scripts\python.exe" "C:/Users/ahitc/PycharmProjects/Python revision/scratch.txt"
File "C:/Users/ahitc/PycharmProjects/Python revision/scratch.txt", line 1
first line of text
^
SyntaxError: invalid syntax

1 comment
Comment actions Permalink

Please try to run your code from the terminal outside of IDE to see if it's IDE's fault:

For more information on how to run your code from the terminal outside of IDE, please see the following article:
https://docs.python.org/3/using/cmdline.html#command-line

If you're using virtualenv interpreter in PyCharm, you may need to activate it in the command line as well:
https://virtualenv.pypa.io/en/latest/user_guide.html#activators

0

Please sign in to leave a comment.