16.07.20 07:34, Charles Machalow пише:
Right now in str.format(), we have !s, !r, and !a to allow us to call str(),
repr(), and ascii() respectively on the given expression.
I'm proposing that we add a !p conversion to have pprint.pformat() be called to
convert the given expression to a
El mar., 21 jul. 2020 a las 17:27, Guido van Rossum ()
escribió:
> A philosophical problem with this is proposal is that it takes a notation
> that is processed by the bytecode compiler and makes it dependent on user
> code to be imported from the stdlib. We only do that in rare cases — IIRC
>
On 7/21/2020 7:36 PM, Rob Cliffe wrote:
On 21/07/2020 21:00, Eric V. Smith wrote:
f-strings call PyObject_Repr directly, without going through builtins.
If we added !p as described here, we'd need to call import every time
we execute !p, because we don't know if it's been imported yet. At
A philosophical problem with this is proposal is that it takes a notation
that is processed by the bytecode compiler and makes it dependent on user
code to be imported from the stdlib. We only do that in rare cases — IIRC
the only other case is ‘import’ calling ‘__import__()’. This reversal of
On 21/07/2020 21:00, Eric V. Smith wrote:
On 7/21/2020 2:54 PM, Alex Hall wrote:
It should do the import for you. As was proposed:
```
print(f"My dict: {d!p}")
```
should be equivalent to
```
import pprint
print(f"My dict: {pprint.pformat(d)}")
```
The import should happen in the same
On 7/21/2020 4:59 PM, Rob Cliffe via Python-ideas wrote:
On 21/07/2020 19:54, Alex Hall wrote:
It should do the import for you. As was proposed:
```
print(f"My dict: {d!p}")
```
should be equivalent to
```
import pprint
print(f"My dict: {pprint.pformat(d)}")
You're right, I didn't read
On 21/07/2020 19:54, Alex Hall wrote:
It should do the import for you. As was proposed:
```
print(f"My dict: {d!p}")
```
should be equivalent to
```
import pprint
print(f"My dict: {pprint.pformat(d)}")
You're right, I didn't read it carefully enough.
```
The import should happen in the
On 7/21/2020 2:54 PM, Alex Hall wrote:
It should do the import for you. As was proposed:
```
print(f"My dict: {d!p}")
```
should be equivalent to
```
import pprint
print(f"My dict: {pprint.pformat(d)}")
```
The import should happen in the same scope. Modifying the global
namespace could be
It should do the import for you. As was proposed:
```
print(f"My dict: {d!p}")
```
should be equivalent to
```
import pprint
print(f"My dict: {pprint.pformat(d)}")
```
The import should happen in the same scope. Modifying the global namespace
could be confusing.
A quick test shows that adding
That seems like a nice idea, but what would happen if pprint had not
been imported? NameError?
Rob Cliffe
On 16/07/2020 05:34, Charles Machalow wrote:
Right now in str.format(), we have !s, !r, and !a to allow us to call str(),
repr(), and ascii() respectively on the given expression.
I'm
+1. I imagine I would use this fairly often, particularly in debugging or
interactive sessions. It goes well with the magic `=` in f-strings, e.g.
`print(f"{d=!p}")`.
It's more useful than the others because the manual way requires an import.
It's easy to learn, easy to remember, and fits
11 matches
Mail list logo