Source

savReaderWriter / savReaderWriter / doc_tests / test_SavReader_get.txt

Full commit
##############################################################################
## Read a file and do a binary search for records (get)
##############################################################################

>>> import pprint
>>> import sys
>>> sys.stdout.write('<skipline> '); from savReaderWriter import * # doctest: +ELLIPSIS
<skipline> ...

## ... Do a binary search for records --> idVar
>>> savFileName = "../savReaderWriter/test_data/Employee data.sav"
>>> try:    # doctest: +ELLIPSIS
...     reader = SavReader(savFileName, idVar="id")       
...     print reader.get(4, "not found")            # gets first record where id==4
...     print reader.get(666, "not found")
...     print reader.get(474, "not found")
...     print reader.get(475, "not found")
...     print reader.get(4, "not found", full=True) # gets all records where id==4
... finally:
...     reader.close()
...
[4.0, 'f', '1947-04-15', 8.0, 1.0, 21900.0, 13200.0, 98.0, 190.0, 0.0]
not found
[474.0, 'f', '1968-11-05', 12.0, 1.0, 29400.0, 14250.0, 63.0, 9.0, 0.0]
not found
[[4.0, 'f', '1947-04-15', 8.0, 1.0, 21900.0, 13200.0, 98.0, 190.0, 0.0]]