user-input

How to supply stdin, files and environment variable inputs to Python unit tests?

ε祈祈猫儿з 提交于 2019-11-26 09:33:34
问题 How to write tests where conditions like the following arise: Test user Input. Test input read from a file. Test input read from an environment variable. It\'d be great if someone could show me how to approach the above mentioned scenarios; it\'d still be awesome if you could point me to a few docs/articles/blog posts which I could read. 回答1: All three situations you've described are where you need to specifically go out of your way to ensure you are using loose coupling in your design. Do

C# arrow key input for a console app

你。 提交于 2019-11-26 09:13:18
问题 I have a simple console app written in C#. I want to be able to detect arrow key presses, so I can allow the user to steer. How do I detect keydown/keyup events with a console app? All my googling has led to info about windows Forms. I don\'t have a GUI. This is a console app (to control a robot over a serial port). I have functions written to handle these events, but I have no idea how to register to actually receive the events: private void myKeyDown(object sender, KeyEventArgs e) { switch

How to capitalize first letter of first word in a sentence?

无人久伴 提交于 2019-11-26 07:45:03
问题 I am trying to write a function to clean up user input. I am not trying to make it perfect. I would rather have a few names and acronyms in lowercase than a full paragraph in uppercase. I think the function should use regular expressions but I\'m pretty bad with those and I need some help. If the following expressions are followed by a letter, I want to make that letter uppercase. \".\" \". \" (followed by a space) \"!\" \"! \" (followed by a space) \"?\" \"? \" (followed by a space) Even

How to use View.OnTouchListener instead of onClick

我们两清 提交于 2019-11-26 05:27:20
问题 I\'m developing an Android 2.2.2 application for a client and he wants to do the following: Now I have a button with an onClick event but he doesn\'t like, he wants to dectect when user release the button. I\'ve found View.OnTouchListener which I think this is what I need to use but, is there any posibility to add this event to xml like I did with onClick? <ImageButton android:id=\"@+id/btnSaveNewGate\" android:layout_width=\"@dimen/btnSaveNewGate_width\" android:layout_height=\"@dimen

Getting user input [duplicate]

孤者浪人 提交于 2019-11-26 05:25:11
问题 This question already has answers here : How to read keyboard-input? (5 answers) Closed last year . I am running this: import csv import sys reader = csv.reader(open(sys.argv[0], \"rb\")) for row in reader: print row And I get this in response: [\'import csv\'] [\'import sys\'] [\'reader = csv.reader(open(sys.argv[0]\', \' \"rb\"))\'] [\'for row in reader:\'] [\' print row\'] >>> For the sys.argv[0] I would like it to prompt me to enter a filename. How do I get it to prompt me to enter a

Fill os.Stdin for function that reads from it

帅比萌擦擦* 提交于 2019-11-26 04:54:50
问题 How do I fill os.Stdin in my test for a function that reads from it using a scanner? I request a user command line input via a scanner using following function: func userInput() error { scanner := bufio.NewScanner(os.Stdin) println(\"What is your name?\") scanner.Scan() username = scanner.Text() /* ... */ } Now how do I test this case and simulate a user input? Following example does not work. Stdin is still empty. func TestUserInput(t *testing.T) { var file *os.File file.Write([]byte(\"Tom\"

How to scanf only integer and repeat reading if the user enters non-numeric characters?

守給你的承諾、 提交于 2019-11-26 04:47:47
问题 Here is some C code trying simply to prevent the user from typing a character or an integer less than 0 or more than 23. #include <stdio.h> #include <stdlib.h> int main(void) { const char *input; char *iPtr; int count = 0; int rows; printf(\"Enter an integer: \"); scanf(\"%s\", input); rows = strtol(input, &iPtr, 0); while( *iPtr != \'\\0\') // Check if any character has been inserted { printf(\"Enter an integer between 1 and 23: \"); scanf(\"%s\", input); } while(0 < rows && rows < 24) //

IO happens out of order when using getLine and putStr

╄→гoц情女王★ 提交于 2019-11-26 04:25:33
问题 I\'m a Haskell beginner, I\'m just beginning to wrap my head around Monads, but I don\'t really get it yet. I\'m writing a game that consists of asking the user for input, and responding. Here is a simplified version of my function: getPoint :: IO Point getPoint = do putStr \"Enter x: \" xStr <- getLine putStr \"Enter y: \" yStr <- getLine return $ Point (read xStr) (read yStr) completeUserTurn :: (Board, Player) -> IO (Board, Player) completeUserTurn (board, player) = do putStr $ \"Enter

JavaScript: Check if mouse button down?

放肆的年华 提交于 2019-11-26 02:30:40
问题 Is there a way to detect if a mouse button is currently down in JavaScript? I know about the \"mousedown\" event, but that\'s not what I need. Some time AFTER the mouse button is pressed, I want to be able to detect if it is still pressed down. Is this possible? 回答1: Regarding Pax' solution: it doesn't work if user clicks more than one button intentionally or accidentally. Don't ask me how I know :-(. The correct code should be like that: var mouseDown = 0; document.body.onmousedown =

Is it ever useful to use Python&#39;s input over raw_input?

放肆的年华 提交于 2019-11-26 02:24:56
问题 I currently teach first year university students python, and I was surprised to learn that the seemingly innocuous input function, that some of my students had decided to use (and were confused by the odd behaviour), was hiding a call to eval behind it. So my question is, why does the input function call eval , and what would this ever be useful for that it wouldn\'t be safer to do with raw_input ? I understand that this has been changed in Python 3, but it seems like an unusual design