Mercurial > hg > swc-python-intro
changeset 4:79ef88975054
created a function to check if a line has data or not.
| author | luisf <luis.figueira@eecs.qmul.ac.uk> |
|---|---|
| date | Tue, 05 Feb 2013 17:05:06 +0000 |
| parents | 8a8bccdf4e9c |
| children | f358a45c148e |
| files | python-intro.py |
| diffstat | 1 files changed, 15 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/python-intro.py Tue Feb 05 16:34:56 2013 +0000 +++ b/python-intro.py Tue Feb 05 17:05:06 2013 +0000 @@ -1,16 +1,24 @@ +def is_data(line): + """ Returns true if the line has data + and false otherwise (header, comments, etc)""" + + if line.startswith('#'): + # skip comments + return False + elif line.startswith('D'): + # skip title row + return False + else: + return True + +# script starts here... source = open('data.txt', 'r') number = 0 # count number of data records for line in source: - if line.startswith('#'): - # skip comments - pass - elif line.startswith('D'): - # skip title row - pass - else: + if is_data(line) == True: number = number + 1 source.close()
