看看下面的字符串:
E|1256280||2014-01-05 17:54:00|1|2014-01-05 18:59:53|True
我想根据管道符号“|”对其进行分割。因此,我使用以下Python代码(其中line是包含上述描述字符串的字符串):
print line
print str(type(line))
print str(line[1])
parts = line.split['|']
print str(parts)
然而,当使用这段代码时我得到了以下的错误:
E|1256280||2014-01-05 17:54:00|1|2014-01-05 18:59:53|True
<type 'str'>
|
Traceback (most recent call last):
File "/path/to/my/pythonscritp.py", line 34, in crawl_live_quotes
parts = line.split['|']
TypeError: 'builtin_function_or_method' object is not subscriptable
然而,我不明白我在这里做错了什么。 有什么建议吗?
()
而不是[]
。 - Ashwini Chaudharystr.split
是一个函数。你应该用圆括号调用函数,而不是方括号。 - Blender