From 78b387cc311a47d5e622ea9ab9ce83c57b6a0d86 Mon Sep 17 00:00:00 2001 From: David Hoese Date: Thu, 27 Sep 2018 11:42:24 -0500 Subject: [PATCH] Remove extra prints and add documentation for regex formatter --- trollsift/parser.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/trollsift/parser.py b/trollsift/parser.py index 3939abe..4852dcb 100644 --- a/trollsift/parser.py +++ b/trollsift/parser.py @@ -161,6 +161,18 @@ def convert_field(self, value, conversion): class RegexFormatter(string.Formatter): + """String formatter that converts a format string to a regular expression. + + >>> regex_formatter = RegexFormatter() + >>> regex_str = regex_formatter.format('{field_one:5d}_{field_two}') + + Can also be used to extract values from a string given the format spec + for that string: + + >>> regex_formatter.extract_values('{field_one:5d}_{field_two}', '12345_sometext') + {'field_one': '12345', 'field_two': 'sometext'} + + """ # special string to mark a parameter not being specified UNPROVIDED_VALUE = '' @@ -510,9 +522,7 @@ def is_one2one(fmt): return False # run data forward once and back to data - print(fmt, data) stri = compose(fmt, data) - print(fmt, stri) data2 = parse(fmt, stri) # check if data2 equal to original data if len(data) != len(data2):