python - raw_input that able to do detect multiple input -
i require advise on problem, output must come out :
interact() friends file: friends.csv command: f john cleese john cleese: ministry of silly walks, 5555421, 27 october command: f michael palin unknown friend michael palin command: f invalid command: f command: michael palin invalid command: michael palin command: john cleese, cheese shop, 5552233, 5 may john cleese friend command: michael palin, cheese shop, 5552233, 5 may command: f michael palin michael palin: cheese shop, 5552233, 5 may command: e saving changes... exiting...
i'm required come out function go stuck ,i thinking if there anyway split user input example if user type:
f john cleese
i wonder if split f , john cleese out separate input process output separately. , possible invoke function withint function? code:
def interact(*arg): open('friends.csv', 'ru') print "friends file: friends.csv" resp = raw_input() if "f" in resp: # display friend function display_friends("resp",) print "resp" elif "a" in resp: # add friend function add_friend("resp",)
my display friends function want invoke within function
def display_friends(name, friends_list): fname = name[0] item in friends_list: if item[0] == fname: print item break else: print false
thank guys in advance
first of all, yes, can place function calls other functions.
second of all, if grab user input, in example "f john cleese", can want in code. example:
s = raw_input("please input something: ") # input "f john cleese", value of 's' # printing value of 's' let see exactly. command = s.split(' ', 1) # above code split string 's' on ' ' space, # , once, , create list pieces # value of 'command' ['f', 'john cleese'] example. # access items in command list use brackets [] command[0] # 'f' command[1] # 'john cleese'
with these tools, can consider advice, bid luck!
Comments
Post a Comment