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 same scope. Modifying the global
namespace could be confusing.
You're right again. It could still break code like this:
from pprint import pprint
...
def myfunc():
# Code modified to use !p here
pprint(something) # Oops, pprint is now a module, not a function
unless the import could actually be local to the f-string itself, not
the surrounding scope
(perhaps similar to the way a list comprehension is implemented as a
function with its own scope).
I don't totally understand these matters, so I may have got something wrong.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/python-ideas@python.org/message/44CJYSVFRU4K5XG54T2TMDCMVBHEJRCQ/
Code of Conduct: http://python.org/psf/codeofconduct/