注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
原題:
import collections.abc
import unittest
from os.path import exists
import subprocess
"""
We are writing software to analyze logs for toll booths on a highway. This highway is a divided highway with limited access; the only way on to or off of the highway is through a toll booth.
There are three types of toll booths:
* ENTRY (E in the diagram) toll booths, where a car goes through a booth as it enters the highway.
* EXIT (X in the diagram) toll booths, where a car goes through a booth as it exits the highway.
* MAINROAD (M in the diagram), which have sensors that record a license plate as a car drives through at full speed.
Entry Booth Exit Booth
| |
E X
/ \
---<------------<---------M---------<-----------<---------<----
(West-bound side)
=================================================f):
return "<LogEntry timestamp: %f license: %s location: %d direction: %s booth type: %s>" % (
self.timestamp, self.license_plate, self.location, self.direction, self.booth_type)
class LogFile(collections.abc.Sequence):
"""
Represents a file containing a number of log lines, converted to LogEntry objects.
"""
def __init__(self, file_handle):
self.log_entries = []
for line in file_handle:
log_entry = LogEntry(line.strip())
self.log_entries.append(log_entry)
def __getitem__(self, index):
return self.log_entries[index]
def __len__(self):
return len(self.log_entries)
|