proposal to allow to set the delimiter in str.format to something other than curly bracket

Terry Reedy tjreedy at udel.edu
Mon Apr 4 01:17:52 EDT 2011


On 4/3/2011 6:07 AM, Alia Khouri wrote:
> Hi folks,
>
> I've been using ironpython2.7 in a project, and I was generating some
> csharp code when i discovered that I couldn't use use str.format
> because the interference with the brackets-aplenty situation in
> csharp.
>
> In [1]: code = "class {0}Model { public bool IsModel(){ return
> true; } }"
>
> In [2]: code.format('My')

Just double the brackets, just as one doubles '\\' to get '\' in a string.

 >>> "class {0}Model {{ public bool IsModel(){{ returntrue; }} 
}}".format('My')
'class MyModel { public bool IsModel(){ returntrue; } }'


-- 
Terry Jan Reedy




More information about the Python-list mailing list