diff options
| author | Kane Blueriver <kxxoling@gmail.com> | 2015-04-28 17:26:18 +0800 |
|---|---|---|
| committer | Kane Blueriver <kxxoling@gmail.com> | 2015-04-28 17:26:18 +0800 |
| commit | b91a7b75ea059a2c4f785d959e97f1a2b4e49377 (patch) | |
| tree | 84bc9934827a308612b006525629d60727d6c0ed | |
| parent | 8964329a88240c27c9fb4f242e9115d8abe1ebab (diff) | |
| download | python-prettytable-ptable-b91a7b75ea059a2c4f785d959e97f1a2b4e49377.tar.gz | |
Clean all the blank spaces at the end of a line
| -rw-r--r-- | prettytable.py | 42 | ||||
| -rw-r--r-- | prettytable_test.py | 12 |
2 files changed, 27 insertions, 27 deletions
diff --git a/prettytable.py b/prettytable.py index a619659..d80acce 100644 --- a/prettytable.py +++ b/prettytable.py @@ -50,7 +50,7 @@ if py3k: iterzip = zip uni_chr = chr from html.parser import HTMLParser -else: +else: itermap = itertools.imap iterzip = itertools.izip uni_chr = unichr @@ -80,7 +80,7 @@ def _get_size(text): height = len(lines) width = max([_str_block_width(line) for line in lines]) return (width, height) - + class PrettyTable(object): def __init__(self, field_names=None, **kwargs): @@ -147,7 +147,7 @@ class PrettyTable(object): self._start = kwargs["start"] or 0 self._end = kwargs["end"] or None self._fields = kwargs["fields"] or None - + if kwargs["header"] in (True, False): self._header = kwargs["header"] else: @@ -174,7 +174,7 @@ class PrettyTable(object): self.min_width = kwargs["min_width"] or {} self.int_format = kwargs["int_format"] or {} self.float_format = kwargs["float_format"] or {} - + self._min_table_width = kwargs["min_table_width"] or None self._max_table_width = kwargs["max_table_width"] or None self._padding_width = kwargs["padding_width"] or 1 @@ -184,7 +184,7 @@ class PrettyTable(object): self._vertical_char = kwargs["vertical_char"] or self._unicode("|") self._horizontal_char = kwargs["horizontal_char"] or self._unicode("-") self._junction_char = kwargs["junction_char"] or self._unicode("+") - + if kwargs["print_empty"] in (True, False): self._print_empty = kwargs["print_empty"] else: @@ -196,7 +196,7 @@ class PrettyTable(object): self._format = kwargs["format"] or False self._xhtml = kwargs["xhtml"] or False self._attributes = kwargs["attributes"] or {} - + def _unicode(self, value): if not isinstance(value, basestring): value = str(value) @@ -238,7 +238,7 @@ class PrettyTable(object): return 0 else: raise AttributeError(name) - + def __getitem__(self, index): new = PrettyTable() @@ -503,7 +503,7 @@ class PrettyTable(object): self._validate_option("max_width",val) for field in self._field_names: self._max_width[field] = val - + @property def min_width(self): """Controls minimum width of fields @@ -626,7 +626,7 @@ class PrettyTable(object): def sort_key(self, val): self._validate_option("sort_key", val) self._sort_key = val - + @property def header(self): """Controls printing of table header with field names @@ -1087,7 +1087,7 @@ class PrettyTable(object): Arguments: options - dictionary of option settings.""" - + if options["oldsortslice"]: rows = copy.deepcopy(self._rows[options["start"]:options["end"]]) else: @@ -1108,13 +1108,13 @@ class PrettyTable(object): rows = rows[options["start"]:options["end"]] return rows - + def _format_row(self, row, options): return [self._format_value(field, value) for (field, value) in zip(self._field_names, row)] def _format_rows(self, rows, options): return [self._format_row(row, options) for row in rows] - + ############################## # PLAIN TEXT STRING METHODS # ############################## @@ -1183,7 +1183,7 @@ class PrettyTable(object): # Add bottom of border if options["border"] and options["hrules"] == FRAME: lines.append(self._hrule) - + return self._unicode("\n").join(lines) def _stringify_hrule(self, options): @@ -1280,12 +1280,12 @@ class PrettyTable(object): return "".join(bits) def _stringify_row(self, row, options): - + for index, field, value, width, in zip(range(0,len(row)), self._field_names, row, self._widths): # Enforce max widths lines = value.split("\n") new_lines = [] - for line in lines: + for line in lines: if _str_block_width(line) > width: line = textwrap.fill(line, width) new_lines.append(line) @@ -1341,7 +1341,7 @@ class PrettyTable(object): if options["border"] and options["vrules"] == FRAME: bits[y].pop() bits[y].append(options["vertical_char"]) - + if options["border"] and options["hrules"]== ALL: bits[row_height-1].append("\n") bits[row_height-1].append(self._hrule) @@ -1361,7 +1361,7 @@ class PrettyTable(object): pages.append(self.get_string(**kwargs)) if kwargs["end"] == true_end: break - kwargs["start"] += page_length + kwargs["start"] += page_length return "\f".join(pages) ############################## @@ -1720,11 +1720,11 @@ def main(): x.add_row(["Melbourne", 1566, 3806092, 646.9]) x.add_row(["Perth", 5386, 1554769, 869.4]) print(x) - + print - + print("Generated using constructor arguments:") - + y = PrettyTable(["City name", "Area", "Population", "Annual Rainfall"], title = "Australian capital cities", sortby = "Population", @@ -1744,6 +1744,6 @@ def main(): y.add_row(["Melbourne", 1566, 3806092, 646.9]) y.add_row(["Perth", 5386, 1554769, 869.4]) print(y) - + if __name__ == "__main__": main() diff --git a/prettytable_test.py b/prettytable_test.py index ef33d3e..ce03780 100644 --- a/prettytable_test.py +++ b/prettytable_test.py @@ -364,9 +364,9 @@ class FloatFormatTests(unittest.TestCase): def setUp(self): self.x = PrettyTable(["Constant", "Value"]) - self.x.add_row(["Pi", pi]) - self.x.add_row(["e", e]) - self.x.add_row(["sqrt(2)", sqrt(2)]) + self.x.add_row(["Pi", pi]) + self.x.add_row(["e", e]) + self.x.add_row(["sqrt(2)", sqrt(2)]) def testNoDecimals(self): self.x.float_format = ".0f" @@ -378,9 +378,9 @@ class FloatFormatTests(unittest.TestCase): string = self.x.get_string() assert "3.14159" in string assert "3.141592" not in string - assert "2.71828" in string - assert "2.718281" not in string - assert "2.718282" not in string + assert "2.71828" in string + assert "2.718281" not in string + assert "2.718282" not in string assert "1.41421" in string assert "1.414213" not in string |
