File: test_File.py

package info (click to toggle)
python-biopython 1.54-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 25,400 kB
  • ctags: 10,975
  • sloc: python: 116,757; xml: 33,167; ansic: 8,622; sql: 1,488; makefile: 147
file content (59 lines) | stat: -rw-r--r-- 1,285 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
58
59
# Copyright 1999 by Jeffrey Chang.  All rights reserved.
# This code is part of the Biopython distribution and governed by its
# license.  Please see the LICENSE file that should have been included
# as part of this package.

import os
import string
from Bio import File



data = """This
is
a multi-line
file"""



### StringHandle

h = File.StringHandle(data)
print repr(h.readline())  # 'This'
print len(h.readlines())  # 3
print repr(h.readline())  # ''
h.close()



### UndoHandle

h = File.UndoHandle(File.StringHandle(data))

print h.readline()   # 'This'
print h.peekline()   # 'is'
print h.readline()   # 'is'
h.saveline("saved")
print h.peekline()   # 'saved'
h.saveline("another")
print h.readline()   # 'another'
print h.readline()   # 'saved'

# Test readlines after saveline
h.saveline("saved again")
lines = h.readlines()
print repr(lines[0])   # 'saved again'
print repr(lines[1])   # 'a multi-line'
print repr(lines[2])   # 'file'
    
# should be empty now
print repr(h.readline())       # ''
    
h.saveline("save after empty")
print h.readline()             # 'save after empty'
print repr(h.readline())       # ''

# test read method
h = File.UndoHandle(File.StringHandle("some text"))
h.saveline("more text")
print h.read()                 # 'more textsome text'