我是 python 新手,正在尝试在 Coursera 数据科学课程上提交我的硬件。环境中有运行 Python 2.7.3 的 VM,我尝试运行的文件 tweet_sentiment.py 中包含以下脚本:
import sys
import json
def hw():
print 'Hello, world!'
def lines(fp):
print str(len(fp.readlines()))
def main():
sent_file = open(sys.argv[1])
tweet_file = open(sys.argv[2])
# hw()
# lines(sent_file)
# lines(tweet_file)
myfile = open(sys.argv[1], 'r')
lines = myfile.readlines()
mydict = {}
for line in lines:
key, value = line.split("\t")
mydict[key] = int(value)
twit_file = open(sys.argv[2], 'r')
twit_lines = twit_file.readlines()
mylist = []
for line in twit_lines:
mylist.append(json.loads(line))
for listik in mylist:
twit_value = 0
twit_text = listik["text"]
twit_words = twit_text.split()
for word in twit_words:
if word in mydict:
twit_value = twit_value + 1
print float(twit_value)
if __name__ == '__main__':
main()
运行 $ python tweet_sentiment.py 时出现以下错误:
File "tweet_sentiment.py", line 25
key, value = line.split("\t")
^
IndentationError: expected an indented block
感谢您的任何提示!谢尔盖