python 3.9 weird behaviour regarding input function - input

I am using python 3.9 in the newest Pycharm ide. I have a very simple 3 liner:
a=input()
b=input()
print(b)
I input 3, enter, then 4---but somehow the value 4 is not registered, and nothing is printed. Strangely enough, when I add a prompt to the second input function, everything returns normal
a=input()
b=input("test:")
print(b)
The output returns the value b as expected. I have looked everywhere online and could not explain this odd behaviour. What is going on?

Turns out to be a pycharm setting. Had to enable "emulate terminal in output console" under run/edit configurations

Related

PyCharm copy console indicator (`>>>`) when copying text from Python console

When I copy this text:
and paste it into a text field, I just get:
scipy.special.softmax([1,1])
array([0.5, 0.5])
I would like to get:
>>> scipy.special.softmax([1,1])
array([0.5, 0.5])
This is the behaviour when using the Python interactive console normally outside PyCharm.
this seems to be reported already, please see https://youtrack.jetbrains.com/issue/PY-52621/Unable-to-copy-code-from-the-console-as-plain-text and feel free to vote in order to increase the priority.
I apologize for the inconvenience.

PyCharm Selenium not openening Chrome, "Process finished with exit code 0" [duplicate]

I am new to PyCharm and I have 'Process finished with exit code 0' instead of getting (683, 11) as a result (please see attachment), could you guys help me out please? Much appreciate it!
That is good news! It means that there is no error with your code. You have run it right through and there is nothing wrong with it. Pycharm returns 0 when it has found no errors (plus any output you give it) and returns 1 as well as an error message when it encounters errors.
Editors and scripts do not behave like the interactive terminal, when you run a function it does not automatically show the the result. You need to actually tell it to do it yourself.
Generally you just print the results.
If you use print(data.shape) it should return what you expect with the success message Process finished with exit code 0.
exit code 0 means you code run with no error.
Let's give a error code for example(clearly in the below image): in below code, the variable lst is an empty list,
but we get the 5 member in it(which not exists), so the program throws IndexError, and exit 1 which means there is error with the code.
You can also define exit code for analysis, for example:
ERROR_USERNAME, ERROR_PASSWORD, RIGHT_CODE = 683, 11, 0
right_name, right_password = 'xy', 'xy'
name, password = 'xy', 'wrong_password'
if name != right_name:
exit(ERROR_USERNAME)
if password != right_password:
exit(ERROR_PASSWORD)
exit(RIGHT_CODE)
I would recommend you to read up onexit codes.
exit 0 means no error.
exit 1 means there is some error in your code.
This is not pyCharm or python specific. This is a very common practice in most of the programming languages. Where exit 0 means the successful execution of the program and a non zero exit code indicates an error.
Almost all the program(C++/python/java..) return 0 if it runs successful.That isn't specific to pycharm or python.
In program there is no need to invoke exit function explicitly when it runs success it invoke exit(0) by default, invoke exit(not_zero_num) when runs failed.
You can also invoke exit function with different code(num) for analysis.
You can also see https://en.wikipedia.org/wiki/Exit_(system_call) for more details.
What worked for me when this happened was to go to
Run --> Edit Configurations --> Execution --> check the box Run with
Python Console (which was unchecked).
This means that the compilation was successful (no errors). PyCharm and command prompt (Windows OS), terminal (Ubuntu) don't work the same way. PyCharm is an editor and if you want to print something, you explicitly have to write the print statement:
print(whatever_you_want_to_print)
In your case,
print(data.shape)
I think there's no problem in your code and you could find your print results (and other outputs) in the tab 5: Debug rather than 4: Run.
I just ran into this, but couldn't even run a simple print('hello world') function.
Turns out Comodo's Firewall was stopping the script from printing. This is a pretty easy fix by deleting Python out of the Settings > Advanced > Script Analysis portion of Comodo.
Good Luck
I had same problem with yours. And I finally solve it
I see you are trying to run code "Kaggle - BreastCancer.py"
but your pycharm try to run "Breast.py" instead of your code.
(I think Breast.py only contains functions so pycharm can run without showing any result)
Check on tab [Run] which code you are trying to run.
Your starting the program's run from a different file than you have open there. In Run (alt+shift+F10), set the python file you would like to run or debug.

This code is directly from a textbook for Cisco Devnet yet presents a syntax error in python 3.8.1 shell. Why? I tried viewing text in notepad++

