how to clear the screen in python [duplicate] - python

This question already has answers here:
Closed 12 years ago.
Possible Duplicates:
clear terminal in python
How to clear python interpreter console?
I'm trying to write a program in Python but I don't know how to clear the screen.
I use both Windows and Linux and I use commands to clear the screen in those, but I don't know how to do it in Python.
How do I use Python to clear the screen?

If you mean the screen where you have that interpreter prompt >>> you can do CTRL+L on Bash shell can help. Windows does not have equivalent. You can do
import os
os.system('cls') # on windows
or
os.system('clear') # on linux / os x

Related

Clearing the screen of IDLE interactive mode [duplicate]

This question already has answers here:
Any way to clear python's IDLE window?
(23 answers)
Closed 2 years ago.
Can I clear the screen of IDLE interactive mode in Windows? I tried with the following code which fails to work:
import os
os.system('cls')
The cls command works only in Windows terminal(command prompt) and it doesn't work in IDLE screen.
Is there any other way? Or first of all, is there any hope to clear that IDLE interactive mode???
cls and clear are commands which will clear a terminal (ie a DOS prompt, or terminal window). If you are using the shell within IDLE, which won't be affected by such things, a workaround might be to print a lot of empty lines with print("\n" * 100). See also this answer for more information.
No, it is not possible, neither in IDLE, nor in Python command prompt.
Use IPython instead with its “magic” command %cls (and many others), preferable as a part of some IDE which utilized it, for example Spyder, PyCharm or JupyterLab.
Anaconda contains both Spyder and JupyterLab and many Python packages, it's probably the best all-in-one solution.
You can from os import system and then system("cls")
this will just clear out the screen. have fun coding:).

How do I export my Python file to an exe in Linux that runs in a command shell? [duplicate]

This question already has answers here:
Packaging a Python script on Linux into a Windows executable
(6 answers)
Closed 4 years ago.
I made a Python script that I would like to turn into a standalone .exe file to distribute it among my not so tech savvy friends. I am using Linux to do all the coding of course and I don't have any Windows computers to compile it on. My application has no user interface so I would need it to run in a command shell like Command Prompt. How would I do this?
My code:
import string
import collections
def caesar(rotate_string, number_to_rotate_by):
upper = collections.deque(string.ascii_uppercase)
lower = collections.deque(string.ascii_lowercase)
upper.rotate(number_to_rotate_by)
lower.rotate(number_to_rotate_by)
upper = ''.join(list(upper))
lower = ''.join(list(lower))
return rotate_string.translate(string.maketrans(string.ascii_uppercase, upper)).translate(string.maketrans(string.ascii_lowercase, lower))
print("Enter message:")
message = raw_input()
print("Enter rotation:")
rotation = raw_input()
print caesar(message, int(rotation))
You could use cx_freeze, I use it to create Windows executables on Linux and vice-versa.

VS Code - can you display a Python shell [duplicate]

This question already has answers here:
How to execute Python code from within Visual Studio Code
(34 answers)
Closed 4 years ago.
When using Python IDLE I find the Python shell, with the >>> prompt very useful for testing syntax. Is there a way of getting a Python shell integrated in VS Code?
Maybe the answer is just to open Python IDLE in another window.
Apparently this is a duplicate of another question, but I did several searches on the words Python shell and didn't find anything that seemed relevant. Sorry.
Many thanks to Jaxi for the answer that you need to type Python in the Terminal Window.
stated here you can use ctrl+backtick to open a terminal window, then from there just type python and it will give you the python shell:
https://code.visualstudio.com/docs/editor/integrated-terminal

Clear the putty terminal screen from Python [duplicate]

This question already has answers here:
Clear terminal in Python [duplicate]
(27 answers)
Closed 7 years ago.
Im calling a python script from a Putty terminal on windows and I need the python script to be able to run the "clear" command in the terminal to clear the screen to make a basic UI. How can I do this?
Answered my own question. Use this code
import subrocess
subprocess.Popen("clear")

How to launch a file with its default application using Python for WIN32, WIN64 and MAC OSX? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Open document with default application in Python
I want python code to launch a file with its default application
e.g. a .txt file with notepad(when notepad is set as the default application to open .txt files)
I want to do this for WIN 32 bit, WIN 64 bit and MAC OS X
Please help me out
Well it might seem awkward but following works quite well under Win Xp:
import webbrowser
webbrowser.open("myFile.txt")
I don't know about OS X, but an os.system call with the file name as an argument works on Windows.
Also take a look at this answer.

Categories

Resources