On Mon, 13 Aug 2007 20:53:26 -0700
"Guido van Rossum" <[EMAIL PROTECTED]> wrote:

...

> One of my favorite examples of non-numeric types are the date, time
> and datetime types from the datetime module; here I propose that their
> __format__ be defined like this:
> 
>   def __format__(self, spec):
>       return self.strftime(spec)

You loose the ability to align the field then. What about:

    def __format__(self, align_spec, spec="%Y-%m-%d %H:%M:%S"):
        return format(self.strftime(spec), align_spec)
 
with

    def format(value, spec):
        if "," in spec:
            align_spec, custom_spec = spec.split(",",1)
            return value.__format__(align_spec, custom_spec)
        else:
            return value.__format__(spec)

":,%Y-%m-%d" may be slightly more gross than ":%Y-%m-%d", but on the plus
side ":30" would mean the same thing across all types.

-- Andrew
_______________________________________________
Python-3000 mailing list
Python-3000@python.org
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe: 
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com

Reply via email to