Paul Moore wrote:
2009/10/1 Eric Smith <e...@trueblade.com>:
It's tangential, but in the str.format case you don't want to check for just
'{asctime}', because you might want '{asctime:%Y-%m-%d}', for example.

But there are ways to delay computing the time until you're sure it's
actually being used in the format string, without parsing the format string.
Now that I think of it, the same technique could be used with %-formatting:

Still tangential, but it seems to me that this discussion has exposed
a couple of areas where the logging interface is less than ideal:

- The introspection of the format string to delay computing certain
items (Eric's suggestion may be an improvement here).
- The "call str() on any non-string object to get a format string" API
(which precludes string subclasses).

Calling str on non-string objects to get a format string does not (prima-facie) preclude string subclasses:

>>> class X(str): pass
...
>>> class Y(object):
...  def __str__(self):
...   return X('foo')
...
>>> a = Y()
>>> type(str(a))
<class '__main__.X'>

Michael

I suspect other APIs will exist with similar issues once the whole
question of supporting multiple format syntaxes gets wider
publicity...

Paul.
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/fuzzyman%40voidspace.org.uk


--
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog


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

Reply via email to