while True:
string = input('Enter some text to print. \nType "done" to quit>')
if string == 'done':
break
print(string)
print('Done!')
SyntaxError: invalid syntax
image of issue
Image after idz's suggestion
I think your problem is that you wrote:
while true:
instead of
while True:
However, if you are using Python 2 you should be aware that input will attempt to evaluate what you type in as Python. Depending on what your aim is, you may want to use raw_input instead. This is not an issue if your are using Python 3.

Is there a way to get ipython autocompletion when piping a pandas dataframe to a function?

For example, if I have a pipe function:
def process_data(weighting, period, threshold):
# do stuff
Can I get autocompletion on the process data arguments?
There are a lot of arguments to remember and I would like to make sure they get passed in correctly. In ipython, the function can autocomplete to show me the keyword args which is really neat, but I would like it to do this when piping a pandas dataframe too!
I don't see how this would be possible, but then again, I'm truly in awe of ipython and all its greatness. So, is this possible? If not, are there other hacks that people have come up with?
Install the pyreadline library.
$ pip install pyreadline
Update:
It seems like this problem is specific to some versions of ipython. The solution is the following:
Run below command from the terminal:
$ ipython profile create
It will create a default profile at ~/.ipython/profile_default/ipython_config.py
Now edit this ipython_config.py and add the below lines and it will solve the issue.
c = get_config()
c.Completer.use_jedi = False
Reference:
https://github.com/jupyter/notebook/issues/2435
https://ipython.readthedocs.io/en/stable/config/intro.html

How to have special/accented characters support in IntelliJ terminal

I use the IntelliJ IDEA's Embedded Local Terminal quite a lot, but there is one thing that is driving me nuts : special and accented characters do not work.
This is what should but is not working :
HOME key to go to the beginning of the line : does nothing
END key to go to the end of the line : does nothing
[CTRL + left arrow] to go to previous word : prints D
[CTRL + right arrow] to go to next word : prints C
all accented characters : prints nothing at first, then ? when I hit another key
There are probably other combinations that should but do not work ... but these are the most annoying ones.
I'm using :
Ubuntu 16.04 virtual box guest running on a Windows 10 host
IntelliJ IDEA 2016.2.4
zsh
oh-my-zsh
Important notes :
in a GNU Terminal (outside of IntelliJ then) everything works perfectly, so I don't think that the "running inside a VM" thing is the source of the problem.
if I run bash instead of zsh the special characters are working (home, end, next work, etc...) but I still don't have propre support of accented characters (prints �), and I'd really prefer using zsh.
showkey --scancodes prints Couldn't get a file descriptor referring to the console
if I start od -c I get ^[[H for the HOME key and ^[[F for the END key
showkey --ascii works and prints ^[[H too for the HOME key
What I did already :
checked that the TERM variable is not overridden in .zshrc
add bindkey "${terminfo[khome]}" beginning-of-line and end of line equivalent in .zshrc
add lines (that seemd appropriate) in .inputrc for readline (OK I see now that this was useless as Zsh does not use readline)
edit : I could make the home/end keys work (see accepted answer below), but not the CTRL+LEFT and CTRL+RIGHT key (for forward-word and backward-word). After some more digging this seems to be an issue with IntelliJ not 100% properly emulating the terminal. 4
There is an issue here, with interesting input from an oh-my-zsh contributor : https://youtrack.jetbrains.com/issue/IDEA-118848#comment=27-1292473
They consider ditching smkx (which appears to be the root of the problem) from oh-my-zsh soon. I've checked out this PR and now my keys work fine (still need the bindings, but CTRL+LEFT and CTRL+RIGHT are ok now)
edit: accented/special characters are now properly supported in IntelliJ (yeehaa !), be sure to have at least the following version : IntelliJ IDEA 2016.3.1, Build #IC-163.9166.29, built on December 9, 2016
I can appreciate that zsh works fine outside IntelliJ.
Step 1
Find the correct key codes being used by the terminal inside Intellij. This will depend on the OS you are using. For OSX and Linux od -c followed by pressing the keys will result in the key code being emitted.
Step 2
Once you have the keycodes, modify your ~/.zshrc :
bindkey "$HOME_KEY_CODE_FROM_STEP_1" beginning-of-line
bindkey "$END_KEY_CODE_FROM_STEP_1" end-of-line
for example (as was the case for the OP):
bindkey "^[[H" beginning-of-line
bindkey "^[[F" end-of-line
and restart the terminal.