diff python/storage.py @ 377:2aed569f39e7

added utils
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Thu, 18 Jul 2013 02:08:51 -0400
parents 14a2405f54f8
children ba813f148ade
line wrap: on
line diff
--- a/python/storage.py	Wed Jul 17 18:19:08 2013 -0400
+++ b/python/storage.py	Thu Jul 18 02:08:51 2013 -0400
@@ -364,9 +364,9 @@
     '''Reads data from the trajectory data provided by NGSIM project
     and converts to our current format.'''
     if append:
-        out = open(outFile,'a')
+        out = utils.openCheck(outFile,'a')
     else:
-        out = open(outFile,'w')
+        out = utils.openCheck(outFile,'w')
     nObjectsPerType = [0,0,0]
 
     features = loadNgsimFile(inFile, sequenceNum)
@@ -391,11 +391,17 @@
         f.write(s+'\n')
 
 def writeTrajectoriesToCsv(filename, objects):
-    f = open(filename, 'w')
+    f = utils.openCheck(filename, 'w')
     for i,obj in enumerate(objects):
         writePositionsToCsv(f, obj)
     f.close()
 
+def writeList(filename, l):
+    f = utils.openCheck(filename, 'w')
+    for x in l:
+        f.write('{}\n'.format(x))
+    f.close()
+
 if __name__ == "__main__":
     import doctest
     import unittest