All Questions
45 questions
1
vote
1
answer
53
views
How do I erase the last word printed onto the terminal?
I would like to be able to erase the last word printed onto the terminal. The last word should be the last string of text following a space. The following code simulates what I am trying to achieve. I ...
0
votes
3
answers
272
views
How to output and log messages at the same time in python
I want something like what the tee command does in Linux based systems, but in pure python code.
I have tried using this snippet:
import sys
# Define the file name for logging
log_file_name = 'output....
0
votes
1
answer
911
views
How to find where the sys.stderr is being printed in a Python module if it isn't showing up where expected?
I'm working on a python module and some functions in said module print the stdout and stderr to custom log files.
# module_ex.py
import sys
def testfunc(errfile):
sys.stdout = open(('stdout....
8
votes
1
answer
3k
views
Why is tqdm output directed to sys.stderr and not to sys.stdout?
Accordingo to the python python documentation concerning sys.stdout and sys.stderr:
stdout is used for the output of print() and expression statements and for the prompts of input();
The interpreter’...
0
votes
2
answers
1k
views
Run Python Script from another script and redirect script output to text file
I would like to run a second Python script and to redirect the output of this second script to a text file. The scripts and the text file are in the same folder.
I tried:
import sys
import os
...
0
votes
0
answers
565
views
Store console's output to a variable on each line
I have a function that prints some output, I want to store the console output line-by-line and send it to the user in real-time (until the word Downloaded from sys.stdout.write("Downloaded") ...
0
votes
0
answers
250
views
redirect module function stdout to flask socket
I have a file with a function that counts to 15 in a for loop. I want to redirect the output to a socket.
test.py
def counttest():
x = 0
for x in range(0,15):
x = x+1
print(&...
6
votes
2
answers
2k
views
How to continuously read from stdin (not just once input file is done)?
I have these two scripts:
clock.py
#!/usr/bin/env python3
import time
while True:
print("True", flush=True)
time.sleep(1)
continuous_wc.py
#!/usr/bin/env python3
import sys
def ...
0
votes
1
answer
577
views
How to refresh an stdout in python
Hello and thank you in advance for your help,
In fact I have a progress bar with various options that I would have liked to see refreshed instead of spending my time clearing the console.
while True :
...
0
votes
2
answers
1k
views
Is there a way to get python to output to the shell and simultaneously output to str in a variable?
The only ways I can find in python that redirects the console output to string in a variable also seem to turn off the functionality of displaying the output to the console in a live manner similar to ...
2
votes
2
answers
808
views
How do I stop Python's Sys module's "stdout" and "stderr" write method from returning the numbers of characters written
whenever I use the write method from the stdout or stderr object in Python's built-in "sys" module in Python with the Python interpreter, the method also prints an integer representing the ...
0
votes
0
answers
161
views
Stream output to different loggers based on output level
I am trying to send the system output in Python to two different logs.
But, despite the fact that I have specified two different files with its own logging levels, the two outputs go to the same file.
...
0
votes
1
answer
48
views
Temporarely open a file to use its content as input: with-statement or redirect sys.stdin?
Let's say for instance I would want to write a function that gets some basic input from a .txt file, say some numbers, and I want to print on another .txt file those numbers multiplied by 2.
I was ...
0
votes
1
answer
204
views
Can't seem to write error to output file if a script doesn't run correctly
I've written a function which reads and runs a python script, then sends it's output to a text file.
I'm trying to get it to write a simple string, or the error in question, to the text file if the ...
0
votes
1
answer
466
views
How do I get my python script that continuously prints out data to output to a line limited text file instead of the standard terminal?
I need to only allow the file to contain 5000 lines of data before deleting the oldest data as the python script outputs new data (Similar to the 'tail command in bash'). I would like to be able to ...