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

kay
  • 176
  • 2
  • 10

1 Answers1

5
import sys

print >>sys.stderr, 'Kapil >> BEFORE INSERT'
print >>sys.stderr, 'Kapil tag_id >> $tag_id'
print >>sys.stderr, 'Kapil Hostname >> $hostname'
John Kugelman
  • 349,597
  • 67
  • 533
  • 578
  • tried this but again nothing is showing up in my output file – kay Feb 03 '14 at 17:57
  • 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)` – SethMMorton Feb 03 '14 at 17:57
  • 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. – SethMMorton Feb 03 '14 at 17:58
  • 1
    @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). – SethMMorton Feb 03 '14 at 18:01
  • 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) – kay Feb 03 '14 at 18:21
  • Is your perl script capturing the output of your python script? – SethMMorton Feb 03 '14 at 19:31