changeset 3:8a8bccdf4e9c

added a comment to the data file; modified script so that it ignores the comment in the data file.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Tue, 05 Feb 2013 16:34:56 +0000
parents c6c0578924fa
children 79ef88975054
files data.txt python-intro.py
diffstat 2 files changed, 10 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/data.txt	Tue Feb 05 16:21:43 2013 +0000
+++ b/data.txt	Tue Feb 05 16:34:56 2013 +0000
@@ -2,4 +2,5 @@
 2012.04.28,marlin,2
 2012.04.28,turtle,1
 2012.04.28,shark,3
+# I think it was a Marlin... luis
 2012.04.27,marlin,4
--- a/python-intro.py	Tue Feb 05 16:21:43 2013 +0000
+++ b/python-intro.py	Tue Feb 05 16:34:56 2013 +0000
@@ -1,13 +1,18 @@
 source = open('data.txt', 'r')
 
-# reads header line
-source.readline()
-
 number = 0
 
 # count number of data records
 for line in source:
-    number = number + 1
+    if line.startswith('#'):
+        # skip comments
+        pass
+    elif line.startswith('D'):
+        # skip title row
+        pass
+    else:
+        number = number + 1
+
 source.close()
 
 print "Total number of data records:", number