2012-01-12 6 views
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 
+4

'oktype is'の代わりに' oktype == 'を使ってみましたか? – TyrantWave

+0

ガベージコレクションとは何も関係ありません。問題がほぼ確実に実際のファイルハンドルです。正しく閉じられなかったり、オペレーティングシステムによってクリーンアップされたりする必要がある場合。 –

+1

TyrantWave:文字列の比較に違いはありません。 –

答えて

0

はい! @ TyrantWaveと@reclosedevあなたは絶対に正しいです。私は=の代わりに==を使用しましたが、今は魅力的です!どうもありがとうございます!

関連する問題