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.
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
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
--~--~-
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
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.
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
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
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
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
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
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
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
12 matches
Mail list logo