").split(' ') command = reply[0] file = reply[1]-6ren">
gpt4 book ai didi

Python:扫描raw_input

转载 作者:行者123 更新时间:2023-11-30 23:41:52 24 4
gpt4 key购买 nike

我想从 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com