没有输入,只有一些伪私有字段和基本分配,但它在解析错误时仍然给我意想不到的EOF。当有24行代码时,第28行给出了例外情况。
class Word:
def _init_(self,text,size):
self._text = text
self._size = size
def get_size(self):
return self._size
def set_size(self,size):
self._size = size
def set_text(self,text):
self._text = text
def get_text(self):
return self._text
这是另外两个与所请求的最接近的类。
from word import Word
class WordCloud:
def _init_(self, count, freq, stop_words):
self._count = count
self._freq = freq
self._stop_words = stop_words
self._max = freq.maximum
self._min = freq.minimum
self._words = []
def __createword__(self):
keys = self._freq.keys()
list(keys)
values = self._freq.values()
list(values)
for i in (0,self._count,1):
if keys[i] not in stop_word:
newWord = Word(keys[i], math.log(values[i]))
self._words.append(newWord)
else:
i+= -1
def save(self,filename):
for i in self._words:
firstnum = i.get_size()
for j in self._words:
secondnum = j.get_size()
if(secondnum > firstnum)and(j>i):
self._words[i],self._words[j] = self._words[j],self._words[i]
with open(filename,'w') as f:
for word in self._words:
f.write(word.get_text() + ':' + str(word.get_size()) +'\n')
class HtmlWordCloud(WordCloud):
def _init_(self,count,freq,stop_words):
WordCloud._init_(self, count, freq, stop_words)
def save(self, filename):
def size(self,size):
maxSize = math.log(self._max)
minSize= math.log(self._min)
lowerBound = minSize
for i in range(0,91,1):
upperBound = minSize+((i+1)/91)*(maxSize-minSize)
if(size==minSize):
return 10
if(size>lowerBound) and (size<=upperBound):
return 10+i
lowerBound = upperBound
header = '''
<html>
<head>
</head>
<body>
<table>
<tr>
'''
f = open(filename,'w')
f.write(header)
itercount = 0
for i in self._words:
size = size(i.get_size())
line =''' <td><span style = "font-size:'+str(size)+'pt">'+i.get_text()+'</span></td>
'''
f.write(line)
itercount+=1
if itercount is 5:
newrow ='''
</tr>
<tr>
'''
f.write(newrow)
itercount = 0
tail = '''
</tr>
</table>
</body>
</html>'''
f.write(tail)
f.close()
答案 0 :(得分:0)
从概念上讲,错误很简单。 EOF意味着python在寻找某些东西的同时命中了文件的末尾。你在某个地方缺少关闭引号,括号或括号。如果python告诉你这个,这是事实。
如果没有看到实际的代码和错误消息,我们只能在哪里猜测。