raw-input

What is the proper way to take a directory path as user input?

让人想犯罪 __ 提交于 2019-11-30 12:48:31
Below is a snippet of code I am trying to use to take a directory path as "raw input" from the user. I receive the following error after the input is taken from the user: Traceback (most recent call last): File "C:\Users\larece.johnson\Desktop\Python Programs\Hello World 2", line 14, in <module> f = open(str,"r+") #I open the text file here which the user gave me IOError: [Errno 2] No such file or directory: 'C:/Users/larece.johnson/Desktop/Python Programs/BostonLog.log.2014-04-01' Ignoring what I have done below, is there a particular way I am supposed to take the path from user so that

User input with a timeout, in a loop

a 夏天 提交于 2019-11-30 09:00:19
问题 I'm trying to create a looping python function which performs a task and prompts the user for a response and if the user does not respond in the given time the sequence will repeat. This is loosely based off this question: How to set time limit on raw_input The task is represented by some_function() . The timeout is a variable in seconds. I have two problems with the following code: The raw_input prompt does not timeout after the specified time of 4 seconds regardless of whether the user

Python raw_input ignore newline

被刻印的时光 ゝ 提交于 2019-11-30 03:30:57
问题 Is there a way to ignore newline characters in data entered through raw_input? I am trying to use raw_input to input a list of strings that are copied and pasted from a spreadsheet. the problem is that it appears that the new line characters cause the data to be entered prematurely. All the empty spaces will be stripped anyway, so removing the newlines as the data is entered would be an added benefit. This data needs to be entered directly through the terminal prompt and not read from a file.

How to set a default editable string for raw_input?

南笙酒味 提交于 2019-11-29 20:16:17
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. You could do: i = raw_input("Please enter name[Jack]:") or "Jack" This way, if user just presses return without entering anything, "i" will be assigned "Jack". Eric Leschinski Python2.7 get raw_input and set a

Create a raw input with commands inside a Python script

。_饼干妹妹 提交于 2019-11-29 18:20:50
I'm trying to implement a small script to manage a localhost with an FTP connection in Python from the command line and using the appropriate "ftplib" module. I would like to create a sort of raw input for the user but with some commands already setup. I try to explain better: Once I have created the FTP connection and login connection been successfully completed through username and password, i would show a sort of "bash shell" with the possibility to use the most famous UNIX commands ( for example cd and ls respectively to move in a directory and show file/folders in the current path ). For

Create a raw input with commands inside a Python script

北城余情 提交于 2019-11-28 12:32:48
问题 I'm trying to implement a small script to manage a localhost with an FTP connection in Python from the command line and using the appropriate "ftplib" module. I would like to create a sort of raw input for the user but with some commands already setup. I try to explain better: Once I have created the FTP connection and login connection been successfully completed through username and password, i would show a sort of "bash shell" with the possibility to use the most famous UNIX commands ( for

Use os.listdir to show directories only

眉间皱痕 提交于 2019-11-28 12:19:20
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 this problem but individually every code piece works as intended. that's expected, since os.listdir only

How to get Coordinates of Touchscreen Rawdata using Linux

痞子三分冷 提交于 2019-11-28 08:41:35
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 from the hexcode. Unfortunately I have no idea how to interpret the hexcode. I couldnt find any source

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

╄→гoц情女王★ 提交于 2019-11-28 08:34:15
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 = threading.Thread(target = message_loop) thread.start() while True: input = raw_input("Prompt> ") print "You

Using wxPython to get input from user

こ雲淡風輕ζ 提交于 2019-11-28 04:03:34
问题 Suppose I need to replace the raw_input function in the following code with a wxPython dialog box that asks for user input and returns the value to program: ... x = raw_input("What's your name?") print 'Your name was', x ... I'm just looking for a simple way to do that. Thanks 回答1: Here is another simple way that does what I was looking for: import wx def ask(parent=None, message='', default_value=''): dlg = wx.TextEntryDialog(parent, message, defaultValue=default_value) dlg.ShowModal()