Page 1 of 1

Literal String Interpolation library

Posted: Tue Feb 23, 2021 11:48 pm
by Drakoky
Is posible add "Literal String Interpolation" to micropython, this library allow to do the next:

Code: Select all

>>> a = "Drako"
>>> b = "micropython"
>>> f"Hello, my name is {a}, I'm new with {b}."
"Hello, my name is Drako, I'm new with micropython."
When I try to do this in micropython, returns me an error.

Re: Literal String Interpolation library

Posted: Wed Feb 24, 2021 1:00 am
by jimmo
Drakoky wrote:
Tue Feb 23, 2021 11:48 pm
Is posible add "Literal String Interpolation" to micropython, this library allow to do the next:
Yes. This is commonly called "f-strings". There is a PR to add this but it needs a little bit more work. I'm hoping it gets added soon.

It's a surprisingly complicated feature, for example because f-strings can be embedded inside f-strings. We will not be able to support that, but coming up with a "micro" way to do the most useful features while still behaving correctly is a bit tricky.