我有一个如下列表:
rawinput = ['corp\\asre', 'corp\\banjar', 'corp\\bicknk', 'corp\\daniele']
我希望能够做到
users = []
users = rawinput.split(",")
print(users)
我如何在 Python 3.2 中做到这一点?谢谢。
我有一个如下列表:
rawinput = ['corp\\asre', 'corp\\banjar', 'corp\\bicknk', 'corp\\daniele']
我希望能够做到
users = []
users = rawinput.split(",")
print(users)
我如何在 Python 3.2 中做到这一点?谢谢。
你有什么,
rawinput = ['corp\\asre', 'corp\\banjar', 'corp\\bicknk', 'corp\\daniele']
已经是一个字符串列表。您可以将其作为列表进行迭代。你不需要拆分任何东西。
如果你有这样的事情,
rawinput = "corp\\asre, corp\\banjar, corp\\bicknk, corp\\daniele"
rawinput.split(',')
将返回上述列表。
split()
应用于字符串,作为回报,它会为您提供一个 list[],其中包含子字符串作为按父字符串顺序排列的元素。
在你的情况下:
input = "corp\\asre, corp\\banjar, corp\\bicknk, corp\\daniele"
input.split(',')
将返回
['corp\\asre', 'corp\\banjar', 'corp\\bicknk', 'corp\\daniele']