indentation - Python 2.7.3 IndentationError: expected an indented block - cant find mistake -
i new python , trying submit hw on coursera data science course. environment there vm running python 2.7.3, file tweet_sentiment.py trying run has following script within it:
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 = {} 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 = [] line in twit_lines: mylist.append(json.loads(line)) listik in mylist: twit_value = 0 twit_text = listik["text"] twit_words = twit_text.split() word in twit_words: if word in mydict: twit_value = twit_value + 1 print float(twit_value) if __name__ == '__main__': main()
when running $ python tweet_sentiment.py getting following error:
file "tweet_sentiment.py", line 25 key, value = line.split("\t") ^ indentationerror: expected indented block
thanks hints! sergey
be careful! you're mixing tabs , spaces indenting.
often tab displayed equivalent of 8 spaces. so, when using common practice of 4 spaces looks 2 levels of indentation, one.
when examine code in editor, can see you've got in @ least 2 places. replace tabs 4 spaces.
Comments
Post a Comment