STINNER Victor <victor.stin...@haypocalc.com> added the comment:

> 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.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue13882>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to