Revision 4:79ef88975054

View differences:

python-intro.py
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...
1 15
source = open('data.txt', 'r')
2 16

  
3 17
number = 0
4 18

  
5 19
# count number of data records
6 20
for line in source:
7
    if line.startswith('#'):
8
        # skip comments
9
        pass
10
    elif line.startswith('D'):
11
        # skip title row
12
        pass
13
    else:
21
    if is_data(line) == True:
14 22
        number = number + 1
15 23

  
16 24
source.close()

Also available in: Unified diff