My program tries to read a file and process its contents. The file to be processed contains
core-001
core-001
core-002
core-003
core-003
...
core-nnn
To process it, I wanted to read out every line, stuff them in a list, remove the duplicates and then put them out again in some other file. The code for these first three things I used is as follows:
content = []
with open(file,'r') as openFile:
content = [line.strip('\n') for line in openFile]
content = list(set(content))
(Why I use list and set)
As far as I see, this should not have any problems, however two errors are returned:
Traceback (most recent call last):
File "/path/to/file", line 1, in <module>
core-004
NameError: name 'core' is not defined
and
File "/path/to/file", line 21
core-009
^
SyntaxError: invalid token
What causes these errors and, more importantly, how to avoid them?
EDIT As also readable in the comments, but repeated here:
It was not an error in the code, it was just me not coding well enough. The errors were given by python
trying to execute the input file as I seemed to have forgotten to give it the executable and only the parameters. After doing so it works perfectly.
I thank you for your time and your kind comments.