Literal String Interpolation library

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
Drakoky
Posts: 1
Joined: Tue Feb 23, 2021 11:35 pm

Literal String Interpolation library

Post by Drakoky » Tue Feb 23, 2021 11:48 pm

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.

User avatar
jimmo
Posts: 2244
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Literal String Interpolation library

Post by jimmo » Wed Feb 24, 2021 1:00 am

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.

Post Reply