From 739810d98ddc92f54cc2ee93846c3b09346198be Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Thu, 14 Nov 2019 10:28:54 -0800 Subject: [PATCH] Make some minor tweaks to `mysqldump_to_csv.py` * Use `.startswith(..)` in place of the unrolled versions of the equivalent functionality. * Use `if foo:` and `if not foo:` instead of `if len(foo) != 0:` and `if len(foo) == 0:`. The former set of patterns is more performant and it protects against `foo` potentially not being an iterable object, or an object that doesn't implement `.__len__(..)`. * Change the mode of the script to 0755 so it's executable out of the box. Signed-of-by: Enji Cooper --- mysqldump_to_csv.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) mode change 100644 => 100755 mysqldump_to_csv.py diff --git a/mysqldump_to_csv.py b/mysqldump_to_csv.py old mode 100644 new mode 100755 index b49cfe7..69e3285 --- a/mysqldump_to_csv.py +++ b/mysqldump_to_csv.py @@ -57,12 +57,12 @@ def parse_values(values, outfile): latest_row.append(chr(0)) continue # If our string starts with an open paren - if column[0] == "(": + if column.startswith("("): # Assume that this column does not begin # a new row. new_row = False # If we've been filling out a row - if len(latest_row) > 0: + if latest_row: # Check if the previous entry ended in # a close paren. If so, the row we've # been filling out has been COMPLETED @@ -80,7 +80,7 @@ def parse_values(values, outfile): latest_row = [] # If we're beginning a new row, eliminate the # opening parentheses. - if len(latest_row) == 0: + if not latest_row: column = column[1:] # Add our column to the row we're working on. latest_row.append(column) @@ -88,7 +88,7 @@ def parse_values(values, outfile): # have the semicolon. # Make sure to remove the semicolon and # the close paren. - if latest_row[-1][-2:] == ");": + if latest_row[-1].endswith(");"): latest_row[-1] = latest_row[-1][:-2] writer.writerow(latest_row)