Re: '"%s/" % var' preferred to 'var + "/"'?

2008-08-24 Thread Fredrik Lundh
Joost Cassee wrote: > Thanks for all the great info. Usually articles refer ''.join(...) as > the fastest concat operation, but it won't do type coersion of course. > I was interested whether there was a Django standard for this sort of > thing. In any case the '+' operator is discouraged by all.

Re: '"%s/" % var' preferred to 'var + "/"'?

2008-08-23 Thread phillc
a python string is immutable using the + operation on it causes strings to be copied into memory and made into another immutable string... which doesn;t save much... but the next uses of + requires another copy, and the next so on... where as using % does copy once On Aug 22, 4:49 am, Joost Casse

Re: '"%s/" % var' preferred to 'var + "/"'?

2008-08-22 Thread Joost Cassee
Thanks for all the great info. Usually articles refer ''.join(...) as the fastest concat operation, but it won't do type coersion of course. I was interested whether there was a Django standard for this sort of thing. In any case the '+' operator is discouraged by all. Regards, Joost --~--~-

Re: '"%s/" % var' preferred to 'var + "/"'?

2008-08-21 Thread lingrlongr
You can also map a dictionary of values to the format string: >>> num = 99 >>> obj = 'red balloons' >>> print '%(a)d %(b)s' % {'a': num, 'b': obj} 99 red baloons Keith On Aug 22, 12:28 am, "Ronny Haryanto" <[EMAIL PROTECTED]> wrote: > On Thu, Aug 21, 2008 at 10:41 PM, Joost Cassee <[EMAIL PROTE

Re: '"%s/" % var' preferred to 'var + "/"'?

2008-08-21 Thread Ronny Haryanto
On Thu, Aug 21, 2008 at 10:41 PM, Joost Cassee <[EMAIL PROTECTED]> wrote: > Just a quick question to set my head right for future Django > contributions. Why is "%s/" % var better than var + '/'? I can think > of some reasons: 1) consistency with other code, 2) certainty of > string concatenation.

Re: '"%s/" % var' preferred to 'var + "/"'?

2008-08-21 Thread Waylan Limberg
On Thu, Aug 21, 2008 at 12:22 PM, Ian Kelly <[EMAIL PROTECTED]> wrote: > > On Thu, Aug 21, 2008 at 10:00 AM, Waylan Limberg <[EMAIL PROTECTED]> wrote: >> I had thought that I read from that same source that formatting is >> faster than concatenation (and that's why I checked there before >> respon

Re: [OT] '"%s/" % var' preferred to 'var + "/"'?

2008-08-21 Thread Yuri Baburov
Also you are able to use %s for numbers and any custom types: "str%s" % 12 but not "str" + 12. Less errors -- more fun. On Thu, Aug 21, 2008 at 11:00 PM, Jeff Anderson <[EMAIL PROTECTED]> wrote: > Joost Cassee wrote: >> >> Hi all, >> >> Just a quick question to set my head right for future Django

Re: '"%s/" % var' preferred to 'var + "/"'?

2008-08-21 Thread Ian Kelly
On Thu, Aug 21, 2008 at 10:00 AM, Waylan Limberg <[EMAIL PROTECTED]> wrote: > I had thought that I read from that same source that formatting is > faster than concatenation (and that's why I checked there before > responding), but I don't see that mentioned. Not sure where I got that > idea or if

Re: '"%s/" % var' preferred to 'var + "/"'?

2008-08-21 Thread Vik Reykja
On Thu, Aug 21, 2008 at 18:00, Waylan Limberg <[EMAIL PROTECTED]> wrote: > I had thought that I read from that same source that formatting is > faster than concatenation (and that's why I checked there before > responding), but I don't see that mentioned. Not sure where I got that > idea or if its

Re: '"%s/" % var' preferred to 'var + "/"'?

2008-08-21 Thread Waylan Limberg
Well, according to the python beginners book; "Dive Into Python" [1], string formatting is less error prone as it also does type coercion whereas string concatenation only works when all objects are already strings. When it's possible that a user will be passing in parts of the concatenation, I'd

Re: [OT] '"%s/" % var' preferred to 'var + "/"'?

2008-08-21 Thread Jeff Anderson
Joost Cassee wrote: Hi all, Just a quick question to set my head right for future Django contributions. Why is "%s/" % var better than var + '/'? I can think of some reasons: 1) consistency with other code, 2) certainty of string concatenation. But is the second expression not much faster? (This

'"%s/" % var' preferred to 'var + "/"'?

2008-08-21 Thread Joost Cassee
Hi all, Just a quick question to set my head right for future Django contributions. Why is "%s/" % var better than var + '/'? I can think of some reasons: 1) consistency with other code, 2) certainty of string concatenation. But is the second expression not much faster? (This is an honest questio