3

this seems to be a little strange. I am having some print statements in my python script which I run via Batch job.

The problem is with the print statements I tried every thing possible but its still throwing a Invalid Syntax error.

print STDERR 'Kapil >> BEFORE INSERT'; print STDERR 'Kapil tag_id >> $tag_id'; print STDERR 'Kapil Hostname >> $hostname'; 

I have to give STDERR to print the statements in job out file. Otherwise nothing is getting printed.

 File "/d/home/aprun-prologue/aprun-prologue", line 169 print STDERR 'Kapil >> BEFORE INSERT \n'; ^ SyntaxError: invalid syntax 

Thanks, Kapil

1
  • 5
    It looks like you copied Perl code and then expected it to work in Python. Commented Feb 3, 2014 at 17:41

1 Answer 1

5
import sys print >>sys.stderr, 'Kapil >> BEFORE INSERT' print >>sys.stderr, 'Kapil tag_id >> $tag_id' print >>sys.stderr, 'Kapil Hostname >> $hostname' 
Sign up to request clarification or add additional context in comments.

6 Comments

tried this but again nothing is showing up in my output file
We aren't sure if the OP is using python2 or python3, so this would not work for them on python3. If python3, they would need print('Kapil >> BEFORE INSERT', file=sys.stderr)
Also, assuming they did in fact copy Perl code and expect it to work, they probably need to put the variables into the strings, so they should be doing 'Kapil tag_id >> {}'.format(tag_id)' to get the exact same result.
@user2907995 Unless you are piping stderr to a file when you call this script, this output would print to the screen, not a file (stderr is not a file).
I am piping stderr to a file. The flow of the job is, its first calling a perl script which calls a python script. Whatever prints statements (STDERR) that I give in perl script are showing up in the stderr file but not the python ones. btw its python 2.6 which is installed and not 3.0 (i checked this too @Seth)
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.