0

I'm working on a python program that reads a text file, splits the file by semicolon, and then removes tabs and newlines. This is the code I have so far

myfile="F:\\Python\\Programs\\test.sas"
f=open(myfile,"r")
g=f.read()
statements=g.split(';')
statements.pop()
statements2=list()
for cue in statements:
    statements2.append(cue.strip("\n")
print(statements)

The text file it reads looks like this

data test1;
    set test;
run;

data test2;
    set test;
run;

data test3;
    set test2;
run;

data test4;
    set test3;
run;

I'm just starting to learn python so I'm not really sure where the problem is. The error I'm getting has an arrow pointing at the t in print, and says "SyntaxError: invalid syntax"

I'm using python 3.4.3. Any help is greatly appreciated.

3
  • 1
    statements2.append(cue.strip("\n") you forgot to put closing bracket it should be statements2.append(cue.strip("\n")). Commented Mar 4, 2015 at 6:21
  • By the way, you could use something like g.replace('\n', '') right after reading file Commented Mar 4, 2015 at 6:23
  • as a general rule if you have a syntax error the problem is either with the line shown or the line before. When I have one I simply assume missing parenthesis on the line before the one where the error appeared since I frequently do that myself. Commented Mar 4, 2015 at 9:03

1 Answer 1

3

Looks like you are missing a trailing ) in the previous line.

statements2.append(cue.strip("\n"))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.