| 1 |
|
| 2 |
|
| 3 |
import nixio |
| 4 |
import datetime as dt |
| 5 |
|
| 6 |
file_name = 'file_create_example.nix' |
| 7 |
|
| 8 |
|
| 9 |
nixfile = nixio.File.open(file_name, nixio.FileMode.Overwrite) |
| 10 |
print("Nix file: %s\n\tformat: %s\n\tversion: %s\n\tcreated at: %s" % (file_name, nixfile.format, nixfile.version, |
| 11 |
str(dt.datetime.fromtimestamp(nixfile.created_at)))) |
| 12 |
nixfile.close() |
| 13 |
|
| 14 |
|
| 15 |
nixfile = nixio.File.open(file_name, nixio.FileMode.ReadOnly) |
| 16 |
|
| 17 |
|
| 18 |
try: |
| 19 |
nixfile.create_block("test block", "test") |
| 20 |
except ValueError: |
| 21 |
print("Error caught: cannot create a new group in nix.FileMode.ReadOnly mode") |
| 22 |
|
| 23 |
nixfile.close() |
| 24 |
|
| 25 |
|
| 26 |
nixfile = nixio.File.open(file_name, nixio.FileMode.ReadWrite) |
| 27 |
nixfile.create_block("test block", "test") |
| 28 |
nixfile.close() |
| 29 |
|
| 30 |
|
| 31 |
nonexistingfilename = "nonexistingfile.nix" |
| 32 |
|
| 33 |
try: |
| 34 |
nixfile = nixio.File.open(nonexistingfilename, nixio.FileMode.ReadOnly) |
| 35 |
except RuntimeError as e: |
| 36 |
print("Error caught: %s" % str(e)) |
| 37 |
print("One cannot open a file, that is not existing and forbidding the library to write it.") |
| 38 |
|
| 39 |
nixfile = nixio.File.open(file_name, mode=nixio.FileMode.Overwrite, compression=nixio.Compression.DeflateNormal) |
| 40 |
nixfile.close() |