raw-input

Python EOF error raw_input()

♀尐吖头ヾ 提交于 2019-11-28 02:21:16
I'm using Zed Shaw's Learn Python the Hard Way . In exercise 11, the code produces an EOF error on line 2. Here is the code: 1 print "How old are you?", 2 age = raw_input() 3 print "How tall are you?", 4 height = raw_input() 5 print "How much do you weigh?", 6 weight = raw_input() 7 print "So, you're %r old, %r tall and %r heavy." % ( age, height, weight) I have searched StackOverflow, Google, and Hacker News forum. I could not find any answer that (a) solved this problem and (b) I could understand. I am using the python compiler on ideone.com (have also tried two other on-line compilers and

Backwards-compatible input calls in Python

微笑、不失礼 提交于 2019-11-27 23:28:25
I was wondering if anyone has suggestions for writing a backwards-compatible input() call for retrieving a filepath? In Python 2.x, raw_input worked fine for input like /path/to/file. Using input works fine in this case for 3.x, but complains in 2.x because of the eval behavior. One solution is to check the version of Python and, based on the version, map either input or raw_input to a new function: if sys.version_info[0] >= 3: get_input = input else: get_input = raw_input I'm sure there is a better way to do this though. Anyone have any suggestions? Since the Python 2.x version of input() is

How to make a list from a raw_input in python? [duplicate]

怎甘沉沦 提交于 2019-11-27 15:05:53
问题 This question already has an answer here: Get a list of numbers as input from the user 16 answers So I am taking raw_input as an input for some list. x= raw_input() Where I input 1 2 3 4 How will I convert it into a list of integers if I am inputting only numbers? 回答1: Like this: string_input = raw_input() input_list = string_input.split() #splits the input string on spaces # process string elements in the list and make them integers input_list = [int(a) for a in input_list] 回答2: list = map

How to set a default editable string for raw_input?

三世轮回 提交于 2019-11-27 10:01:39
问题 I'm using Python 2.7's raw_input to read from stdin. I want to let the user change a given default string. Code: i = raw_input("Please enter name:") Console: Please enter name: Jack The user should be presented with Jack but can change (backspace) it to something else. The Please enter name: argument would be the prompt for raw_input and that part shouldn't be changeable by the user. 回答1: You could do: i = raw_input("Please enter name[Jack]:") or "Jack" This way, if user just presses return

Use os.listdir to show directories only

旧巷老猫 提交于 2019-11-27 06:57:17
问题 How can I bring python to only output directories via os.listdir , while specifying which directory to list via raw_input ? What I have: file_to_search = raw_input("which file to search?\n>") dirlist=[] for filename in os.listdir(file_to_search): if os.path.isdir(filename) == True: dirlist.append(filename) print dirlist Now this actually works if I input (via raw_input ) the current working directory. However, if I put in anything else, the list returns empty. I tried to divide and conquer

Python EOF error raw_input()

坚强是说给别人听的谎言 提交于 2019-11-27 04:53:10
问题 I'm using Zed Shaw's Learn Python the Hard Way . In exercise 11, the code produces an EOF error on line 2. Here is the code: 1 print "How old are you?", 2 age = raw_input() 3 print "How tall are you?", 4 height = raw_input() 5 print "How much do you weigh?", 6 weight = raw_input() 7 print "So, you're %r old, %r tall and %r heavy." % ( age, height, weight) I have searched StackOverflow, Google, and Hacker News forum. I could not find any answer that (a) solved this problem and (b) I could

Raw_Input() Is Not Defined [duplicate]

本秂侑毒 提交于 2019-11-27 03:49:03
问题 This question already has an answer here: How do I use raw_input in Python 3 7 answers I'm a seventh grade programmer so I may be missing a lot of things in this program, but for my coding club my instructor asked us to make a guess the number game. I have very limited knowledge on this subject, since I've only attended four classes. Anyway, when I run this program in Python IDLE 3.5 this is what it says: Traceback (most recent call last): File "C:\Users\morrris\AppData\Local\Programs\Python

Reading input from raw_input() without having the prompt overwritten by other threads in Python

不打扰是莪最后的温柔 提交于 2019-11-27 02:24:07
问题 I'm trying to let the user input commands at a console using raw_input(), this works fine. The problem is I have background threads that occasionally output log-information to the screen and when they do they mess up the input prompt (since the output go wherever the cursor happens to be at the moment). This is a small Python program that illustrate what i mean. #!/usr/bin/env python import threading import time def message_loop(): while True: time.sleep(1) print "Hello World" thread =

Behaviour of raw_input()

筅森魡賤 提交于 2019-11-27 02:16:52
I wanted to understand the behaviour of raw_input in the below code. I know num will be string. Irrespective of whatever number i enter it always enter the elif part i.e. if num is 5, which should go to if num<check: part or if num is 10 which should go to else part. Every single time it is going to elif . I thought comparing STRING and INT might throw exception( I dont think so) but just in case, so I had included try except but as expected it did not throw any exception. But what puzzles me is why it is ALWAYS hitting elif even when the input given was 10, atleast in that case i was

How to get Coordinates of Touchscreen Rawdata using Linux

二次信任 提交于 2019-11-27 01:40:49
问题 wie have a 3m microtouch display. Its connected to my debian system via usb and recongnized as human interface (hid). I am trying to access and push realtime information... if its getting touched I want to know where (x,y) and pipe it throught netcat to another host. Unfortunately I am only able to get raw data using cat /dev/input/event2 | hexdump or evtest You get hexcode that seem nowhere documented... Does anybody have a clue how to get those information? There must be a way to extract it