Message152358
> One possibility (still awkward IMO) would be to use the return type as
> the format specifier.
Yeah, I already thaught to this idea. The API would be:
- time.time(format=float)
- time.time(format=decimal.Decimal)
- time.time(format=datetime.datetime)
- time.time(format=?) # for timespec, but I don't think that we need timespec in Python which is a object oriented language, we can use better than low level strutures
- os.stat(path, format=decimal.Decimal)
- etc.
I have to write a function checking that obj is decimal.Decimal or datetime.datetime without importing the module. I suppose that it is possible by checking obj type (it must be a class) and then obj.__module__.
> This would at least require the user to import
> datetime or decimal before calling time() with corresponding
> format.
Another possibility is what I proposed before in the issue #11457: take a callback argument.
http://bugs.python.org/issue11457#msg143738
The callback prototype would be:
def myformat(seconds, floatpart, divisor):
return ...
Each module can implements its own converter and time can provide some builtin converts (because I don't want to add something related to time in the decimal module for example).
But I don't really like this idea because it requires to decide the API of the low level structure of a timestamp (which may change later), and it doesn't really solve the issue of "import decimal" if the converter is in the time module. |
|
Date |
User |
Action |
Args |
2012-01-30 23:15:30 | vstinner | set | recipients:
+ vstinner, loewis, mark.dickinson, belopolsky, pitrou, eric.smith, Arfrever, skrah, Alexander.Belopolsky |
2012-01-30 23:15:29 | vstinner | set | messageid: <1327965329.96.0.695497919885.issue13882@psf.upfronthosting.co.za> |
2012-01-30 23:15:29 | vstinner | link | issue13882 messages |
2012-01-30 23:15:29 | vstinner | create | |
|