2016-05-08 43 views
1

我正在使用PyTables python包構建HDF5文件。該文件將每天更新最新的滴答數據。我想創建兩個組 - QuotesTrades以及不同期貨到期的表格。我想檢查組Quotes是否存在,如果不存在,然後創建它。在PyTables中做什麼是最好的方法?創建HDF5組/表如果不存在

下面是我對現在所在的代碼片段:

hdf_repos_filters = tables.Filters(complevel=1, complib='zlib') 
for instrument in instruments: 
    if options.verbose: 
    hdf_file = os.path.join(dest_path, "{}.h5".format(instrument)) 
    store = tables.open_file(hdf_file, mode='a', filters=hdf_repos_filters) 
    # This is where I want to check whether the group "Quotes" and "Trades" exist and if not create it 

回答

0

我想我已經想通了。

我在PyTablesFile類中使用File.__contains__(path)方法。

按照文檔:

File.__contains__(path) 

是否有與路徑的節點?

如果文件具有給定路徑(字符串)的節點,則返回True,否則返回False。

PyTables File class