To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / python-intro.py @ 3:8a8bccdf4e9c
History | View | Annotate | Download (331 Bytes)
| 1 |
source = open('data.txt', 'r') |
|---|---|
| 2 |
|
| 3 |
number = 0
|
| 4 |
|
| 5 |
# count number of data records
|
| 6 |
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:
|
| 14 |
number = number + 1
|
| 15 |
|
| 16 |
source.close() |
| 17 |
|
| 18 |
print "Total number of data records:", number |