<div class="gmail_quote">On Tue, Jan 31, 2012 at 7:35 PM, Nick Coghlan <span dir="ltr"><<a href="mailto:ncoghlan@gmail.com">ncoghlan@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Such a protocol can easily be extended to any other type - the time<br>
module could provide conversion functions for integers and float<br>
objects (meaning results may have lower precision than the underlying<br>
system calls), while the existing "fromtimestamp" APIs in datetime can<br>
be updated to accept the new optional arguments (and perhaps an<br>
appropriate class method added to timedelta, too). A class method<br>
could also be added to the decimal module to construct instances from<br>
integer components (as shown above), since that method of construction<br>
isn't actually specific to timestamps.<br></blockquote><div><br></div><div>Why not just make it something like __fromfixed__() and make it a standard protocol, implemented on floats, ints, decimals, etc. Then the API is just "time.time(type)", where type is any object providing a __fromfixed__ method. ;-)</div>
<div> </div></div>