0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

HDFについて② 〜File Objects〜

Posted at

備忘録です。かなり初心者なので、どしどしご指摘お願いします。
https://docs.h5py.org/en/latest/index.html
を参考にしています。

# 準備:h5pyパッケージ&HDF5ファイルの読み込み
import h5py
f = h5py.File('myfile.h5','r+')
# r・・・read only ファイルは存在しなくてはならない
# r+・・・Read/write ファイルは存在しなくてはならない
# w・・・create file 新規作成。既存なら初期化
# w-・・・create file 新規作成。既存なら失敗
# a・・・Read/write 新規作成。既存なら別に作成(名前がダブるので注意)。

ファイルは使い終わったら閉じるといいみたいです。

File drivers

ファイルを開くときに、どのドライバを使用するか選べるみたいです。僕はこのコマンド使いません。なんだかよくわからなかったから。そもそもfile driversって何者ですか。
(あとで追記します。きっと)

Python file-like objects

io.BytesIOやtempfile.TemporaryFileといった、Pythonファイルのようなオブジェクトについて。一時的にHDF5を作成するときに便利。

これらのオブジェクトはバイナリ形式で開かれ、read(),write(), seek(),tell(),truncate(),flush()といったメソッドを持つ必要がある。

これもよくわかりませんでした。
(あとで追記します。きっと)

※注意!

pythonなどでHDF5ファイルをいじっているときは、Pythonより先にHDF5を閉じるように!だそうです。

Closing files

strong closing

File.close()と記述するor with h5py.File(...)を離れること。ファイルは閉じられ、オブジェクトは使えなくなる。

weak closing

オブジェクトコードがPythonのコードがカバーする範囲を超えたとき、そのPythonコードに属するオブジェクトがなくなったときに閉じられる。(Pythonの方のファイルが消えたときとかでしょうか?)

正直、後者はいつ使うかわかりません。

Filenames on Linux

(自分がLinux使うのでこれしか読んでません。。)
unicode文字を使うのはノープロブレム。しかし、エンコードされたbytesを使うとたまにおかしくなる。
(あとで追記します。きっと)

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?