~ubuntu-branches/ubuntu/natty/pytables/natty-updates

« back to all changes in this revision

Viewing changes to examples/tutorial3-1.py

  • Committer: Bazaar Package Importer
  • Author(s): Alexandre Fayolle
  • Date: 2006-06-28 10:45:03 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 5.
  • Revision ID: james.westby@ubuntu.com-20060628104503-cc251q5o5j3e2k10
  * Fixed call to pyversions in debian/rules which failed on recent versions 
    of pyversions
  * Fixed clean rule in debian/rules which left the stamp files behind
  * Acknowledge NMU
  * Added Alexandre Fayolle to uploaders

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""Small example of do/undo capability with PyTables"""
 
2
 
 
3
import tables
 
4
 
 
5
# Create an HDF5 file
 
6
fileh = tables.openFile("tutorial3-1.h5", "w", title="Undo/Redo demo 1")
 
7
 
 
8
         #'-**-**-**-**-**-**- enable undo/redo log  -**-**-**-**-**-**-**-'
 
9
fileh.enableUndo()
 
10
 
 
11
# Create a new array
 
12
one = fileh.createArray('/', 'anarray', [3,4], "An array")
 
13
# Mark this point
 
14
fileh.mark()
 
15
# Create a new array
 
16
another = fileh.createArray('/', 'anotherarray', [4,5], "Another array")
 
17
# Now undo the past operation
 
18
fileh.undo()
 
19
# Check that anotherarray does not exist in the object tree but anarray does
 
20
assert "/anarray" in fileh.objects
 
21
assert "/anotherarray" not in fileh.objects
 
22
# Unwind once more
 
23
fileh.undo()
 
24
# Check that anarray does not exist in the object tree
 
25
assert "/anarray" not in fileh.objects
 
26
assert "/anotherarray" not in fileh.objects
 
27
# Go forward up to the next marker
 
28
fileh.redo()
 
29
# Check that anarray has come back to life in a sane state
 
30
assert "/anarray" in fileh.objects
 
31
assert fileh.root.anarray.read() == [3,4]
 
32
assert fileh.root.anarray.title == "An array"
 
33
assert fileh.root.anarray == one
 
34
# But anotherarray is not here yet
 
35
assert "/anotherarray" not in fileh.objects
 
36
# Now, go rewind up to the end
 
37
fileh.redo()
 
38
assert "/anarray" in fileh.objects
 
39
# Check that anotherarray has come back to life in a sane state
 
40
assert "/anotherarray" in fileh.objects
 
41
assert fileh.root.anotherarray.read() == [4,5]
 
42
assert fileh.root.anotherarray.title == "Another array"
 
43
assert fileh.root.anotherarray == another
 
44
 
 
45
         #'-**-**-**-**-**-**- disable undo/redo log  -**-**-**-**-**-**-**-'
 
46
fileh.disableUndo()
 
47
 
 
48
# Close the file
 
49
fileh.close()