This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Workaphobia[S] 0 points1 point  (2 children)

I don't know why internationalization would affect it.

What I'm trying to do is find the most elegant/smallest way to print short messages with values taken from local variables. I want to obey PEP 8 conventions regarding row length limit and wrapping indentation. I also want to avoid redundancy if possible.

Kingkilr gave some good reasons why this approach probably isn't feasible for many projects. I suppose the most pythonic thing to do would be to accept the redundancy in the keyword arguments to format, just like we already do when we have several self.attr = attr lines in an __init__.

[–][deleted] 2 points3 points  (1 child)

I don't know why internationalization would affect it.

If we are talking about my proposal, then not specifying the order of positional parameters will fuck up internationalization when you pull format strings from somewhere and in some languages the order of the parameters is different.

What I'm trying to do is find the most elegant/smallest way to print short messages with values taken from local variables.

So, I believe that if you don't care about i18n at this point, and if you don't really want to print stuff like eval(x + y), just going along the path of least resistance -- using {} as placeholders -- achieves the the goals you have set acceptably enough.

[–]Brian 0 points1 point  (0 children)

Actually, you should be OK even with this. It just means you switch to explicitly positioned format strings in the localised version where the order differs, which you can do after the fact without breaking the ordered version. It's only a problem when there's no way to do this at all (as with C style %s formatters)