console

How can I capture 'Ctrl-D' in python interactive console?

How can I capture 'Ctrl-D' in python interactive console? Question: I have a server which runs in a thread in the background, and I start it using python -i so I can get an interactive console where I can type in commands and easily debug it. But when I hit Ctrl-D, since the server is …

Total answers: 2

Python: Print to one line with time delay between prints

Python: Print to one line with time delay between prints Question: I want to make (for fun) python print out ‘LOADING…’ to console. The twist is that I want to print it out letter by letter with sleep time between them of 0.1 seconds (ish). So far I did this: from time import sleep print(‘L’) …

Total answers: 7

Python using basicConfig method to log to console and file

Python using basicConfig method to log to console and file Question: I don’t know why this code prints to the screen, but not to the file? File "example1.log" is created, but nothing is written there. #!/usr/bin/env python3 import logging logging.basicConfig(level=logging.DEBUG, format=’%(asctime)s %(message)s’, handlers=[logging.FileHandler("example1.log"), logging.StreamHandler()]) logging.debug(‘This message should go to the log file and to the …

Total answers: 7

Performance effect of using print statements in Python script

Performance effect of using print statements in Python script Question: I have a Python script that process a huge text file (with around 4 millon lines) and writes the data into two separate files. I have added a print statement, which outputs a string for every line for debugging. I want to know how bad …

Total answers: 2

how to launch a command window from Python

how to launch a command window from Python Question: I’d like to use Python 2.6 on Windows to launch several separate command windows, each running their own Python script. The purpose is: these are clients, and I’m trying to load up the server with requests from multiple quasi-independent clients. I don’t need to communicate with …

Total answers: 5

Is there go up line character? (Opposite of n)

Is there go up line character? (Opposite of n) Question: I would like to overwrite something on a line above in a serial console. Is there a character that allows me to move up? Asked By: Sponge Bob || Source Answers: No, not really easily, for that you’d have to use something like the curses …

Total answers: 6

How to get Python interactive console in current namespace?

How to get Python interactive console in current namespace? Question: I would like to have my Python code start a Python interactive console (REPL) in the middle of running code using something like code.interact(). But the console that code.interact() starts doesn’t see the variables in the current namespace. How do I do something like: mystring=”hello” …

Total answers: 5

How do I hide the console when I use os.system() or subprocess.call()?

How do I hide the console when I use os.system() or subprocess.call()? Question: I wrote some statements like below: os.system(cmd) #do something subprocess.call(‘taskkill /F /IM exename.exe’) both will pop up a console. How can I stop it from popping up the console? Asked By: Synapse || Source Answers: Try subprocess.Popen([“function”,”option1″,”option2″],shell=False). Answered By: ambagesia The process …

Total answers: 5

Rewrite multiple lines in the console

Rewrite multiple lines in the console Question: I know it is possible to consistently rewrite the last line displayed in the terminal with “r”, but I am having trouble figuring out if there is a way to go back and edit previous lines printed in the console. What I would like to do is reprint …

Total answers: 7