stdout

Does `print()` delay in some consoles where `stdout.flush` doesn't?

Does `print()` delay in some consoles where `stdout.flush` doesn't? Question: I’m working on an open source python library that uses a verbose_print command to log outputs in the console. Currently it looks like this: def sys_write_flush(s): """ Writes and flushes without delay a text in the console """ sys.stdout.write(s) sys.stdout.flush() def verbose_print(verbose, s): """ Only …

Total answers: 1

Call another click command from a click command

Call another click command from a click command Question: I want to use some useful functions as commands. For that I am testing the click library. I defined my three original functions then decorated as click.command: import click import os, sys @click.command() @click.argument(‘content’, required=False) @click.option(‘–to_stdout’, default=True) def add_name(content, to_stdout=False): if not content: content = ”.join(sys.stdin.readlines()) …

Total answers: 4

Overwriting/clearing previous console line

Overwriting/clearing previous console line Question: My problem is, that I want to be able to overwrite/clear previous printed line in python console. This question has been asked many times (Python – Remove and Replace Printed items for example), however with the very same code that is (the answer marked as correct, for me prints out …

Total answers: 4

How to detect that stdio was redirected to nul?

How to detect that stdio was redirected to nul? Question: I’m developing a package to fix several issues with Unicode in Python run in standard Windows console environment: https://github.com/Drekin/win-unicode-console. The key operation is to replace the standard stream objects when needed. For this I need to detect whether the standard streams were redirected or not. …

Total answers: 1

Get output from a Paramiko SSH exec_command continuously

Get output from a Paramiko SSH exec_command continuously Question: I am executing a long-running python script via ssh on a remote machine using paramiko. Works like a charm, no problems so far. Unfortunately, the stdout (respectively the stderr) are only displayed after the script has finished! However, due to the execution time, I’d much prefer …

Total answers: 6

Python read from subprocess stdout and stderr separately while preserving order

Python read from subprocess stdout and stderr separately while preserving order Question: I have a python subprocess that I’m trying to read output and error streams from. Currently I have it working, but I’m only able to read from stderr after I’ve finished reading from stdout. Here’s what it looks like: process = subprocess.Popen(command, stdout=subprocess.PIPE, …

Total answers: 7

Using tee to get realtime print statements from python

Using tee to get realtime print statements from python Question: I have a python script that looks something like this: for item in collection: print “what up” #do complicated stuff that takes a long time. In bash, I run this script by doing the following: $ python my.py | tee my_file.txt However, all I see …

Total answers: 1

"subprocess.Popen" – checking for success and errors

"subprocess.Popen" – checking for success and errors Question: I want to check if a subprocess has finished execution successfully or failed. Currently I have come up with a solution but I am not sure if it is correct and reliable. Is it guaranteed that every process outputs its errors only to stderr respectfully to stdout: …

Total answers: 7

Writing PDFs to STDOUT with Python

Writing PDFs to STDOUT with Python Question: I want to merge two PDF documents with Python (prepend a pre-made cover sheet to an existing document) and present the result to a browser. I’m currently using the PyPDF2 library which can perform the merge easily enough, but the PdfFileWriter class write() method only seems to support …

Total answers: 1