[英]inconsistent use of tabs and spaces in indentation notepad++ Python
I am getting an inconsistent use of tabs and spaces in indentation error after adding only one line of code and I can't see why it would throw the error, here is the code: 在添加一行代码后,我在缩进错误中使用制表符和空格不一致,我不明白为什么会抛出错误,这里是代码:
auth = tweepy.OAuthHandler(consumer_key, consumer_secret) #create authentcation handler
auth.set_access_token(access_token, access_secret) #set access tokens to connect to twitter dev account
api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True) #consume tweepy api function,
tweets = api.user_timeline('realDonaldTrump', count=30)
tweets_list = []
for each_tweet in tweets:
tweets_list.append(each_tweet._json)
with open('tweets.csv', 'a') as file:
file.write(json.dumps(tweets_list, indent=4))
my_demo_list = []
with open('tweets.csv', encoding='utf-8') as csvFile:
all_data = json.load(csvFile)
for json_tweet_data in all_data:
tweet_id = json_tweet_data['id']
text = json_tweet_data['text']
favorite_count = json_tweet_data['favorite_count']
retweet_count = json_tweet_data['retweet_count']
created_at = json_tweet_data['created_at']
#lang= json_tweet_data['lang']
my_demo_list.append({'tweet_id': str(tweet_id),
'text': str(text),
'favorite_count': int(favorite_count),
'retweet_count': int(retweet_count),
'created_at': created_at,
'lang':str(lang)
})
print(my_demo_list)
tweet_json = pd.DataFrame(my_demo_list, columns =
['tweet_id', 'text',
'favorite_count', 'retweet_count',
'created_at','language'])
print(tweet_json)
the #lang = json_tweet_data['lang'] line is where the error is appearing and if I remove it or comment it out like it is in the code shown, it will work fine, from what I can see everything is indented fine, what could be the issue here? #lang = json_tweet_data ['lang']行是出现错误的地方,如果我将其删除或者将其注释掉,就像在显示的代码中一样,它会正常工作,从我可以看到的一切都是缩进的,什么可能是这里的问题?
It means exactly what is sounds like: you indented your code with spaces in some places and with tabs in others. 这意味着听起来完全是这样的:您在某些地方使用空格缩进代码,而在其他地方使用制表符缩进代码。 To fix this, in Notepad++, go to Edit -> Blank Operations -> TAB to Space (PEP 8 recommends using spaces vs. tabs).
要解决此问题,请在Notepad ++中,转到编辑 - > 空白操作 - > TAB到空格 (PEP 8建议使用空格与制表符)。
To be sure about spacing in Python scripts, you can use some of sophisticated text editors. 为了确保Python脚本中的间距,您可以使用一些复杂的文本编辑器。 I would recommend you to use Sublime Text 3 or Atom so you can easily handle it next time.
我建议你使用Sublime Text 3或Atom,以便下次可以轻松处理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.