raw_input that able to do detect multiple input
Dave Angel
davea at davea.name
Sat Apr 6 21:41:24 EDT 2013
On 04/06/2013 09:03 PM, Frank wrote:
> Hi all, I would require advise on this question for function call interact:
>
> the desire outcome:
> 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: a Michael Palin
> Invalid Command: a Michael Palin
> Command: a John Cleese, Cheese Shop, 5552233, 5 May
> John Cleese is already a friend
> Command: a Michael Palin, Cheese Shop, 5552233, 5 May
> Command: f Michael Palin
> Michael Palin: Cheese Shop, 5552233, 5 May
> Command: e
> Saving changes...
> Exiting...
>
> my code so far for interact:
> #interact function
> def interact(*arg):
> open('friends.csv', 'rU')
> d = load_friends('friends.csv')
> print "Friends File: friends.csv"
> s = raw_input("Please input something: ")
> command = s.split(" ", 1)
> if "f" in command:
> display_friends("command",load_friends('friends.csv'))
> print command
>
> #display friend function
> def display_friends(name, friends_list):
> Fname = name[0]
> for item in friends_list:
> if item[0] == Fname:
> print item
> break
> else:
> print False
>
> Let say if i type in " f John Cleese " and after the line 6 , my value of "command" should be ['f', 'John Cleese']. Is there ways to extract out John Cleese as a input so that i could use it on my function call "display_friends" ?
>
>
Nothing about this message makes any sense to me. The function
display_friends() has no body. Code for load_friends() is missing. You
seem to be confusing variable names with literal strings. You open an
input file "friends.csv", but never use the file handle. You store the
return value of load_friends() in d, but never use it. The "desire
outcome" includes lots of stuff that this code won't be producing.
And I cannot understand the question you ask at the end. However, one
thing I see that's wrong is the user is apparently typing a leading and
trailinb blank on the line. If you want to strip out whitespace before
and after, just use strip().
--
DaveA
More information about the Python-list
mailing list