-
-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tabulators break formatting #113
Comments
How are you actually using PrettyTable? Please provide some example Python code. |
startindex = page * num_elems
showarr = inputarr[startindex:startindex+num_elems]
headers = ["Index", "Date", "Type", "Command", "Internal Hash", "Project Commit Hash", "Diff from last commit", "Tag"]
table = PrettyTable()
table.field_names = headers
# this line is currently used to remove "\t" chars from problematic column, breaks without
table.add_rows(map(lambda x: (x[0], x[1], x[2], x[3], x[4], x[5], x[6].replace("\t", ""), x[7]), showarr))
table.align = "l"
print(table) |
Thanks, please could you create a "Minimal, Reproducible Example"? |
from prettytable import PrettyTable
data = [[ "first",
"second",
"""diff --git partdiff.c partdiff.c
index 05ced0c..804cd7d 100644
--- partdiff.c
+++ partdiff.c
@@ -377,6 +377,7 @@ main (int argc, char** argv)
\tstruct calculation_arguments arguments;
\tstruct calculation_results results;
+\tprintf("Some random text!");
\taskParams(&options, argc, argv);
\tinitVariables(&arguments, &results, &options);""",
"fourth"],
]
headers = ["col1", "col2", "col3", "col4"]
table = PrettyTable()
table.field_names = headers
table.add_rows(data)
print(table) produces
You could also try adding a |
Thanks for that! So it looks like this is the Python's For example: >>> print("a\tb")
a b
>>> print(" \tstruct calculation_arguments arguments;")
struct calculation_arguments arguments; If I preprocess the data and replace from prettytable import PrettyTable
data = [[ "first",
"second",
"""diff --git partdiff.c partdiff.c
index 05ced0c..804cd7d 100644
--- partdiff.c
+++ partdiff.c
@@ -377,6 +377,7 @@ main (int argc, char** argv)
\\tstruct calculation_arguments arguments;
\\tstruct calculation_results results;
+\\tprintf("Some random text!");
\\taskParams(&options, argc, argv);
\\tinitVariables(&arguments, &results, &options);""",
"fourth"],
]
headers = ["col1", "col2", "col3", "col4"]
table = PrettyTable()
table.field_names = headers
table.add_rows(data)
print(table) It prints nicely as:
But I guess it doesn't make much sense to show Another idea is to pre-process the from prettytable import PrettyTable
data = [[ "first",
"second",
"""diff --git partdiff.c partdiff.c
index 05ced0c..804cd7d 100644
--- partdiff.c
+++ partdiff.c
@@ -377,6 +377,7 @@ main (int argc, char** argv)
struct calculation_arguments arguments;
struct calculation_results results;
+ printf("Some random text!");
askParams(&options, argc, argv);
initVariables(&arguments, &results, &options);""",
"fourth"],
]
headers = ["col1", "col2", "col3", "col4"]
table = PrettyTable()
table.field_names = headers
table.add_rows(data)
print(table) Produces:
How does that sound? Can you preprocess I'm not sure if this should be handled by PrettyTable itself, whether it should make assumptions whether |
Printing |
I am trying to print a diff between different commits in Git. The string contains a tabulator character that seems to interfere with the centering.
Example string from diff:
Actually spelled out the "\t":
Printing with a PrettyTable breaks the layout. If you replace the "\t" with any character it works fine,
The text was updated successfully, but these errors were encountered: