Add Python's f-strings (and more?) in Julia?: PEP 498 -- Literal String Interpolation

Is there some package with same in Julia?:

[I kind of recall there’s such a package (or more than one implementing similar ideas).]

Is there value in keeping compatibility with Python as much as possible? Here, at least reserving f"…" in Julia 0.6 even if not implmented yet?

1 Like

Yes, my https://github.com/ScottPJones/StringUtils.jl does a lot of that, however I’m in the process of updating it and moving it an organization.
I was planning on using f"…", and it will implement both C style and Python style formatting, along with cleaner Swift string literal syntax. (The C syntax that Julia uses has a number of issues, whereas the Swift syntax avoids them,
and allows room for expansion).

I meant is there value in having exactly Python’s f-style formatting, nothing more, nothing less? E.g. if someone is porting code. [In general, this could apply to other Python stuff; e.g. I know / has Python 3 semantics…]

And I probably meant then to have f-strings in Base. [Can you reserve f in Base for a future package? Would it not disallow adding that and any package trying to implement the strings later. I guess you can “reserve” informally in docs…]

Was your plan to implement f"…" then somebody else might do it (differently) and it depends on “using”?

[I guess I had GitHub - JuliaIO/Formatting.jl: A Julia package to provide Python-like formatting support “Python-style Types and Functions” in mind, as one package, but it’s 3 years old, and PEP 498/Python 3.6 is brand new.]

I guess your package can implement more e.g. C"…" and Swift"…" and/or utility-functions.

My string literal package actually depends on a modified fork of Formatting.jl (with a set of changes from @tbreloff , and further ones from me).
I am aware of the new PEP, and was hoping to implement a lot of that.
I’m not really interesting in trying to implement the old style Python printing which is positional, like C’s printf, because I think it is better to have the format specification at the same place as the expression being formatted, which is what I allow using an extended interpolation syntax (which starts with , like Swift).
The part that I got from Tom’s PR that never got merged into Formatting.jl, is type based settable defaults, so that
you can set how you want values of a particular type to be formatted, with what padding, precision, etc. This is very powerful)

1 Like