Thread: escaping data for copy_from()

escaping data for copy_from()

From
Josh Kupershmidt
Date:
Hi all,

I haven't seen a built-in way to escape data meant for copy_from().
The example code in examples/copy_from.py uses only pre-escaped data
e.g:

  data.write('\n'.join(['Tom\tJenkins\t37',
                        'Madonna\t\N\t45',
                        'Federico\tDi Gregorio\t\N']))

which works OK for such pre-escaped data, but what I really want is a
way to escape arbitrary text blobs for use with copy_from() -- for
instance, text containing newlines, tabs, backslash characters, and
other sequences which need escaping.

Is there some easy way to handle this problem I'm missing, or do I
need to just write my own escaping code?

Josh