Mercurial > hg > nsaunier > traffic-intelligence
comparison python/utils.py @ 304:20f9cd972dde
added capability to parse cfg file for display-trajectories.py
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Fri, 29 Mar 2013 16:56:23 -0400 |
| parents | 27f06d28036d |
| children | 6c068047edbf |
comparison
equal
deleted
inserted
replaced
| 303:514f6b98cd8c | 304:20f9cd972dde |
|---|---|
| 328 while (len(s) > 0) and (not s.startswith(delimiterCharacter)): | 328 while (len(s) > 0) and (not s.startswith(delimiterCharacter)): |
| 329 dataStrings += [s.strip()] | 329 dataStrings += [s.strip()] |
| 330 s = readline(f) | 330 s = readline(f) |
| 331 return dataStrings | 331 return dataStrings |
| 332 | 332 |
| 333 class FakeSecHead(object): | |
| 334 '''Add fake section header [asection] | |
| 335 | |
| 336 from http://stackoverflow.com/questions/2819696/parsing-properties-file-in-python/2819788#2819788 | |
| 337 use read_file in Python 3.2+ | |
| 338 ''' | |
| 339 def __init__(self, fp): | |
| 340 self.fp = fp | |
| 341 self.sechead = '[main]\n' | |
| 342 | |
| 343 def readline(self): | |
| 344 if self.sechead: | |
| 345 try: return self.sechead | |
| 346 finally: self.sechead = None | |
| 347 else: return self.fp.readline() | |
| 348 | |
| 333 def removeExtension(filename, delimiter = '.'): | 349 def removeExtension(filename, delimiter = '.'): |
| 334 '''Returns the filename minus the extension (all characters after last .)''' | 350 '''Returns the filename minus the extension (all characters after last .)''' |
| 335 i = filename.rfind(delimiter) | 351 i = filename.rfind(delimiter) |
| 336 if i>0: | 352 if i>0: |
| 337 return filename[:i] | 353 return filename[:i] |
