Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I suppose you mean to take the variable names of the arguments without using keyword arguments? That's not possible because .format() is just a simple method call on str/unicode objects.


>That's not possible

That statement is against my religious beliefs. Apparently we can stick an f in front of the string, but we can't have default values that work with locals()?


That would mean the formattee would have to dig thru its surrounding namespace. This solution is more elegant, the string is transformed into the equivalent format call at compile time, making the implementation tiny.


Python provides many ways to 'dig thru' the surrounding namespace. I find it ironic that do so is effortless in the language while at the same time is considered unpythonic. Which is it? Is the language itself unpythonic?


Stack frame digging is discouraged yes, I'm ok with that.

Also, this alternative solution would not allow arbitrary expressions, which was a design goal.


Elegant for who?

Adding a new syntax that doesn't exist in any language.

vs.

Using sensible default parameters.

-----------------

An argument for why my suggestion would be bad: https://www.python.org/dev/peps/pep-0498/#no-use-of-globals-...


> Adding a new syntax that doesn't exist in any language.

Not true, look into the new interpolation features in C#, Scala, JS, Swift, nim, etc.


> Adding a new syntax that doesn't exist in any language.

Please, even JavaScript (ES6) got itself something similar; implicit string interpolation is not that rare.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: