On 8/13/07, Andrew James Wade <[EMAIL PROTECTED]> wrote:
> 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.
Sorry, I really don't like imposing *any* syntactic constraints on the
spec apart from !r and !s.
You can get the default format with a custom size by using !s:30.
If you want a custom format *and* padding, just add extra spaces to the spec.
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
_______________________________________________
Python-3000 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe:
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com