2008/5/13 Daniel Fetchinson <[EMAIL PROTECTED]>:
> And if this part of your code becomes the real performance bottleneck
> you might want to do the search/replace using the re module. Take a
> look at xml.etree.ElementTree in the stdlib for an example (if you
> have python > 2.4).
I do not think this will be the bottleneck. Displaying is offcourse
what is done most, but retreiving the values from the database is more
expensive as the replacements I think.
But it never hurts to think about performance I think. So I made it like:
#####
startSpaces = re.compile(' +')
def splitLines(thisText):
if thisText == None:
return None
thisText = xml.etree.ElementTree._encode_entity(thisText)
lines = thisText.split('\n')
for i in range(len(lines)):
match = startSpaces.match(lines[i])
if match:
lines[i] = ' ' * match.end() + lines[i][match.end():]
return '<br/>'.join(lines)
#####
With xml.etree.ElementTree._encode_entity the conversion is done more
efficiƫnt and at the same time there is more done.
I find the spaces at the start of a line significant. That is why I
added the for-loop. In this way the spaces at the start of a line are
replaced with and is the indent of a line saved.
--
Cecil Westerhof
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---