Ex26 Syntax Issue File

hey i’m having a problem with my all the files i type suddenly

$ python test.txt
  File "test.txt", line 1
    This is the stuff I typed into the file
                ^
SyntaxError: invalid syntax

Literally all the files when executing in the terminal are showing this.
Please help. @zedshaw

$ python test.txt – is test.txt a Python file? Doesn’t look like it from the extension.

Are all the files triggering the exact same error message?
I think we won’t be able to help you further unless you post your code.

It’s not a python file. It’s a text file and I’m doing file handling from a python code. All my files are showing this error after I did the languages.txt exercise.

I think I don’t quite get it. From the output you posted it looks like you’re trying to feed that text file directly to the interpreter: $ python file.txt. There should be a Python file first: python myscript.py and then maybe the text file as an argument.

Or am I completely misunderstanding you? In that case, I thinkit would be way easier if you could post your code.

Yes @Pri21, what’s happening is you’re typing the python command, and the file to work on, but not telling the python command what .py script to give that file to for processing. Your command should look like this:

python ex26.py test.txt

In fact, I can’t see how you would not know this unless you were skipping many, many exercises. You’ve done this for 25 exercises, so why is it at ex26 you do it differently?

1 Like

I feel so stupid I just realized I’ve done this for ex 16 as well and i thought well it worked before and i was also thinking if i do type python text.txt how would the machine know which file to access and it slipped my mind somehow sorry i get it now. Also since 26 was marked as an exam and i have a fear of exams so i might have done this.

Well, now you know you get confused when you get scared, so next time that hits try to come up with a strategy for it. Keep in mind that there’s really no way to “fail” my book. You just do the work.

1 Like
A free service run by Zed A. Shaw for learncodethehardway.org.