Redefining "\n"
Robert Amesz
sheershion at mailexpire.com
Sun Feb 17 15:47:47 EST 2002
Dale Strickland-Clark wrote:
> When preparing strings for the Windows clipboard, I need \x0d\x0a for
> a newline which is a bit cumbersome to insert all over the place.
>
> It would be neat if I could make "\n" insert some other sequence.
Uh, how about
data = data.replace("\n", "\r\n")
before sending it to the clipboard?
Probably the best thing is to put everything in a function (caution -
untested code):
def SetClipboardText(data):
data = str(data) # A precaution
if wxPlatform == '__WXMSW__':
data = data.replace("\n", "\r\n")
dataobject = wxTextDataObject()
dataobject.SetText(data)
wxTheClipboard.Open()
wxTheClipboard.SetData(dataobject)
wxTheClipboard.Close()
That would neatly encapsulate it, and it's more portable that way, too.
Robert Amesz
More information about the Python-list
mailing list