Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #42963

Re: raw_input that able to do detect multiple input

Date 2013-04-06 21:41 -0400
From Dave Angel <davea@davea.name>
Subject Re: raw_input that able to do detect multiple input
References <cb34034e-8cd5-400b-9b71-7d365326d289@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.220.1365298909.3114.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

raw_input that able to do detect multiple input Frank <jiewei24@gmail.com> - 2013-04-06 18:03 -0700
  Re: raw_input that able to do detect multiple input Dave Angel <davea@davea.name> - 2013-04-06 21:41 -0400
    Re: raw_input that able to do detect multiple input Frank <jiewei24@gmail.com> - 2013-04-06 20:22 -0700
      Re: raw_input that able to do detect multiple input Dave Angel <davea@davea.name> - 2013-04-07 00:36 -0400
        Re: raw_input that able to do detect multiple input Frank <jiewei24@gmail.com> - 2013-04-06 22:00 -0700
          Re: raw_input that able to do detect multiple input Dave Angel <davea@davea.name> - 2013-04-07 01:25 -0400
        Re: raw_input that able to do detect multiple input Frank <jiewei24@gmail.com> - 2013-04-06 22:00 -0700
    Re: raw_input that able to do detect multiple input Frank <jiewei24@gmail.com> - 2013-04-06 20:22 -0700

csiph-web