raw-input

How could I save data after closing my program?

我的未来我决定 提交于 2019-12-03 22:46:26
问题 I am currently working on a phone book directory using dictionaries. I didn't know any way to save the information after closing the program. I need to save the variable Information so that I can add more later and print it. Information={"Police":911} def NewEntry(): Name=raw_input("What is the targets name?") Number=raw_input("What is the target's number?") Number=int(Number) Information[Name]=Number NewEntry() print Information Edit: I am now using the Pickle module and this is my current

Get a String from a collection of keys presses retrieved using Raw Input API

∥☆過路亽.° 提交于 2019-12-03 15:41:17
I am using the Raw Input API to get a collection of key presses from a keyboard (actually, a magnetic stripe card reader that emulates a keyboard). Here are a couple of code excerpts so you can have an idea of how I'm getting the keys. [StructLayout(LayoutKind.Sequential)] internal struct RAWKEYBOARD { [MarshalAs(UnmanagedType.U2)] public ushort MakeCode; [MarshalAs(UnmanagedType.U2)] public ushort Flags; [MarshalAs(UnmanagedType.U2)] public ushort Reserved; [MarshalAs(UnmanagedType.U2)] public ushort VKey; [MarshalAs(UnmanagedType.U4)] public uint Message; [MarshalAs(UnmanagedType.U4)] public

Use of input/raw_input in python 2 and 3 [duplicate]

和自甴很熟 提交于 2019-12-03 14:24:50
问题 This question already has answers here : Backwards-compatible input calls in Python (4 answers) Closed last year . I would like to set a user prompt with the following question: save_flag is not set to 1; data will not be saved. Press enter to continue. input() works in python3 but not python2. raw_input() works in python2 but not python3. Is there a way to do this so that the code is compatible with both python 2 and python 3? 回答1: Bind raw_input to input in Python 2: try: input = raw_input

How to go back to first if statement if no choices are valid

柔情痞子 提交于 2019-12-03 13:27:18
问题 How can I have Python move to the top of an if statement if no condition is satisfied correctly. I have a basic if/else statement like this: print "pick a number, 1 or 2" a = int(raw_input("> ") if a == 1: print "this" if a == 2: print "that" else: print "you have made an invalid choice, try again." What I want is to prompt the user to make another choice for this if statement without them having to restart the entire program, but am very new to Python and am having trouble finding the answer

Use of input/raw_input in python 2 and 3 [duplicate]

天涯浪子 提交于 2019-12-03 04:13:06
This question already has an answer here: Backwards-compatible input calls in Python 4 answers I would like to set a user prompt with the following question: save_flag is not set to 1; data will not be saved. Press enter to continue. input() works in python3 but not python2. raw_input() works in python2 but not python3. Is there a way to do this so that the code is compatible with both python 2 and python 3? Ashwini Chaudhary Bind raw_input to input in Python 2: try: input = raw_input except NameError: pass Now input will return a string in Python 2 as well. If you're using six to write 2/3

raw_input() won't show prompt until after input

半腔热情 提交于 2019-12-02 18:48:13
问题 It actually goes further than the title suggests, if I have raw_input() anywhere in main, nothing will happen until the input has been entered by the user including any function calls or outputs that should occur before raw_input is called. Here's a very simple example of my code and what occurs when it's run. def main(): answer = raw_input('Continue?') print 'You said: ', answer When I run it: (nothing comes on screen) (user input) blah blah blah (Output): Continue?You said: blah blah blah I

How can i use raw_input and string formatting % or %d python

与世无争的帅哥 提交于 2019-12-02 12:26:55
i have variable var, and it is changeable how can i use raw_input and inside raw_input make a question and use this variable i.e. z = raw_input("Is your age %d') %(var) but this don't work. Any ideas? With raw_input , %var should also lie within the parentheses. i.e: z = raw_input("Is your age %d" % var) I guess the cleanest way is to use format : z = raw_input("Is your age {0}?".format(var)) Your code should be: z = raw_input("Is your age %d" %(var,) ) 来源: https://stackoverflow.com/questions/24230069/how-can-i-use-raw-input-and-string-formatting-or-d-python

Calling/selecting variables (float valued) with user input in Python

扶醉桌前 提交于 2019-12-02 07:29:17
问题 I've been working on a computational physics project (plotting related rates of chemical reactants with respect to eachother to show oscillatory behavior) with a fair amount of success. However, one of my simulations involves more than two active oscillating agents (five, in fact) which would obviously be unsuitable for any single visual plot... My scheme was hence to have the user select which two reactants they wanted plotted on the x-axis and y-axis respectively. I tried (foolishly) to

Calling/selecting variables (float valued) with user input in Python

馋奶兔 提交于 2019-12-02 03:13:43
I've been working on a computational physics project (plotting related rates of chemical reactants with respect to eachother to show oscillatory behavior) with a fair amount of success. However, one of my simulations involves more than two active oscillating agents (five, in fact) which would obviously be unsuitable for any single visual plot... My scheme was hence to have the user select which two reactants they wanted plotted on the x-axis and y-axis respectively. I tried (foolishly) to convert string input values into the respective variable names, but I guess I need a radically different

How to accurately measure mouse movement in inches or centimetres for a mouse with a known DPI

强颜欢笑 提交于 2019-12-02 02:07:50
问题 I have a Logitech G500 gaming mouse that is running at its full DPI of 5700. I'm trying to write a program in C++ that accurately measures horizontal movement of the mouse in physical units, ie. centimetres or inches. I'm using the windows API and windows raw input via the WM_INPUT message to get raw movement changes from the mouse. I'm then assuming 1 unit of movement reported through WM_INPUT is 1/5700th of an inch, and as I'm tracking the net movement of the mouse, I thought I could