How to clear the terminal in Py-charm. (non-manually) - python

I need to clear the terminal in Pycharm without clicking the trashbin myself. I've tried using the whole os and csl thing but it only makes some weird arrow in the terminal.

The os.system command cannot work because it only executes commands in the Console. It won't work in many other places including IDLE's Python Shell, PyCharm, etc.
It should work in your Terminal. You can write your code in PyCharm and execute it in a terminal.
You can also use multiple \n, but it is not really what you want.
Another idea would be to add a keyboard shortcut.

You need to open Preferences, look for "clear all" and assign a Keyboard Shotcut, for example I put Ctrl+Alt+5 :
Keyboard Shotcut, Ctrl+Alt+5
Then you need to use it when you are inside the console,
I hope it helps,
Kind Regards,
Manuel.

Related

How to use VS Code - Python Shell

So I am relatively new to programming and used to use Python's own "IDLE". After I run a ".py" file with IDLE, I am used to getting a python shell or a command window, I don't really know the terminological name for it, where I could play around with the objects inside the script.
For example, if I had a list A=[1,2,3] inside the program, after I run it I get a command console that says ">>" and I can say ">>A" which gives me "[1,2,3]" and I can add elements to A etc.
Now, I want to start using VS Code but I can't seem to find that particular thing. I have a terminal where I can run python code if I give the command "python" first, but It doesn't seem to effect anything inside the script.
I want to use that to see if some objects are working fine and to check their types etc. I add more lines to code after I try from there first, if that makes sense.
Sorry for really bad terminology, I really don't know the names but I can try even more if it's not clear.
Thanks a lot in advance.
Are you looking for the Integrated Terminal of VS Code?
Here are some ways to open the terminal:
Use the ⌃` keyboard shortcut with the backtick character.
Use the View > Terminal menu command.
From the Command Palette (⇧⌘P), use the View: Toggle Integrated Terminal command.
In the window that shows up, enter python and you'll get the Python shell you're looking for.
Try using the integrated terminal inside vs code and make sure that python and pip are properly configured. Type python in the command line and make sure the terminal points to the same folder where your program file is located.

Python in VSCode: How do you run a previous command?

I'm kind of new to software development. Outside of VSCode, I can open up a terminal (let's say PowerShell), run python in it, type in a command (like 2+2), be able to click the up arrow key to find my previous command so that I can run it again.
If I run PowerShell in VSCode and do the same thing, nothing happens when I click the up arrow where I would expect my previous command to be cycled.
Is this a problem with my Python or VSCode? I've been looking for a solution for this but haven't found many useful topics on this.
This was going to just be a comment but its too long. Sorry it isn't more informative than it is. This is kind of an odd problem because VSCode isn't a true IDE. It doesn't have its own shell and just hijacks your powershell or bash terminal, depending on which OS you are using. You should be able to use your up and down arrows just like you can in powershell. I have tested it on my own VSCode installation and it works fine for me. If it's a problem, it's not with python, since VSCode will interact with the terminal the same way no matter which language you are using it for, so its probably with VSCode or your terminal. I have heard of others having issues with up arrow autocomplete in bash, so if you are connecting to a bash terminal that could be it, but I've never heard of it glitching in powershell. I'd say check which terminal you are using, see if the problem persists when you change terminals, and try reinstalling VSCode if it does. Past that, I don't know what to tell you.
I found a work-around. For me, neither git bash, nor PowerShell allowed up/down arrows for history switching within a python shell. So here it goes.
Ctr-Shift-P opens VSCode commands
Python: Create Terminal does not actuallt start python, but it does launch powershell in a mode that will enable us to succeed
py starts python shell with working up/down arrows!

Find the exact .py window/script that corresponds to the IPython console in Spyder

I would like to know if there is way to figure out (from the IPython console) the .py script that was used to run/execute the python commands interactively and thus got printed into the Ipython console.
For eg.
From the below screenshot, looking at the 3+3 in the Ipython console, I can see that it came in when command from untitled2.py was executed.
However when the scripts get long, and IPython output gets long and you are often shifting scripts on the left side, it can be hard to keep track.
So i was wondering if there is a way i can quickly execute some command or view some setting on Ipython console that can tell me that the above line came from untitled.py.
(Spyder maintainer here) There's no way to know from which Editor you're executing some portion of code, sorry.
However, you could use dedicated consoles (under Preferences > Run > Execute in a dedicated console) to have one console per file you execute, as long as you use F5 to run each one of them.
You could edit each .py script, so the first thing it does is to print its name and functionality.
untitled2.py:
print('untitled2.py')
...

Python - hiding characters while typing a password

I have to type in a terminal a user password. googling arround lead to getpass as the most recommended way to do it.
But, somehow- using this function did not hide the characters as expected.
First I thought it has somthing to do with the platform ( Pycharm ), but testing is on IDLE yield the same.
any ideas why ? (code below was on Mac using Python shell)
>> import getpass
>>> a=getpass.getpass(prompt='Password')
Warning: Password input may be echoed.
PasswordTHISISPASSWORD
if you will launch it from IDE it will cause echo will be seen. You can try it in command line terminal it works fine as can be seen in the attached screenshot.
hope this helps
I tried your code with a terminal and with PyCharm too, it works better in terminal but i found a checkbox in the run configurations of PyCharm that avoid the echoing of the password and set it correctly to the variable as you could see with the debugger, but i noticed that if you try to print the variable in some cases it prints something strange.
Click on Edit Configurations... on the left of the run button and check Emulate terminal in output console, it worked with the last version of PyCharm
EDIT: I read just now that you are using a Mac, I tried this with linux, so I'm not sure it will work on mac
In the latest version of Pycharm, all you have to do is update your run configurations.
Run> Edit Configurations> Enable "Emulate terminal in output console"
This enables your Pycharm output console to behave as the terminal. Then, the getpass() function works well without echoing your password.

Python shell unresponsive in emacs

I'm trying to use emacs as my python develloping environement. But I'm facing a problem.
All communication between emacs and any python interactive shell that is called by python-shell seems broken:
The shell seems to start normally, displaying versions and giving me a prompt but then as I enter commands, nothing seems to happen. I have no answer from the interpreter. I can keep writing things but they then stay there in the middle of the screen and nothing happens. I've tried setting regular python interpreter to python and ipython and nothing changes.
I also try to invoke a system shell, that works correctly, and then call python or ipython from there, that brings me back to the same "no response" situation. It just looks like a normal buffer that I can edit. I can delete through the prompt, write some character anywhere in the screen, in the version info... It doesn't looks interactive at all.
What could be the reason of this problem?

Categories

Resources