Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'elif': 0.05; 'insert': 0.05; 'output': 0.05; 'friend.': 0.07; 'arguments': 0.09; 'fname': 0.09; 'function:': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; 'question.': 0.14; '"a"': 0.16; '"e"': 0.16; '"f"': 0.16; "'\\n')": 0.16; "'w')": 0.16; "['f',": 0.16; 'argument,': 0.16; 'command:': 0.16; 'item[0]': 0.16; 'list"': 0.16; 'rough': 0.16; 'silly': 0.16; 'split': 0.19; 'later': 0.20; 'command': 0.22; 'input': 0.22; 'example': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'adds': 0.24; 'char': 0.24; 'question': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; 'function': 0.29; 'appear': 0.29; 'michael': 0.29; 'on,': 0.29; 'statement': 0.30; "i'm": 0.30; 'code': 0.31; 'file:': 0.31; 'invoke': 0.31; 'prints': 0.31; 'subject:that': 0.31; 'maybe': 0.34; 'skip:d 20': 0.34; 'received:209.85': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'false': 0.36; 'interaction': 0.36; "didn't": 0.36; 'should': 0.36; 'list': 0.37; 'received:209': 0.37; 'ends': 0.38; 'sure': 0.39; 'how': 0.40; 'remove': 0.60; 'break': 0.61; 'name:': 0.61; 'john': 0.61; 'further': 0.61; 'first': 0.61; 'information': 0.63; 'name': 0.63; 'invalid': 0.68; 'saving': 0.69; 'friend': 0.79; 'friends': 0.81; 'confusion.': 0.84; 'palin': 0.84; 'shop,': 0.84; 'unclear': 0.84; 'updated,': 0.84; 'ministry': 0.91 X-Received: by 10.49.12.16 with SMTP id u16mr1316226qeb.31.1365304962809; Sat, 06 Apr 2013 20:22:42 -0700 (PDT) Newsgroups: comp.lang.python Date: Sat, 6 Apr 2013 20:22:42 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=202.171.164.211; posting-account=Ku_GgAoAAACcsiNwXg5lFaSDSrqhcidb References: User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 202.171.164.211 MIME-Version: 1.0 Subject: Re: raw_input that able to do detect multiple input From: Frank To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=ISO-8859-1 Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: Lines: 100 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1365304971 news.xs4all.nl 6876 [2001:888:2000:d::a6]:37783 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:42973 Hi Dave, Sorry for my unclear question. I didn't use the d = load_friends('friends.csv') now because I'm going use it for other function later on, I should have remove it first to avoid confusion. This is the code for load_friends , add_info ,display_friends, save_friends function: def load_friends(filename): f = open(filename, 'rU') for row in f: return list (row.strip() for row in f) def add_info(new_info, new_list): # Persons name is the first item of the list name = new_info[0] # Check if we already have an item with that name for item in new_list: if item[0] == name: print "%s is already in the list" % name return False # Insert the item into the list new_list.append(new_info) return True def display_friends(name, friends_list): Fname = name[0] for item in friends_list: if item[0] == Fname: print item break else: print False def save_friends(friend_info, new_list): with open(friend_info, 'w') as f: for line in new_list: f.write(line + '\n') I will elaborate my question further , when the user type the function call interact() this will appear : interact() Friends File: friends.csv so after which the user would type in the command call maybe we call it " F John Cleese", the program need to know if the user input contain a "f" "a" or "e" at the first char and if 'f' it mean it would takes a name as an argument, prints out the information about that friend or prints an error message if the given name is notthe name of a friend in the database(friends.csv). if "a" it would takes four arguments (comma separated) with information about a person and adds that person as a friend. An error message is printed if that person is already a friend. if "e" it would ends the interaction and, if the friends information has been updated, the information is saved to the friends.csv. This is the example output 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... So currently I think i had my other functions ready but I do not know how do i apply it into interact() my rough idea is : def interact(*arg): open('friends.csv', 'rU') d = load_friends('friends.csv') print "Friends File: friends.csv" s = raw_input() command = s.split(" ", 1) if "f" in command: # invoke display_friends function print result elif "a" in command: # invoke add_info function print result elif "e" in command: # invoke save_friends function print result My idea is to split the user command out to ['f', 'John Cleese'] and use the 'F' to invoke my "f" in the if statement and then i would use the display_friends function to process 'John Cleese' but i'm not sure if i'm able to do it this way