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

> things that did change didn't actually make a clear difference in [...] the clarity of your code

print "%s remember to %s in %s if %s but never %s" % (some_random_tuple)

vs

print("{when} remember {what} in {room} if {condition} but never {dont}".format(* * dict_with_explicit_keys))

A bit verbose but much clearer and future-proof.



Python 2.7 supports string.format and Python 3 supports % formatting.

The only actual difference in that example is that print became a function in Python 3, requiring some additional parentheses. (Something that can be mechanically translated without much hassle.)


Wasn't the % formatting missing from early versions of python3?


That's an unfair comparison, however,

    print "%(when)s remember to %(what)s in %(room)s but never %(dont)s" % dict_with_explicit_keys
was supported back in at least 2.4.


But you can already do that in Python 2.7.




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

Search: