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

Path csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <davea@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.060
X-Spam-Evidence '*H*': 0.88; '*S*': 0.00; 'else:': 0.03; 'fname': 0.09; 'literal': 0.09; 'strings.': 0.09; 'def': 0.12; '"f"': 0.16; "['f',": 0.16; 'after,': 0.16; 'command:': 0.16; 'item[0]': 0.16; 'received:74.208.4.195': 0.16; 'silly': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'all,': 0.19; 'typing': 0.19; 'command': 0.22; 'input': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'question': 0.24; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'michael': 0.29; 'code': 0.31; 'apparently': 0.31; 'extract': 0.31; 'file:': 0.31; 'strip': 0.31; 'subject:that': 0.31; 'file': 0.32; 'stuff': 0.32; 'open': 0.33; 'sense': 0.34; 'skip:d 20': 0.34; 'could': 0.34; 'but': 0.35; 'there': 0.35; 'false': 0.36; 'should': 0.36; 'wrong': 0.37; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'blank': 0.60; 'break': 0.61; 'john': 0.61; 'body.': 0.68; 'frank': 0.68; 'invalid': 0.68; 'received:74.208': 0.68; 'saving': 0.69; 'friend': 0.79; 'friends': 0.81; 'confusing': 0.84; 'end.': 0.84; 'missing.': 0.84; 'outcome:': 0.84; 'palin': 0.84; 'shop,': 0.84; 'ministry': 0.91
Date Sat, 06 Apr 2013 21:41:24 -0400
From Dave Angel <davea@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130308 Thunderbird/17.0.4
MIME-Version 1.0
To python-list@python.org
Subject Re: raw_input that able to do detect multiple input
References <cb34034e-8cd5-400b-9b71-7d365326d289@googlegroups.com>
In-Reply-To <cb34034e-8cd5-400b-9b71-7d365326d289@googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:QBBYCdtncBe4i+DYUj9RsZ4zODdxHRwPrnuiSTu6kCb 9gzOS6jnoYVh8qKQxr/lNy7zhvVfwHCd16yRNc7ALKz4svgVW6 9AdEwaqTllRFxlNfFiXj7IxkJaej+iR2eyRuKPxbwO3ZXhmEj7 h45EkNC4GIWxJQBMcZ8e+1U02osnYQY/OxPIu71zcb4HQVuAcj PYi08nRqTmj4HsfVww37OCpV0Uj6mixa5gy/Hq2xjt+aOTESeP s6IZ4bijwxmhVl83qq+NBgrLHC/W7IL40/DvPPivAK+X+PDfe6 SCDYQXcnQFY8HVogHbT3VM7T3tvPUFXOaQDbJ8+ycjZO4oRdw= =
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.220.1365298909.3114.python-list@python.org> (permalink)
Lines 64
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1365298909 news.xs4all.nl 6872 [2001:888:2000:d::a6]:60119
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:42963

Show key headers only | 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