Movatterモバイル変換
[0]ホーム
[Python-ideas] Briefer string format
Chris Angelicorosuav at gmail.com
Thu Jul 23 05:41:15 CEST 2015
On Thu, Jul 23, 2015 at 1:31 PM, Steven D'Aprano <steve at pearwood.info> wrote:> I would go further and allow all the f prefixes apart from the first to> be optional. To put it another way, the first f prefix "infects" all the> other string fragments:>> msg = (f'a long message here blah blah {x}'> ' and {y} and {z} and more {stuff} and {things}'> ' and perhaps even more {poppycock}'> )>> should be exactly the same as the first version.Editors/IDEs would have to be taught about this (and particularly,taught to show f"..." very differently from "..."), because otherwisea missed comma could be very surprising:lines = [ "simple string", "string {with} {braces}", f"formatted string {using} {interpolation}" # oops, missed a comma "another string {with} {braces}"]Could be a pain to try to debug that one, partly because stuff ishappening at compile time, so you can't even pretty-print linesimmediately after assignment to notice that there are only threeelements rather than four.That solved, though, I think you're probably right about the f prefixinfecting the remaining fragments. It'd be more consistent to have it*not* infect, the same way that an r or u/b prefix doesn't infectsubsequent snippets; but if anyone's bothered by it, they can alwaysstick in a few plus signs.ChrisA
More information about the Python-ideasmailing list
[8]ページ先頭