prettyprinter icon indicating copy to clipboard operation
prettyprinter copied to clipboard

`import prettyprinter` empties stdin when stdin reads from file.

Open Kenny2github opened this issue 3 years ago • 0 comments

  • PrettyPrinter version: 0.18.0
  • Python version: 3.9.6
  • Operating System: Windows 10 Command Prompt

Description

I was trying to prettyprint the result of operating on sys.stdin.read() when I noticed that the result of that function call was always ''. I isolated the problem to the import of prettyprinter - reading stdin operates correctly before the import, and reads the empty string after. Note: This only happens when a file (not a command's output!) is being redirected to stdin.

What I Did

C:\Users\Public>echo test>tmp.txt

C:\Users\Public>echo test | py -c "import sys; from prettyprinter import pprint; pprint(sys.stdin.read())"
'test \n'

C:\Users\Public>py -c "import sys; from prettyprinter import pprint; pprint(sys.stdin.read())" < tmp.txt
''

C:\Users\Public>type tmp.txt | py -c "import sys; from prettyprinter import pprint; pprint(sys.stdin.read())"
'test\n'

Kenny2github avatar Sep 09 '22 23:09 Kenny2github