0
我有一個小型的python/pyqt程序,它在第一次運行時運行良好。但是如果我關閉並快速重啓(大約3秒),這個定義會給出錯誤的結果。它運行正常,沒有錯誤,但如果oktype將不會返回true,即使它與第一次運行它完全相同的文件!這個代碼有什麼用?或者是在我的代碼中更高,或者可能是某種垃圾收集錯誤?關閉並快速啓動Python程序的問題
def fileChanged(fileIn, pubNotes, fileType):
pubNotes.clear()
fileType.clear()
filename = str(fileIn.text())
foundtype = 0
oktype = ''
okfiles = ('.max','.ma','.mb','.ni','.nk', '.psd','.ztl', '.tif', '.tiff')
for ftype in okfiles:
if filename.endswith(ftype):
print('File: %s matches pattern %s') % (filename,ftype)
foundtype = 1
print 'ftype er %s' % ftype
oktype = ftype
break
if foundtype:
print('File is of type %s') % oktype
if oktype is '.psd':
typeopt = ['Matte Paint','Texture paint']
for i in range(len(typeopt)):
fileType.addItem(typeopt)
if oktype is '.nk':
typeopt = ['Comp', 'Precomp', 'Roto']
for i in range(len(typeopt)):
fileType.addItem(typeopt[i])
if oktype is '.max':
typeopt = ['Model']
for i in range(len(typeopt)):
fileType.addItem(typeopt[i])
if oktype is '.tif':
typeopt = ['Texture']
for i in range(len(typeopt)):
fileType.addItem(typeopt[i])
#update comboBox_types here
else:
messageBox('File is not of known type, please drag other file')
fileIn.clear
您是否嘗試過使用'oktype =='而不是'oktype is'? – TyrantWave 2012-01-12 16:11:50
與垃圾回收無關 - 問題幾乎可以肯定是實際的文件句柄,如果它沒有正確關閉或者需要由操作系統清理。 – 2012-01-12 16:14:46
TyrantWave:字符串比較沒有區別。 – 2012-01-12 16:15:58