【发布时间】:2024-01-22 13:54:01
【问题描述】:
看看下面的字符串:
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
但是,我不明白我在这里做错了什么。有什么建议吗?
【问题讨论】:
-
你需要
()而不是[] -
str.split是一个函数。你用括号而不是方括号调用函数。 -
哦,伙计....谢谢:)