[issue10660] format() to lower and uppercase

2010-12-10 Thread Hervé Cauwelier

Hervé Cauwelier he...@itaapy.com added the comment:

Thanks for the example. The Python 2.7 documentation about the mini-language 
doesn't clearly state that it is extensible and how. we see examples of 
formatting but not of extending.

Your example would be welcome in the documentation.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue10660
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10660] format() to lower and uppercase

2010-12-09 Thread Hervé Cauwelier

New submission from Hervé Cauwelier he...@itaapy.com:

Hexadecimals can be formatted to lower and uppercase:

 '{0:x}'.format(123)
'7b'
 '{0:X}'.format(123)
'7B'

I would like the same thing for strings:

 '{0.lastname:u} {0.firstname}'.format(user)
'DOE John'

I first thought using S for uppercase, but s is not available for 
lowercase. So I thought about u and l.

The alternative is to write:

 '{0} {1}'.format(user.lastname.upper(), user.firstname)
'DOE John'

But I find it less compact and elegant.

--
components: Interpreter Core
messages: 123684
nosy: Hervé Cauwelier
priority: normal
severity: normal
status: open
title: format() to lower and uppercase
type: feature request
versions: Python 2.7

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue10660
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10660] format() to lower and uppercase

2010-12-09 Thread R. David Murray

R. David Murray rdmur...@bitdance.com added the comment:

The format support is written specifically so that it is extensible.  You can 
write your own string subclass that extends the formatting mini-language with 
whatever features you find useful.  There are too many variations on what might 
be useful with regards to case transformations for this to be a sensible 
addition to the language itself.  Much better that an application create 
use-case tailored facilities.

(Note, by the way, that new features can only go in to 3.3 at this point.)

--
nosy: +r.david.murray
resolution:  - rejected
stage:  - committed/rejected
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue10660
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10660] format() to lower and uppercase

2010-12-09 Thread Eric Smith

Eric Smith e...@trueblade.com added the comment:

I agree with David.

Here's an example of using such a subclass. It extends the format string for 
strings to begin with an optional 'u' or 'l':
---
class U(str):
def __format__(self, fmt):
if fmt[0] == 'u':
s = self.upper()
fmt = fmt[1:]
elif fmt[0] == 'l':
s = self.lower()
fmt = fmt[1:]
else:
s = str(self)
return s.__format__(fmt)

name = 'Hervé Cauwelier'

print('{0:u*^20} {0:l*^20} {0:*^20}'.format(U(name)))
---

It produces:
**HERVÉ CAUWELIER*** **hervé cauwelier*** **Hervé Cauwelier***

--
nosy: +eric.smith

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue10660
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com