1

I did not know there was a redirect operator in Python 2, for example here somebody is using it to redirect something to a file. I just knew that there is one in Bash. Is still there such a thing in Python 3?

Community
  • 1
  • 1
nbro
  • 15,395
  • 32
  • 113
  • 196

2 Answers2

3

print function in Python 3.x optionally accept file parameter, you can specify file object.

import sys

print(n, file=sys.stderr)
falsetru
  • 357,413
  • 63
  • 732
  • 636
0

Using the shell redirection this way

python foo_bar.py > file

is still possible with python 3.x as this is not a feature of python itself but this is actually a feature of the shell interpreter in which the python command is run.

Zhormos
  • 31
  • 5