[issue28904] add more format conversion flags eg. "len" and "id"

2016-12-08 Thread Berker Peksag

Changes by Berker Peksag :


--
resolution: fixed -> rejected
stage:  -> resolved

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28904] add more format conversion flags eg. "len" and "id"

2016-12-08 Thread Samuel Colvin

Samuel Colvin added the comment:

I see, I hadn't appreciated fstrings where entirely different and more powerful 
than format(), I'll close this.

For anyone else coming to this, with fstrings in >=3.6 you can do:

In [4]: value = [1,2, 3]

In [5]: f'The value is {value}.'
Out[5]: 'The value is [1, 2, 3].'

In [6]: f'The value is {len(value)}.'
Out[6]: 'The value is 3.'

--
resolution:  -> fixed
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28904] add more format conversion flags eg. "len" and "id"

2016-12-08 Thread R. David Murray

R. David Murray added the comment:

Thanks for the idea, but I think we're going to see a shift away from format 
calls and toward fstrings, so I don't think this is worth doing.  See 
https://www.python.org/dev/peps/pep-0498/#id45; the ! expressions are only 
supported by fstrings only for consistency with format, not because they are 
particularly useful with fstrings.

--
nosy: +r.david.murray

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28904] add more format conversion flags eg. "len" and "id"

2016-12-08 Thread Samuel Colvin

Samuel Colvin added the comment:

I know contributing to python is currently a pain (bring on github!) but I'd be 
happy to attempt a patch if others agree this would be useful.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28904] add more format conversion flags eg. "len" and "id"

2016-12-08 Thread Samuel Colvin

New submission from Samuel Colvin:

(The "Components" selection might be wrong, I wasn't sure what to use)

As https://docs.python.org/3.6/library/string.html

> Three conversion flags are currently supported: '!s' which calls str() on the 
> value, '!r' which calls repr() and '!a' which calls ascii().

It would be great if further conversation flags were added for more built-in 
methods. In particular:
* '!l' for len()
* '!i' for id()

(There might be others but these are the two I would find most useful.)

format() is now very powerful, but it's very common for strings, lists, dicts, 
sets etc. to want to include their length in strings. This is currently ugly.

This enhancement will be even more sought after with string literals in python 
3.6.

Example of when this would be very useful:

v = {'type': 'whatever, 'items': ['foo', 'bar', 'spam']}
'{type}{items!l}'.format(**v)

Would also be very useful with getattr, and getitem usage.

--
components: Library (Lib)
messages: 282707
nosy: Samuel Colvin
priority: normal
severity: normal
status: open
title: add more format conversion flags eg. "len" and "id"
type: enhancement
versions: Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com