Message152358
| Author |
vstinner |
| Recipients |
Alexander.Belopolsky, Arfrever, belopolsky, eric.smith, loewis, mark.dickinson, pitrou, skrah, vstinner |
| Date |
2012年01月30日.23:15:29 |
| SpamBayes Score |
3.2508865e-06 |
| Marked as misclassified |
No |
| Message-id |
<1327965329.96.0.695497919885.issue13882@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
> 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. |
|