我試圖建立一個產生一個隨機數每次調用時間的函數,它以恆定的整數,我的函數看起來像的輸出整數:增加一個功能
def offsetradf():
global x
x = random.randint(0,7)
return x
y = offsetradf()
和
elif string.find(line,'nslice')==1:
nslice = nslice+y
output_file.write(' nslice = '+str(nslice)+'\n')
我收到的錯誤信息是:
Traceback (most recent call last):
File "./rungenesis.py", line 23, in <module>
nslice = nslice+offsetradf
TypeError: unsupported operand type(s) for +: 'int' and 'function'
任何時候它是在代碼以後稱爲幫助會很棒。
你確定你沒有做 - 'y = offsetradf'而不是'y = offsetradf()'? – 2013-02-19 14:49:58
'nslice + = random.randint(0,7)'? – YXD 2013-02-19 14:50:04