<html>
<head>
<style>
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
</style>
</head>
<body class='hmmessage'>
Hi list,<br><br>I'm sorry if this has been discussed before, but I did not find any references. I've been playing abit with the new str.format function. I really like the syntax and simplicity.<br><br>However, when simply printing named variables in locals() or a class, I quite common use-case, I find it a bit too complicated with the **:<br><br>"Local variable var1 is %(var1)s" % locals() <br><br>vs<br><br>"Local variable var1 is {var1}".format(**locals())<br><br>and<br><br>"Instance variable var2 is %(var2)s" % self.__dict__<br><br>vs<br><br>"Instance variable var2 is {var2}" % **self.__dict__<br><br>Therefore I have made myself a utility funcion:<br><br>def easyformat(s, data):<br>    try:<br>        return s.format(**data)<br>    except TypeError:<br>        return s.format(**data.__dict__)<br><br>so that I can do the following:<br><br>"Local variable var1 is {var1}".format(**locals())<br><br>and<br><br>"Instance variable var2 is %(var2)s" % self<br><br>Should a function similar to this (maybe with a better name) be included included in some standard library?<br><br>-Dag<br><br /><hr />En om gangen eller alle på én gang? <a href='http://www.microsoft.com/norge/windows/windowslive/products/social-network-connector.aspx' target='_new'>Få oppdateringer fra vennene dine på ett sted.</a></body>
</html>