diff --git a/gramps/cli/argparser.py b/gramps/cli/argparser.py index 8fdb70546..a2f934d64 100644 --- a/gramps/cli/argparser.py +++ b/gramps/cli/argparser.py @@ -255,8 +255,7 @@ class ArgParser: # Some args can work on a list of databases: if leftargs: - for opt_ix in range(len(options)): - option, value = options[opt_ix] + for option, value in options: if option in ['-L', '-l', '-t']: self.database_names = leftargs leftargs = [] @@ -269,8 +268,7 @@ class ArgParser: ) % leftargs[0], file=sys.stderr) #see if force open is on - for opt_ix in range(len(options)): - option, value = options[opt_ix] + for option, value in options: if option in ('-u', '--force-unlock'): self.force_unlock = True break @@ -279,8 +277,7 @@ class ArgParser: # Go over all given option and place them into appropriate lists cleandbg = [] need_to_quit = False - for opt_ix in range(len(options)): - option, value = options[opt_ix] + for opt_ix, (option, value) in enumerate(options): if option in ['-O', '--open']: self.open = value elif option in ['-C', '--create']: @@ -345,10 +342,9 @@ class ArgParser: from gramps.gen.config import config print(_("Gramps config settings from %s:" ) % config.filename) - for sect in config.data: - for setting in config.data[sect]: - print("%s.%s=%s" % (sect, setting, - repr(config.data[sect][setting]))) + for sect, settings in config.data.items(): + for settings_index, setting in settings.items(): + print("%s.%s=%s" % (sect, settings_index, repr(value))) print() sys.exit(0) elif option in ['-c', '--config']: diff --git a/gramps/cli/test/argparser_test.py b/gramps/cli/test/argparser_test.py index fccb82619..f3162dd08 100644 --- a/gramps/cli/test/argparser_test.py +++ b/gramps/cli/test/argparser_test.py @@ -94,6 +94,9 @@ class TestArgParser(unittest.TestCase): argument_parser.errors ) + def test_option_with_multiple_arguments(self): + argument_parser = self.create_parser('-l', 'family_tree_name') + self.assertEqual(argument_parser.database_names, ['family_tree_name']) if __name__ == "__main__": unittest.main() diff --git a/gramps/gen/db/base.py b/gramps/gen/db/base.py index 8020e42ae..66f586653 100644 --- a/gramps/gen/db/base.py +++ b/gramps/gen/db/base.py @@ -2008,8 +2008,7 @@ class DbWriteBase(DbReadBase): birth_ref_index = -1 death_ref_index = -1 event_ref_list = person.get_event_ref_list() - for index in range(len(event_ref_list)): - ref = event_ref_list[index] + for index, ref in enumerate(event_ref_list): event = self.get_event_from_handle(ref.ref) if (event.type.is_birth() and ref.role.is_primary() diff --git a/gramps/gen/filters/_paramfilter.py b/gramps/gen/filters/_paramfilter.py index 67de2c069..4f1605217 100644 --- a/gramps/gen/filters/_paramfilter.py +++ b/gramps/gen/filters/_paramfilter.py @@ -53,8 +53,8 @@ class ParamFilter(GenericFilter): # Need to change existing params one by one to keep # the correct number of arguments new_list = rule.list[:] - for ix in range(len(self.param_list)): - new_list[ix] = self.param_list[ix] + for index, param in enumerate(self.param_list): + new_list[index] = param rule.set_list(new_list) for rule in self.flist: if rule.nrprepare > 0: diff --git a/gramps/gen/filters/rules/_rule.py b/gramps/gen/filters/rules/_rule.py index 63c9f3872..59f71011d 100644 --- a/gramps/gen/filters/rules/_rule.py +++ b/gramps/gen/filters/rules/_rule.py @@ -81,12 +81,12 @@ class Rule: if self.nrprepare == 0: if self.use_regex: self.regex = [None]*len(self.labels) - for i in range(len(self.labels)): - if self.list[i]: + for index, label in enumerate(self.labels): + if self.list[index]: try: - self.regex[i] = re.compile(self.list[i], re.I) + self.regex[index] = re.compile(self.list[index], re.I) except re.error: - self.regex[i] = re.compile('') + self.regex[index] = re.compile('') self.match_substring = self.match_regex self.prepare(db, user) self.nrprepare += 1 @@ -141,10 +141,10 @@ class Rule: def display_values(self): """Return the labels and values of this rule.""" - l_v = ('%s="%s"' % (_(self.labels[ix][0] if - isinstance(self.labels[ix], tuple) else - self.labels[ix]), self.list[ix]) - for ix in range(len(self.list)) if self.list[ix]) + l_v = ('%s="%s"' % (_(self.labels[index][0] if + isinstance(self.labels[index], tuple) else + self.labels[index]), item) + for index, item in enumerate(self.list) if item) return ';'.join(l_v) diff --git a/gramps/gen/lib/test/date_test.py b/gramps/gen/lib/test/date_test.py index 13517224a..8b21454db 100644 --- a/gramps/gen/lib/test/date_test.py +++ b/gramps/gen/lib/test/date_test.py @@ -235,8 +235,8 @@ class ParserDateTest(BaseDateTest): Date displayer and parser tests. """ def do_case(self, testset): - for date_format in range(len(get_date_formats())): - set_format(date_format) + for index, date_format in enumerate(get_date_formats()): + set_format(index) for dateval in date_tests[testset]: datestr = _dd.display(dateval) @@ -245,7 +245,7 @@ class ParserDateTest(BaseDateTest): "dateval fails is_equal in format %d:\n" " '%s' != '%s'\n" " '%s' != '%s'\n" % - (date_format, dateval, ndate, + (index, dateval, ndate, dateval.__dict__, ndate.__dict__)) def test_basic(self): diff --git a/gramps/gen/plug/docgen/fontscale.py b/gramps/gen/plug/docgen/fontscale.py index ffe9ae25b..93b57b3fe 100644 --- a/gramps/gen/plug/docgen/fontscale.py +++ b/gramps/gen/plug/docgen/fontscale.py @@ -300,9 +300,7 @@ def string_trim(font, text, width, ellipses = "..."): # find the part that is < width retval = "" sumlen = 0 - length = 0 - for i in range(len(text)): - c = text[i] + for c in text: try: length = l[ord(c)] except: @@ -325,9 +323,7 @@ def string_trim(font, text, width, ellipses = "..."): # too long; try again with ellipses retval = "" sumlen = 0 - length = 0 - for i in range(len(text)): - c = text[i] + for c in text: try: length = l[ord(c)] except: diff --git a/gramps/gen/plug/report/_book.py b/gramps/gen/plug/report/_book.py index 61fc6c5db..24d560e62 100644 --- a/gramps/gen/plug/report/_book.py +++ b/gramps/gen/plug/report/_book.py @@ -516,10 +516,9 @@ class BookList: 'length="%d">\n' % ( escape(option_name), len(options[option_name]))) - for list_index in range(len(option_value)): - option_type = type_name( - option_value[list_index]) - value = escape(str(option_value[list_index])) + for list_index, v in enumerate(option_value): + option_type = type_name(v) + value = escape(str(v)) value = value.replace('"', '"') b_f.write(' \n' % ( @@ -557,7 +556,7 @@ class BookList: b_f.write(' ' '\n' % (size[0], size[1])) if book.get_margins(): - for pos in range(len(book.get_margins())): + for pos, margin in enumerate(book.get_margins()): b_f.write(' \n' % ( pos, book.get_margin(pos))) diff --git a/gramps/gen/plug/report/_options.py b/gramps/gen/plug/report/_options.py index 277473808..d29ccb4c9 100644 --- a/gramps/gen/plug/report/_options.py +++ b/gramps/gen/plug/report/_options.py @@ -497,9 +497,9 @@ class OptionListCollection(_options.OptionListCollection): % (size[0], size[1])) if option_list.get_margins(): margins = option_list.get_margins() - for pos in range(len(margins)): + for pos, margin in enumerate(margins): file.write(' \n' - % (pos, margins[pos])) + % (pos, margin)) if option_list.get_style_name(): file.write('