快速关闭和启动Python程序的问题

2024-04-27 22:38:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个小python/pyqt程序,在我第一次运行它时它的功能很好。但是如果我关闭它并快速重启(大约3秒),这个定义会给出错误的结果。它运行良好,没有错误,但是if oktype将不会返回true,即使它与我第一次运行它的文件完全相同!这跟这个代码有什么关系吗?或者它是在我的代码中更高的位置,还是某种垃圾收集错误?在

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

Tags: inforlenifis错误rangefilename