console

Can I redirect unicode output from the console directly into a file?

Can I redirect unicode output from the console directly into a file? Question: I’ve got a python script that outputs unicode to the console, and I’d like to redirect it to a file. Apparently, the redirect process in python involves converting the output to a string, so I get errors about inability to decode unicode …

Total answers: 4

Is there a tool in Python to create text tables like Powershell?

Is there a tool in Python to create text tables like Powershell? Question: Whenever PowerShell displays its objects, it formats them in a nice pretty manner in the monospaced console, e.g.: > ps Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName ——- —— —– —– —– —— — ———– 101 5 1284 3656 32 0.03 …

Total answers: 3

Text progress bar in terminal with block characters

Text progress bar in terminal with block characters Question: I wrote a simple console app to upload and download files from an FTP server using the ftplib. I would like the app to show some visualization of its download/upload progress for the user; each time a data chunk is downloaded, I would like it to …

Total answers: 31

Changing default encoding of Python?

Changing default encoding of Python? Question: I have many “can’t encode” and “can’t decode” problems with Python when I run my applications from the console. But in the Eclipse PyDev IDE, the default character encoding is set to UTF-8, and I’m fine. I searched around for setting the default encoding, and people say that Python …

Total answers: 14

How to disable logging on the standard error stream?

How to disable logging on the standard error stream? Question: How to disable logging on the standard error stream in Python? This does not work: import logging logger = logging.getLogger() logger.removeHandler(sys.stderr) logger.warning(‘foobar’) # emits ‘foobar’ on sys.stderr Asked By: sorin || Source Answers: I don’t know the logging module very well, but I’m using it …

Total answers: 19

Running a process in pythonw with Popen without a console

Running a process in pythonw with Popen without a console Question: I have a program with a GUI that runs an external program through a Popen call: p = subprocess.Popen(“<commands>” , stdout=subprocess.PIPE , stderr=subprocess.PIPE , cwd=os.getcwd()) p.communicate() But a console pops up, regardless of what I do (I’ve also tried passing it NUL for the …

Total answers: 6

Disable console output from subprocess.Popen in Python

Disable console output from subprocess.Popen in Python Question: I run Python 2.5 on Windows, and somewhere in the code I have subprocess.Popen("taskkill /PID " + str(p.pid)) to kill IE window by pid. The problem is that without setting up piping in Popen I still get output to console – SUCCESS: The process with PID 2068 …

Total answers: 2

How do I detect whether sys.stdout is attached to terminal or not?

How do I detect whether sys.stdout is attached to terminal or not? Question: Is there a way to detect whether sys.stdout is attached to a console terminal or not? For example, I want to be able to detect if foo.py is run via: $ python foo.py # user types this on console OR $ python …

Total answers: 1

How to get Linux console window width in Python

How to get Linux console window width in Python Question: Is there a way in python to programmatically determine the width of the console? I mean the number of characters that fits in one line without wrapping, not the pixel width of the window. Edit Looking for a solution that works on Linux Asked By: …

Total answers: 15

How to clear the interpreter console?

How to clear the interpreter console? Question: Like most Python developers, I typically keep a console window open with the Python interpreter running to test commands, dir() stuff, help() stuff, etc. Like any console, after a while the visible backlog of past commands and prints gets to be cluttered, and sometimes confusing when re-running the …

Total answers: 31