File: filenode.py

package info (click to toggle)
pytables 3.3.0-5
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 14,972 kB
  • ctags: 16,919
  • sloc: python: 59,339; ansic: 46,596; cpp: 1,463; sh: 476; makefile: 428
file content (57 lines) | stat: -rw-r--r-- 1,263 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Copy this file into the clipboard and paste into 'script -c python'.

from __future__ import print_function
from tables.nodes import FileNode


import tables
h5file = tables.open_file('fnode.h5', 'w')


fnode = FileNode.new_node(h5file, where='/', name='fnode_test')


print(h5file.getAttrNode('/fnode_test', 'NODE_TYPE'))


print("This is a test text line.", file=fnode)
print("And this is another one.", file=fnode)
print(file=fnode)
fnode.write("Of course, file methods can also be used.")

fnode.seek(0)  # Go back to the beginning of file.

for line in fnode:
    print(repr(line))


fnode.close()
print(fnode.closed)


node = h5file.root.fnode_test
fnode = FileNode.open_node(node, 'a+')
print(repr(fnode.readline()))
print(fnode.tell())
print("This is a new line.", file=fnode)
print(repr(fnode.readline()))


fnode.seek(0)
for line in fnode:
    print(repr(line))


fnode.attrs.content_type = 'text/plain; charset=us-ascii'


fnode.attrs.author = "Ivan Vilata i Balaguer"
fnode.attrs.creation_date = '2004-10-20T13:25:25+0200'
fnode.attrs.keywords_en = ["FileNode", "test", "metadata"]
fnode.attrs.keywords_ca = ["FileNode", "prova", "metadades"]
fnode.attrs.owner = 'ivan'
fnode.attrs.acl = {'ivan': 'rw', '@users': 'r'}


fnode.close()
h5file.close()