Package: planetext-table
planetext-tableOverviewplanetext table gengerator.Exampleimportdatetimeasdtimportplanetext_tableasptdata=[['file name','update date','size'],['foo.txt',dt.date(2022,1,1),12000],['bar.txt',dt.date(2022,2,3),500],['ＡＢＣ.txt',dt.date(2022,11,12),2554500],]print(pt.to_ascii(data))# +------------+-------------+---------+# | file name  | update date | size    |# +------------+-------------+---------+# | foo.txt    | 2022-01-01  | 12000   |# | bar.txt    | 2022-02-03  | 500     |# | ＡＢＣ.txt | 2022-11-12  | 2554500 |# +------------+-------------+---------+Referenceto_asciiGenerate ascii table.+------------+-------------+---------+
| file name  | update date | size    |
+------------+-------------+---------+
| foo.txt    | 2022-01-01  | 12000   |
| bar.txt    | 2022-02-03  | 500     |
| ＡＢＣ.txt | 2022-11-12  | 2554500 |
+------------+-------------+---------+argumentsdata (list[list[Any]])input list datanewline (str)newline character at end of lineDefault:'\n'internal_newline (str)newline character at inside elementDefault:'\n'aligns (list[Align])text alignment of each column (see below for details)Default:Noneconverterslist of type and converter pairs (see below for details)Default:Noneto_csvGenerate CSV table."file name","update date","size"
"foo.txt","2022-01-01","12000"
"bar.txt","2022-02-03","500"
"ＡＢＣ.txt","2022-11-12","2554500"argumentsdata (list[list[Any]])input list datadelimiter (str):delimiter between elementsDefault:','quotechar (str):quote character at both ends of elementDefault:'"'newline (str)newline character at end of lineDefault:'\n'internal_newline (str)newline character at inside elementDefault:'\n'converterslist of type and converter pairs (see below for details)Default:Noneto_markdownGenerate markdown table.| file name  | update date | size    |
|------------|-------------|---------|
| foo.txt    | 2022-01-01  | 12000   |
| bar.txt    | 2022-02-03  | 500     |
| ＡＢＣ.txt | 2022-11-12  | 2554500 |argumentsdata (list[list[Any]])input list datanewline (str)newline character at end of lineDefault:'\n'internal_newline (str)newline character at inside elementDefault:'\n'aligns (list[Align])text alignment of each column (see below for details)Default:Noneconverterslist of type and converter pairs (see below for details)Default:NoneNoteAboutalignsargumentLiner list for specifying the alignment of each column. Inside values should be theplanetext_table.Alignenumeration.Ifto_ascii, it affects alignment with space padding.
Ifto_markdown, the alignment is specified according to the markdown notation.The value of theplanetext_table.Alignis as follows:Align.NONEAlign.LEFTAlign.CENTERAlign.RIGHTNONEwill meanLEFT, but the markdown will no longer use:on the second line.AboutconverterargumentBy default, built-in functionstris used to convert the value of each element to a string, but this argument allows any conversion function to be used.To pass liner list of pairs (tuples) of target element types and conversion functions.
It is possible to specify multiple types by making a tuple of element types. (As used in built-in functionisinstance)Example:importdatetimeasdtdefint2str(x):returnf'{x:,}'defdate2str(x):returndt.datetime.strftime(x,r'%Y/%m/%d%H:%M:%S.%f')converter=[(int,int2str),((dt.date,dt.datetime),date2str),]data=[[10,dt.date(2022,1,2)]]to_ascii(data,converter=converter)full-width character handlingThe character width of full-width characters is determined according to the character type classified byEast Asian Widthas follows:character typewidthFullwidth (F)2Halfwidth (H)1Wide (W)2Narrow (Na)1Ambiguous (A)2Neutral (N)2The functionunicodedata.east_asian_widthfrom the standard library is used.
Some combinations of characters and fonts, such as some symbols and emojis, may not appear to be aligned nicely.