jazzband / prettytable

Display tabular data in a visually appealing ASCII table format
https://pypi.org/project/PrettyTable/
Other
1.35k stars 154 forks source link

How to save prettytable as csv or json file? #224

Closed zxczrx123 closed 1 year ago

zxczrx123 commented 1 year ago

Hi, thanks for your great work!

I want to know how to save prettytable as csv or json file elegantly?

zxczrx123 commented 1 year ago
import io
import csv
reader = csv.reader(io.StringIO(x.get_csv_string())) 
with open('string2csv.csv', 'w') as out_file:
    writer = csv.writer(out_file)
    writer.writerows(reader)

I have found a way. Is there a more concise io interface?

hugovk commented 1 year ago

That looks pretty good to me.

No, PrettyTable only does string output via the get*_string methods.

ewyluda commented 1 year ago

x.get_csv_string() no longer works... I've been using this method for 6 months or so without any issue, went to rerun my code today and i keep getting an attribute error... any suggestions? image

hugovk commented 1 year ago

@ewyluda Please open a new, detailed issue: https://github.com/jazzband/prettytable/issues/new/choose