3 ms·
I hope this gets implemented. A year ago or so we had several customers wanting to custom format output filenames and directories in a desktop application and w
by stinos 11y ago
I hope this gets implemented. A year ago or so we had several customers wanting to custom format output filenames and directories in a desktop application and we settled for something which is almost exactly this, so the {identifier:format spec} idea, and ever since implementing it I wish any language had it as we found it really convenient and having no apparant disadvantages in comparision with printf-%-style in C or Python/streams in C++/{}-style in C#/Python
- chrismorgan 11y agoI don’t understand what you’re seeking. This is purely for string literals. If you’re taking a user input string like `"foo-{date}.{extension}"`, you could use `string.format(date=…, extension=…)`
- stinos 11y agoYes it's for literals only, just saying I like the inline style and readability and succinctness of it and wouldn't mind it being implemented in Python and other languages.
- dalke 11y agoBut this wouldn't solve your case because it could only be applied to strings that are in the source code. Your users don't have the ability to change those string. Instead, they want to provide a format string, which you fill in. That is already available, eg, via str.format(kwargs), where you control the kwargs and the user controls the str.
- stinos 11y agoYes, I know that as well. But this wasn't a Python application :] Maybe should have mentioned that earlier..
- CmonDev 11y agoC# has it.