@@ -24,8 +24,7 @@ def finish(self):
2424 self ._data .sort ()
2525
2626 def __str__ (self ):
27- return '\n ' .join (['{0}: {1}' .format (self .name , x )
28- for x in self ._data ])
27+ return '\n ' .join ([f'{ self .name } : { value } ' for value in self ._data ])
2928
3029
3130class BlocksHandler (ContentHandler ):
@@ -54,10 +53,8 @@ def startDocument(self):
5453
5554 def startElement (self , name , attrs ):
5655 if name == 'block' :
57- logging .info ('start of {0}' .format (attrs .getValue ('name' )))
58- parent_name = ''
59- if self ._stack :
60- parent_name = self ._stack [- 1 ].name + '/'
56+ logging .info (f'start of { attrs .getValue ("name" )} ' )
57+ parent_name = f'{ self ._stack [- 1 ].name } /' if self ._stack else ''
6158 block = Block (parent_name + attrs .getValue ('name' ))
6259 self ._stack .append (block )
6360 elif name == 'item' :
@@ -68,15 +65,15 @@ def characters(self, contents):
6865 contents = contents .strip ()
6966 if contents :
7067 data = float (contents .strip ())
71- logging .info ("found '{0 }'" . format ( data ) )
68+ logging .info (f "found '{ data } '" )
7269 self ._stack [- 1 ].add_data (data )
7370
7471 def endElement (self , name ):
7572 if name == 'block' :
7673 block = self ._stack .pop ()
7774 block .finish ()
7875 self ._blocks .append (block )
79- logging .info ('end of {0}' . format ( block .name ) )
76+ logging .info (f 'end of { block .name } ' )
8077 elif name == 'item' :
8178 self .in_item = False
8279
@@ -86,7 +83,7 @@ def endDocument(self):
8683
8784def main ():
8885 arg_parser = ArgumentParser (description = 'reformat XML code' )
89- arg_parser .add_argument ('-verbose' , action = 'store_true' ,
86+ arg_parser .add_argument ('-- verbose' , action = 'store_true' ,
9087 help = 'print verbose output' )
9188 arg_parser .add_argument ('file' , type = FileType ('r' ),
9289 help = 'XML file to convert' )
0 commit comments