Python raw_input doesn't work in VIM - python

I wrote a simply program:
print "What is your name?"
name = raw_input()
print "Hello %s!" % name
When I run it directly in VIM I get:
What is your name?
Hello print "What is your name?"!
I can't type anything. Program stops with "Hit any key to close this window..."
What is going here? Python 2.7, Win10, VIM 7.4.

Related

Python 3 input() function not allowing input

I haven't really ran into many issues with python but I'm working on a side project and the input() function wasn't working. I created a new file to test out a simple input() function and the same thing happened, the program doesn't take any input and it instead seems to take in the pyenv version or something? Anyone know how to fix this?
# Taking input from the user
name = input("Enter your name")
# Print input
print("Hello", name)
Pasted output from terminal:
Enter your namepyenv shell 2.7.18
Hello pyenv shell 2.7.18

Python IDE PyCharm won't print last line of code

I'm a complete newbie when it comes to coding, so I'm probably making a stupid mistake here. What I'm doing is following along with a Python For Beginners textbook and writing the 'Hello World' exercise. I added the variable 'name' to the code and called the variable in the very next line. However, the
print('Hello', name) line of code I wrote would not print, even though my first line print('Hello, world') did print. Here's a screenshot of the code run on the Python console There are no error codes, so I'm guessing I just incorrectly defined the variable, but I'm not sure.
You need to hit Enter after Python prints 'Keenan' to print the last line.
When you call input(str), str is the prompt. Once python prints the prompt, it's waiting for an input and then Enter.
So logically speaking your code should be:
name = input("What's your name?:")
print('Hello', name)
Which will print:
What's your name?:
where you can type:
What's your name?: Keenan
followed by Enter

Run the code through console by pycharm

Hi I am new to programming and pycharm. I want to run the code below through the python console. I need to enter 3 values to run it. I tried python p13.py one two three but it didn't work.
from sys import argv
script, first, second, third = argv
print "The script is called", script
print "Your first variable is:", first
print "Your second variable is:", second
print "Your third variable is:", third
Could you help me with what am I meant to type into the python consle in pycharm in order to run this.

Interactive Python like Interactive Ruby?

I'm trying to load a ".py" file in Python like I did with a ".rb" file in interactive Ruby. This file runs a code which asks for a user's name, and then prints "Hello (user's name), welcome!". I have searched all over but I can't quite find a solution.
I know how to do this in Ruby, but how can I do this in Python?
Ruby Code (test.rb)
print "Enter your name:"
input = gets.chomp
puts "Hello " + input + "! Welcome to Ruby!"
Python Code (test.py)
name = raw_input("What is your name? ")
print ("Hello" + (name) + "Welcome to Python!")
How I run it in interactive ruby (irb)
So how would I do the same in python?
In Python 2 execfile("test.py") is equivelant to the Ruby load "test.rb"
In Python 3 execfile has been removed probably as this isn't usually the recommended way of working. You can do exec(open("test.py").read()) but a more common workflow would be to either just run your script directly:
python test.py
or to import your test.py file as a module
import test
then you can do reload(test) to load in subsequent edits - although this is much reliable than just re-running python test.py each time for various reasons
This assumes test.py is in a directory on your PYTHONPATH (or sys.path) - typically your shells current folder is already added
You just say import file_name in the python interpreter this should help you. Then file_name.function_to_run() of course you don't have to do this step if you have the function calls at the bottom of the script it will execute everything then stop.
From the command-line
You can use the -i option for "interactive". Instead of closing when the script completes, it will give a python interpreter from which you can use the variables defined by your script.
python -i test.py
Within the interpreter
Use exec
exec(open("test.py").read())
Reference thread.
You are using python 3
so you do it like this
name = input("Enter your name: ")
print("Hello " + name + ". Welcome to Python!")

Coding in VSCode Python 3.6, input doesn't show out put

i'm just getting into programming and i've installed VScode and i've been using python 3.6. When i enter a simple code like:
print("Hello world!")
NAME = input("What's your name?")
print(NAME)
And when i run debug it appears the print Hello world! and the input "What's your name?" and i type whatever, and it doesn't print the NAME afterward.
Thank you in advance for the time taken to answer me.
please use IntegratedTerminal ratherthan internalTerminal
Maybe you can see it:
https://github.com/DonJayamanne/pythonVSCode/wiki/Capture-User-Input-via-input()-or-raw_input()

Categories