Closed jo-koe closed 9 months ago
Here's some simple code to reproduce the issue:
from pytablewriter import MarkdownTableWriter
def main():
writer = MarkdownTableWriter(
table_name="Simple Table",
headers=[
"String",
],
value_matrix=[["0123456"]],
)
writer.write_table()
if __name__ == "__main__":
main()
Output:
# Simple Table
|String|
|-----:|
|123456|
and if I change it to:
[...]
value_matrix=[["0123456" + "a"]],
[...]
the Output includes the missing "0":
# Simple Table
| String |
|--------|
|0123456a|
@jo-koe
The leading zeros will be printed as it is when you explicitly specify the type hint as str
as follows:
def main():
writer = MarkdownTableWriter(
table_name="Simple Table",
headers=[
"String",
],
type_hints=["str"],
value_matrix=[["0123456"]],
)
writer.write_table()
if __name__ == "__main__":
main()
|String |
|-------|
|0123456|
If you do not specify type_hints
, the type of a column is automatically inferred from the values in the column.
0123456
is inferred as int
, and the values will be converted to int
and rendered as 123456
.
On the other hand, 0123456a
is inferred as str
, and the values will be rendered as 0123456a
.
Hi, first of all thanks a lot for creating this library!
I've just experienced that leading zeros of strings passed as part of the
value_matrix
are not printed when creating a Markdown table. Is this intended behaviour or do I miss something here?Thanks a lot in advance, Jonas