Python 能够检测多个输入的原始输入

Python 能够检测多个输入的原始输入,python,python-2.7,raw-input,Python,Python 2.7,Raw Input,我需要关于这个问题的建议,这是我必须给出的输出: 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 Pali

我需要关于这个问题的建议,这是我必须给出的输出:

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...
我需要拿出一个函数来实现这一点,但我陷入了困境,我在想是否还有其他方法可以分割用户输入,例如,如果用户类型:

f John Cleese
我想知道是否可以将F和johncleese分开作为单独的输入,以便可以单独处理输出。也可以用int调用函数吗?这是我的代码:

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函数

def display_friends(name, friends_list):
Fname = name[0]
for item in friends_list:
    if item[0] == Fname:
        print item
        break
    else:
        print False

提前感谢各位

首先,是的,您可以将函数调用放入其他函数中

其次,如果您获取用户输入,在您的示例“f John Cleese”中,那么您可以在代码中简单地使用它。例如:

s = raw_input("Please input something: ")
# now I input "f John Cleese", so that is now the value of 's'
# printing the value of 's' will let you see what it is exactly.

command = s.split(' ', 1) 
# the above code will split the string 's' on a ' ' space, 
# and only do it once, and then create a list with the pieces
# so the value of 'command' will be ['f', 'John Cleese'] for your example.

# to access items in the command list use brackets []
command[0] # 'f'
command[1] # 'John Cleese'

所有这些工具,你可以考虑作为建议,我祝你好运! 谢谢,我还有一个问题,在我执行命令=s.split(“”,1)之后,我如何从命令中取出F并将其用于其他函数?就像John Cleese的wise一样。我编辑了我的答案,您可以使用括号
[]
访问它们。在提出更多问题之前,请先学习python,这些都是基本的东西,如果您只阅读基本教程,最多需要2个小时,将为您节省大量时间和精力。有很多教程