2017-06-06 3 views
0

私はPyTablesを使用します。テーブルが作成されているかどうかを確認したい場合は作成していないかどうかを確認してから作成します。NoSuchNodeErrorファイル内のテーブルを決定するとき

私は次のコードを使用:「等級」という名前のそのようなテーブルが存在しないときながら、プログラムのエラー報告

if handle.__contains__(handle.root.grades)==False: 
    handle.create_table('/', 'grades', grades) 

を:「NoSuchNodeError:グループ/は子供が命名されていないgrades

「グレード」という表があると、次のようになります。

handle.__contains__(handle.root.grades) 

を返します。

特定のテーブルがあるかどうかをどのように判断する必要がありますか?

答えて

0

問題に対処するために次の式を使用します。

import tables as tb 
try: 
    handle.__contains__(handle.root.grades) 
    print('contains grades') 
except tb.NoSuchNodeError: 
    print('there is no grades, will create it') 
    handle.create_table('/', 'grades', grades) 

とファイルの式。 がそう

def __contains__(self, path): 

    try: 
     self.get_node(path) 
    except NoSuchNodeError: 
     return False 
    else: 
     return True 

で含まれ、pytablesはいくつかの問題がありますか?テーブルを正しくインポートしないのですか?

関連する問題