Why do this?

Matthew Warren Matthew.Warren at digica.com
Thu Oct 5 07:19:58 EDT 2006


 > Also, having a variable of type str called 'number' seems 
> perverse (and 
> probably error prone), so I suspect I might need something like:
>

And not something I would normally do, but for hastily written contrived
examples I might :)

 
>    print "There are "+str(number)+" ways to skin a "+furryanimal
> 
> but the format string does the conversion for free.
> 
> The other main reason for preferring format strings is that 
> they make it 
> easier to refactor the code. If you ever want to move the 
> message away from 
> where the formatting is done then it's a lot easier to 
> extract a single 
> string than it is to clean up the concatenation.
> -- 


This is a benefit of pythons implementation of format strings I hadn't
considered, that __str__() is called to get the representation. And
something I like about python, althgouh at the moment the __xxx__
methods available and their use is something I'm just getting into


This email is confidential and may be privileged. If you are not the intended recipient please notify the sender immediately and delete the email from your computer. 

You should not copy the email, use it for any purpose or disclose its contents to any other person.
Please note that any views or opinions presented in this email may be personal to the author and do not necessarily represent the views or opinions of Digica.
It is the responsibility of the recipient to check this email for the presence of viruses. Digica accepts no liability for any damage caused by any virus transmitted by this email.

UK: Phoenix House, Colliers Way, Nottingham, NG8 6AT UK
Reception Tel: + 44 (0) 115 977 1177
Support Centre: 0845 607 7070
Fax: + 44 (0) 115 977 7000
http://www.digica.com

SOUTH AFRICA: Building 3, Parc du Cap, Mispel Road, Bellville, 7535, South Africa
Tel: + 27 (0) 21 957 4900
Fax: + 27 (0) 21 948 3135
http://www.digica.com



More information about the Python-list mailing list