Thursday, March 31, 2016

p-strings

Currently, there is an interesting debate on python-ideas on the topic of "Would we like to add so-called p-strings to Python?". The p-string idea basically extends the f-string syntax which will be released in the upcoming Python 3.6.

The "p" in p-string stands for path and one of the alternative proposals is to add the following syntactic sugar to Python like this:

p'/someroot/{myvariable}/file.ext'

This basically is supposed to create a pathlib.Path object which allows all sort of convenience methods like extracting the extension or iterating over the parts of the path and more.

Despite the usability improvement, there are of course reservations about the idea. Mainly these are:

  • path vs. str (I will cover this in another post)
  • tying a syntax to a stdlib module (in this case pathlib)
  • security concerns about including user input (same discussion arose with f-strings back then)

If you find the proposal useful or have something else to contribute to the discussion, we look forward to seeing you on the mailing list. :)

Best,
Sven

No comments:

Post a Comment