Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is this print syntax? (print rightshift) [duplicate]

Looking at the source code of pstats I see this syntax:

print >> self.stream, "in %.3f seconds" % self.total_tt
print >> self.stream

What is this syntax, how is it called and how to use it? I have never seen it before, nor seen it in any of the Python books/tutorials I have read.

like image 817
orlp Avatar asked Dec 09 '25 18:12

orlp


1 Answers

If you mean the >>, that's the Python 2.x syntax for writing to a file-like other than sys.stdout with print. It's defined in the Python docs, 6.6. The print statement and has been around since at least Python 2.5 (and I think earlier).

This syntax has been replaced with a file kwarg to the print function in Python 3.0.

like image 177
Fred Foo Avatar answered Dec 12 '25 11:12

Fred Foo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!