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.25089e-06
Marked as misclassified No
Message-id <>
> 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.

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:30vstinnersetrecipients: + vstinner, loewis, mark.dickinson, belopolsky, pitrou, eric.smith, Arfrever, skrah, Alexander.Belopolsky
2012-01-30 23:15:29vstinnersetmessageid: <>
2012-01-30 23:15:29vstinnerlinkissue13882 messages
2012-01-30 23:15:29vstinnercreate