How to modify lines in Python stream

Viewed 66

I am using psycopg2 to export a PostgreSQL table.

file = sys.stdout # writable file
cur.copy_to(file, "example_table")

I have a transformation that I would like to apply to each line of the file as it is exported.

def transform(line):
  # ...
  return line

How should I do this?

I could implement my own TextIO class from scratch, but it seems like there ought to be a simple, less error-prone way to modify this output line by line.

0 Answers
Related