[omaha] String Concatenation

Jeff Hinrichs - DM&T jeffh at dundeemt.com
Mon Jun 9 06:10:31 CEST 2008


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


More information about the Omaha mailing list