尝试在你的Python 3.3.2 IDLE中输入这个,希望我不是唯一一个想知道并且我愿意理解为什么会这样的人.
>>> n = 331
>>> d = 165.0 # float number
>>> a = 174
>>>
>>> a**d % n
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
a**d % n
OverflowError: (34, 'Result too large')
>>> d = int(d)
>>> a**d % n
330
Run Code Online (Sandbox Code Playgroud)
浮标究竟是如何工作的,为什么会发生这种情况?谢谢.
让我通过我的确切代码:这是短模块
class SentenceSplitter:
def __init__(self, filename=None):
self._raw_text = self.raw_text(filename)
self._sentences = self.to_sentences()
def raw_text(self, filename):
text = ''
with open(filename, 'r') as file:
for line in file.readlines():
line = line.strip()
text += ''.join(line.replace(line, line+' '))
file.close()
text = text.strip() # Deal with the last whitespace
return text
def to_sentences(self):
""" Sentence boundaries occur at '.', '!', '?' except that,
there are some not-sentence boundaries that
may occur before/after the period.
"""
raw_text = self._raw_text
sentences = []
sentence = '' …
Run Code Online (Sandbox Code Playgroud) 所以我有一个TerrainManager
类,它会TerrainStructure
在列表中存储很少的对象.我有一个方法,在TerrainStructure
类中称为generate_pillar_points()
它用于设置属性的x, y
值TerrainStructure
.
我应该分配属性来引用类吗?我认为这可能是一个很好的方法,因为我可以查看属性并看到它将是一个Point
对象.或者我应该将默认值设置为None或0,稍后,当我调用generate_pillar_points()
将这些属性设置为Point
类的实例时
考虑到这一点,我问这个问题:
a = Cls # reference to Cls
a = Cls() # instance of Cls
这是代码,我相信我会更清楚我要问的问题.
class Point(object):
def __init__(self, x, y):
self.x, self.y = x, y
class TerrainStructure(object):
def __init__(self):
# what default values should this points have?
self.top_left, self.top_right = Point, Point
self.bottom_left, self.bottom_right = Point, Point
# picks 4 random points between fixed ranges
# and …
Run Code Online (Sandbox Code Playgroud)