我想从 raw_input() 获取多个命令。我一直在用这个:
reply = raw_input(">").split(' ')
command = reply[0]
file = reply[1]
但这对我来说似乎很老套,有没有更好的方法在 python 中做到这一点?
最佳答案
我相信最Pythonic的方式是
command,file = raw_input(">").split()
使用元组解包而不是索引
在Python3.0+中,你可以使用
command,file,*everything_else = raw_input(">").split()#untested
关于Python:扫描raw_input,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11743372/