On Thu, Jun 24, 2021 at 10:34 AM micro codery wrote:
> As pointed out already, f-strings and format are subtly different (not
> counting that one can eval and the other cannot). Besides quoting, the
> f-sting mini language has diverged from format's
> >>> spam="Spam"
> >>> f"{spam=}"
> "spam='Spa
What part are you trying to delay, the expression evaluations, or the
string building part?
There was a recent discussion on python-ideas starting at
https://mail.python.org/archives/list/python-id...@python.org/message/LYAC7JC5253QISKDLRMUCN27GZVIUWZC/
that might interest you.
Eric
On 6/24
On Jun 23, 2021, at 16:34, Miro Hrončok wrote:
> Yes, we have a way to check all Fedora's Python packages by reusing our
> Python 3.10 pre-releases test-rebuild-everything mechanism, but it takes a
> few days to finish the builds and analyze the failures. Test failures caused
> by DeprecationWa
As pointed out already, f-strings and format are subtly different (not
counting that one can eval and the other cannot). Besides quoting, the
f-sting mini language has diverged from format's
>>> spam="Spam"
>>> f"{spam=}"
"spam='Spam'"
>>> "{spam=}".format(spam=spam)
Traceback (most recent call las
Except I like the mini-language of f-strings much better than format()’s.
And there is a performance difference between f-strings and format().
> On 24 Jun 2021, at 19:03, Luciano Ramalho wrote:
>
> I don't think that would be a good idea since we already have
> .format() which covers that use
I didn’t make myself clear, sorry.
The code example was just to give an initial what I was suggesting.
The errors you show demonstrate the example is incomplete.
I’d like them to work.
> On 24 Jun 2021, at 18:37, Martin (gzlist) wrote:
>
> On Thu, 24 Jun 2021 at 17:25, Eric Nieuwland wrote:
>>
I don't think that would be a good idea since we already have
.format() which covers that use case and is more flexible than
f-strings (it supports positional arguments, as well as *args and
**kwargs).
I think keeping f-strings simple is a better idea.
Best,
Luciano
On Thu, Jun 24, 2021 at 1:30
On Thu, 24 Jun 2021 at 17:37, Martin (gzlist) wrote:
>
> >>> d = dict(a=1)
> >>> f'{d["a"]}'
> '1'
> >>> str(DelayedFString('{d["a"]}'))
> Traceback (most recent call last):
> File "", line 1, in
> File "", line 5, in __str__
> KeyError: '"a"'
And the other si
On Thu, 24 Jun 2021 at 17:25, Eric Nieuwland wrote:
>
> class DelayedFString(str):
> def __str__(self):
> vars = inspect.currentframe().f_back.f_globals.copy()
> vars.update(inspect.currentframe().f_back.f_locals)
> return self.format(**vars)
This isn't quite right as
for your usecase I'd write:
def delayed_fstring(*, name: str) -> str:
return "The current name is {name}"
def new_scope() -> None:
for name in ["foo", "bar"]:
print(delayed_fstring(name=name))
for logging I use:
class Msg:
def __init__(self, fn: Callable[[], str]):
In a recent discussion with a colleague we wondered if it would be possible to
postpone the evaluation of an f-string so we could use it like a regular string
and .format() or ‘%’.
I found
https://stackoverflow.com/questions/42497625/how-to-postpone-defer-the-evaluation-of-f-strings
and tweake
That sounds great, thanks Mariatta.
-Barry
> On Jun 23, 2021, at 12:36, Mariatta wrote:
>
> My understanding is that Ezio is/will be working on updating PEP 588.
> Last I heard from Ezio is that he would be co-author of PEP 588 and he would
> be updating it/rewrite it to better match the curre
12 matches
Mail list logo