To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Revision:

root / python-intro.py @ 4:79ef88975054

History | View | Annotate | Download (535 Bytes)

1
def is_data(line):
2
    """ Returns true if the line has data
3
    and false otherwise (header, comments, etc)"""
4

    
5
    if line.startswith('#'):
6
        # skip comments
7
        return False
8
    elif line.startswith('D'):
9
        # skip title row
10
        return False
11
    else:
12
        return True
13

    
14
# script starts here...
15
source = open('data.txt', 'r')
16

    
17
number = 0
18

    
19
# count number of data records
20
for line in source:
21
    if is_data(line) == True:
22
        number = number + 1
23

    
24
source.close()
25

    
26
print "Total number of data records:", number