请帮助解决错误 这是我的代码
#Import Statements#
from textblob import TextBlob #ForAnalyzingGrammarInData
import sys, tweepy #ForAuthentication
import matplotlib.pyplot as plt #ForPlottingPieChart
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
global positive,mixed,negative
class mafia(GridLayout):
#ToShowDataInPercentage
def search(s1,s2):
consumerKey="Kx05pI2ZHtRkQs6LHsLYOkeRK"
consumerSecret="grY1yujbtYBRwfspIS8swiFoXUlTrBgr5I4IwcQhBbWmyFgYPM"
accessToken="2530152451-OO6vRCLjNXQIaHyelo1TdFhSlI8YpBzpUX91RAa"
accessTokenSecret="jscWVipPNASXspdVbwNxiRY1ZpiAw3syUi6agB4kcmr1m"
#PasscodesForAuthentication
auth=tweepy.OAuthHandler(consumer_key=consumerKey,consumer_secret=consumerSecret)
auth.set_access_token(accessToken,accessTokenSecret)
api=tweepy.API(auth)
#UsingTextBlobForAuthentication
searchTerm=str(s1)
numberofSeachTerms=int(s2)
#FirstInput
tweets=tweepy.Cursor(api.search, q=searchTerm, lang="English").items(numberofSeachTerms)
#GetData
positive=0.00
negative=0.00
mixed=0.00
polarity=0.00
#DefineSegregation
for tweet in tweets:
print(tweet.text) #PrintingRecievedData
analysis=TextBlob(tweet.text) #DeclareLoopConditions
polarity+=analysis.sentiment.polarity
if(analysis.sentiment.polarity==0.00):
mixed+=1
elif(analysis.sentiment.polarity<0.00):
negative+=1
elif(analysis.sentiment.polarity>0.00):
positive+=1
#LoopEnds
positive=100*(float(positive)/float(numberofSearchTerms))
negative=100*(float(negative)/float(numberofSeachTerms))
mixed=100*(float(mixed)/float(numberofSeachTerms))
polarity=100*(float(polarity)/float(numberofSeachTerms))
#CallingPercentageFunction
positive=format(positive,'.2f')
negative=format(negative,'.2f')
mixed=format(mixed,'.2f')
#ConvertingToFloatVals
print('How people are reacting on'+searchTerm)
if(polarity==0):
print("Mixed Views")
elif(polarity<0.00):
print("Negatively")
elif(polarity>0.00):
print("Positively")
#Mafia
def chart():
labels=["Positive["+str(positive)+"%]","Mixed Views["+str(mixed)+"%]","Negative["+str(negative)+"%]"]
sizes=[positive,mixed,negative]
colors=["pink","lightgreen","lightblue"]
patches,texts=plt.pie(sizes,colors=colors,startangle=90)
plt.legend(patches,labels,loc="best")
plt.title("People are reacting on"+searchTerm)
plt.axis("equal")
plt.tight_layout()
plt.show()
黑手党(App)类:
def build(self):
return mafia()
黑手党1 =黑手党()
mafia1.run()
kivy code is
:
id:主要
显示:条目
行数:5
内边距:10
间距:10
BoxLayout:
TextInput:
id: entry1
font_size: 32
multiline: False
TextInput:
id: entry2
font_size: 32
multiline: False
BoxLayout:
spacing: 10
CustButton:
text: "submit"
on_press: main.search(entry1.text,entry2.text)
BoxLayout:
TextInput:
id: entry
font_size: 32
multiline: True
BoxLayout:
spacing: 10
CustButton:
text: "chart"
on_press: main.chart`
错误是
[INFO] [Logger]在C:\ Users \ SANKET MAGODIA.kivy \ logs \ kivy_18-08-08_13.txt中记录日志 [信息] [基辅] v1.10.1 [INFO] [Python] v3.6.5(v3.6.5:f59c0932b4,Mar 28 2018,16:07:46)[MSC v.1900 32位(Intel)] [INFO] [Factory]已载入194个符号 [INFO] [Image]提供者:img_tex,img_dds,img_sdl2,img_pil,img_gif(忽略img_ffpyplayer) 追溯(最近一次通话): 文件“ C:\ Users \ SANKET MAGODIA \ AppData \ Local \ Programs \ Python \ Python36-32 \ nehacode.py”,第136行,在 mafia1.run() 运行中的文件“ C:\ Users \ SANKET MAGODIA \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ site-packages \ kivy \ app.py”,行799 self.load_kv(文件名= self.kv_file) 在load_kv中的第596行,文件“ C:\ Users \ SANKET MAGODIA \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ site-packages \ kivy \ app.py” 根= Builder.load_file(rfilename) 在load_file中的第301行,文件“ C:\ Users \ SANKET MAGODIA \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ site-packages \ kivy \ lang \ builder.py” 返回self.load_string(data,** kwargs) 文件“ C:\ Users \ SANKET MAGODIA \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ site-packages \ kivy \ lang \ builder.py”,行368,在load_string中 解析器=解析器(content = string,filename = fn) init 中的第392行的文件“ C:\ Users \ SANKET MAGODIA \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ site-packages \ kivy \ lang \ parser.py” self.parse(内容) 解析中的文件“ C:\ Users \ SANKET MAGODIA \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ site-packages \ kivy \ lang \ parser.py” 对象,剩下的行= self.parse_level(0,行) 在parse_level中,文件“ C:\ Users \ SANKET MAGODIA \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ site-packages \ kivy \ lang \ parser.py”,第605行 级别+ 1,行[i:],空格) 在parse_level中,文件“ C:\ Users \ SANKET MAGODIA \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ site-packages \ kivy \ lang \ parser.py”,行664 如果current_property [:3] =='on_': TypeError:“ NoneType”对象不可下标