简体   繁体   中英

Python unsupported operand type(s) for >>

I've never used such code with streams:

print >>self._stream, indentation + line

Would like to look at the docs. Google wasn't good at searching ">>".
The question is - how to write it in Python 3?

It causes an error:

Python unsupported operand type(s) for >>

By default (in function) stream is sys.stdout

The >> syntax prints the string to the given stream instead of stdout.

The equivalent in python 3 is the file keyword argument on the print function.

print('my text here', file=self._stream)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM