I'm trying to highlight part of my output in the Windows console as follows:
print 'Matches:'+'\033[0;33m'+str(123)+'\033[0;0m'
It works fine in a Linux terminal, but under Windows it shows
>>>Matches:[0;33m123[0;0m
How can I enable highlighting in the Windows console?
PS: I think there should be a way to do this because it works with raw_input. For example:
I have tried a method, mentioned by #eryksun, thanks for your help.
from IPython.utils.io import stdout;
stdout.write('Matches:'+'\033[0;33m'+str(123)+'\033[0;0m')
Here is the outout:
For further discussion, I find that even in pure python shell, the raw_input() works fine to highlight the text, but stdout.write is not working any more.
Here is the python shell output:
Related
Here's the code:
import emoji
import time
print("\U0001F600")
time.sleep(50)
Here's the output when I run in the python idle shell thingo:
Here's the output when I run the program in windows terminal thingo:
I've got this game thing I'm working on for an assignment, and I've simply just copy pasted emojis into the print function, and when I run it in PyCharm, it works just like in idle shell. But when I turn it into an executable using the pyinstaller module thing, it just shows ? instead of the emoji.
By the way, I'm not that advanced in this kinda thing, so I'd appreciate if someone could explain how to fix this problem :)
This does not work in the normal cmd console. If so, you need the
Terminal
(In addition, you do not need the emoji module for your method)
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.
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.
I installed package called Anaconda into my Sublime Text 3
Simple command such as 1+1 doesn't show anything but function print does.
Simple code like 1+1 doesn't work
But python's print function works well.
Can you tell me what am I doing wrong?
Sublime console is not made an interactive console. When you run the python code it actually runs the file. You can check this by typing 1+1 in a file, saving it in a .py format and then running the file as
python -u filename.py
which is how sublime executes the code as seen in https://www.youtube.com/watch?v=6ZpuwW-9T54 at 2:36.
You can check the same response to a similar question in this discussion forum as well. https://forum.sublimetext.com/t/running-python-on-sublime-console/18621/2
Yes it may give you correct answers for the script part i.e print but for things such as 1+1 you need an interactive console. You can just install anaconda directly in your os from this link this would be better.
What are the key differences between Python's IDLE and its command line environment? IDLE looks nicer, of course, and has some kind of GUI...
Moreover, is IDLE treated the same as the shell? I mean, the shell is the middle layer between the user and Python's interpreter?
They are both the same thing but, IDLE is made to write python code so its better if you can to write on IDLE. You can also try Notepad++ its a pretty good program to write code on.
I am not sure what you question is, but here is a Windows-7 oriented answer of similarity and difference. In the start menu for Python x.y, you can select 'Python x.y (x bits)' to run python interactive in a text-line-oriented console window provided by Microsoft. The console handles key presses and mouse movements and clicks. When you hit , the console sends the line of text to python, which is waiting for input on sys.stdin. When Python processes the line, it sends output to sys.stdout or sys.stderr. This includes '>>> ' and '... ' prompts. The console displays the text for you to see.
In the start menu, you can instead select 'Idle ...'. Unless you have previously selected a different startup option, python run Idle code which uses the tkinter module which used tcl/tk to run a graphical user interface that somewhat imitates the console. The tkinter/tk gui handles key and mouse input and displays output. In both cases, some software besides the Python interpreter itself handles interaction between you and Python.
Some important differences:
Cut, copy, and paste work normally. The Windows console is crippled in this respect.
Idle colors input and output. The Windows console does not.
Idle can display all unicode BMP (the first 64K) chars. The Windows console is limited by code pages.
For 1, 2, and 3, the console of other OSes may do as well or better than Idle.
Idle lets you enter, edit, send, and retrieve complete statements. Interactive python with Windows console only works with physical lines.
Update, 2017/11:
Item 1 above: At least on current Win10, cut, copy, and paste work normally.
Item 3 above: At least on Win10, unicode works better in Command Prompt with 3.6+.
New item 5: The IDLE doc section, also available as Help => IDLE Help now has section '3.3. IDLE-console differences'.
IDLE is a very simple Integrated Development Environment. It runs the same python, libraries etc. as commant-line.
Even more basic (with less features) is IPython. Full feature IDE for Python is, for example, Eclipse with PyDev plugin, or LiClipse.
Python IDLE is where you write your program/s and Python Shell is where you run your program/s.