[issue39842] partial_format()

2020-03-04 Thread Eric V. Smith
Eric V. Smith added the comment: Well, I'm the one who made them private, I can make them public if they're useful. But I won't do that if you're not willing to look at it. -- ___ Python tracker ___

[issue39842] partial_format()

2020-03-04 Thread Marco Sulla
Marco Sulla added the comment: @Eric V. Smith: that you for your effort, but I'll never use an API marked as private, that is furthermore undocumented. -- ___ Python tracker

[issue39842] partial_format()

2020-03-04 Thread Marco Sulla
Marco Sulla added the comment: > What would "{} {}".partial_format({}) return? `str.partial_format()` was proposed exactly to avoid such tricks. > It is not possible to implement a "safe" variant of str.format(), > because in difference to Template it can call arbitrary code If you read the d

[issue39842] partial_format()

2020-03-04 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: What would "{} {}".partial_format({}) return? It is not possible to implement a "safe" variant of str.format(), because in difference to Template it can call arbitrary code and allows easily to produce arbitrary large strings. Template is more appropriate

[issue39842] partial_format()

2020-03-04 Thread Eric V. Smith
Eric V. Smith added the comment: I suggest using the version I posted here and see if it meets your needs. It uses the str.format parser to break the string into pieces, so it should be accurate as far as that goes. -- ___ Python tracker

[issue39842] partial_format()

2020-03-04 Thread Marco Sulla
Marco Sulla added the comment: > Do you have some concrete use case for this? Yes, for EWA: https://marco-sulla.github.io/ewa/ Since it's a code generator, it uses templates a lot, and much times I feel the need for a partial substitution. In the end I solved with some ugly tricks. Furtherm

[issue39842] partial_format()

2020-03-04 Thread Eric V. Smith
Eric V. Smith added the comment: Do you have some concrete use case for this, or is this a speculative feature request? This will do what you want, although it uses some undocumented internals of the _string module. I've only tested it a little, and I've done especially little testing for t

[issue39842] partial_format()

2020-03-03 Thread Marco Sulla
New submission from Marco Sulla : In `string` module, there's a very little known class `Template`. It implements a very simple template, but it has an interesting method: `safe_substitute()`. `safe_substitute()` permits you to not fill the entire Template at one time. On the contrary, it sub