[omaha] Omaha Digest, Vol 16, Issue 5

David Blaschke dwblas at gmail.com
Wed Jun 11 19:31:36 CEST 2008


Supposedly, the  fastest method is to use
a= "a"
b="b"
s = "%s %s" % (a, b,)
print s
s = "%s %s" % (s, b,)
print s
because it reverts to the underlying C code, but I don't use concatenation
much, so there isn't enough of a difference.

On 6/9/08, omaha-request at python.org <omaha-request at python.org> wrote:
>
> Send Omaha mailing list submissions to
>         omaha at python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>         http://mail.python.org/mailman/listinfo/omaha
> or, via email, send a message with subject or body 'help' to
>         omaha-request at python.org
>
> You can reach the person managing the list at
>         omaha-owner at python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Omaha digest..."
>
>
> Today's Topics:
>
>    1. String Concatenation (Matthew Nuzum)
>    2. Re: String Concatenation (Jeff Hinrichs - DM&T)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Sun, 8 Jun 2008 12:08:18 -0500
> From: "Matthew Nuzum" <newz at bearfruit.org>
> Subject: [omaha] String Concatenation
> To: "Omaha Python Users Group" <omaha at python.org>
> Message-ID:
>         <f3c0b4080806081008v12e96dedlf5d756a514ba7e43 at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-2
>
> On 6/7/08, Matt Harriger <mharriger at gmail.com> wrote:
> >  On Sat, Jun 7, 2008 at 4:12 PM, freeav8r <freeav8r at yahoo.com> wrote:
> >  > When you type in a form on a web page, any non ascii characters get
> >  > converted to their &#; equivalent.  As an example,, the capital D with
> a
> >  > horizontal line gets converted to &#272.
> >  >
> >  > Is there a python module out there that will do this for unicode
> characters
> >  > with no ascii equivalent?
> >
> > ord(uchar) (where uchar is a unicode string of length 1) will return the
> >  unicode codepoint for the given char, so ord(?) returns 272. "&#" +
> >  str(ord(uchar)) would give you the full HTML entity representation for
> that
> >  character.
>
> One of my first real python programs was incredibly slow because I
> used a lot of string concatenation. (Since strings are immutable in
> python changing them is slow)
>
> Now, whenever possible, I use the equiv of:
>   d = ["hello", "world"]
>   s = ' '.join(d)
>
> Is doing what Matt H suggested above (i.e. s = a + b + c) the slow
> kind of concatenation or is this fast since it's not actually
> modifying a string (i.e. s += b)?
>
> --
> Matthew Nuzum
> newz2000 on freenode
>
> ------------------------------
>
> Message: 2
> Date: Sun, 8 Jun 2008 23:10:31 -0500
> From: "Jeff Hinrichs - DM&T" <jeffh at dundeemt.com>
> Subject: Re: [omaha] String Concatenation
> To: "Omaha Python Users Group" <omaha at python.org>
> Message-ID:
>         <5aaed53f0806082110m2270044ek5a24609724dce184 at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-2
>
> 2008/6/8 Matthew Nuzum <newz at bearfruit.org>:
> > On 6/7/08, Matt Harriger <mharriger at gmail.com> wrote:
> >>  On Sat, Jun 7, 2008 at 4:12 PM, freeav8r <freeav8r at yahoo.com> wrote:
> >>  > When you type in a form on a web page, any non ascii characters get
> >>  > converted to their &#; equivalent.  As an example,, the capital D
> with a
> >>  > horizontal line gets converted to &#272.
> >>  >
> >>  > Is there a python module out there that will do this for unicode
> characters
> >>  > with no ascii equivalent?
> >>
> >> ord(uchar) (where uchar is a unicode string of length 1) will return the
> >>  unicode codepoint for the given char, so ord(?) returns 272. "&#" +
> >>  str(ord(uchar)) would give you the full HTML entity representation for
> that
> >>  character.
> >
> > One of my first real python programs was incredibly slow because I
> > used a lot of string concatenation. (Since strings are immutable in
> > python changing them is slow)
> >
> > Now, whenever possible, I use the equiv of:
> >  d = ["hello", "world"]
> >  s = ' '.join(d)
> >
> > Is doing what Matt H suggested above (i.e. s = a + b + c) the slow
> > kind of concatenation or is this fast since it's not actually
> > modifying a string (i.e. s += b)?
> Actually, recent version of Python(2.5.x) have been optimized, so that
> the use of 'foo' + 'bar' is on par with ''.join('foo','bar')
>
> see
> http://wiki.python.org/moin/PythonSpeed/PerformanceTips#head-bcf69f4e2cacc9683c2f9a1f401e891cac50506f
>
> -Jeff
>
> ------------------------------
>
> _______________________________________________
> Omaha mailing list
> Omaha at python.org
> http://mail.python.org/mailman/listinfo/omaha
>
>
> End of Omaha Digest, Vol 16, Issue 5
> ************************************
>


More information about the Omaha mailing list