Python csv - data export and formatting color, text format, etc.

I am exporting data from python with the csv library, which works very well. After a web search, I cannot find any information on how to format the exported data using python.

For instance. I am exporting a csv string in python like this.

for hour_record in object_list:
            row = list()
            for field in fields:
                try:
                    row.append(getattr(hour_record, field))
                except:
                    pass
            writer.writerow(row)

Now I am wondering how I can pass some formatting information into a row.append call. For example, if I want to format the text in red and make sure that it is formed as a number, etc.

Does anyone know how this works?

+3
source share
2 answers

CSV . , , HTML-, . , .

+2

csv numpy.genfromtxt numpy.savetxt:

>>> data = numpy.genfromtxt('mydata.txt', dtype=None)
>>> <-> work with the data recarray object
>>> numpy.savetxt('results.txt', data)

help (numpy.savetxt), , "fmt", .

, HTML, , terminalcolor, STDOUT.

0

Source: https://habr.com/ru/post/1733507/


All Articles