Python how to export a print view to txt

Viewed 20

I have a print that works perfectly to me since I use tabulate:

print(tabulate(query, headers= 'keys', tablefmt = 'psql'))

And I would like to export this print to a txt file just the way it looks in terminal.

Thanks for your support!

1 Answers

Try in this way

print(tabulate(query, headers= 'keys', tablefmt = 'psql'), file=open("output.txt", "a"))
Related