Revision 3:8a8bccdf4e9c

View differences:

data.txt
2 2
2012.04.28,marlin,2
3 3
2012.04.28,turtle,1
4 4
2012.04.28,shark,3
5
# I think it was a Marlin... luis
5 6
2012.04.27,marlin,4
python-intro.py
1 1
source = open('data.txt', 'r')
2 2

  
3
# reads header line
4
source.readline()
5

  
6 3
number = 0
7 4

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

  
11 16
source.close()
12 17

  
13 18
print "Total number of data records:", number

Also available in: Unified diff