@@ -44,6 +44,19 @@ def short_format_time(t):
4444 return " %5.1fs" % (t )
4545
4646
47+ def pformat (obj , indent = 0 , depth = 3 ):
48+ if 'numpy' in sys .modules :
49+ import numpy as np
50+ print_options = np .get_printoptions ()
51+ np .set_printoptions (precision = 6 , threshold = 64 , edgeitems = 1 )
52+ else :
53+ print_options = None
54+ out = pprint .pformat (obj , depth = depth , indent = indent )
55+ if print_options :
56+ np .set_printoptions (** print_options )
57+ return out
58+
59+
4760###############################################################################
4861# class `Logger`
4962###############################################################################
@@ -70,16 +83,7 @@ def debug(self, msg):
7083 def format (self , obj , indent = 0 ):
7184 """ Return the formated representation of the object.
7285 """
73- if 'numpy' in sys .modules :
74- import numpy as np
75- print_options = np .get_printoptions ()
76- np .set_printoptions (precision = 6 , threshold = 64 , edgeitems = 1 )
77- else :
78- print_options = None
79- out = pprint .pformat (obj , depth = self .depth , indent = indent )
80- if print_options :
81- np .set_printoptions (** print_options )
82- return out
86+ return pformat (obj , indent = indent , depth = self .depth )
8387
8488
8589###############################################################################
@@ -141,8 +145,8 @@ def __call__(self, msg='', total=False):
141145 print (full_msg , file = sys .stderr )
142146 if self .logfile is not None :
143147 try :
144- with open (self .logfile , 'a' ) as logfile :
145- print (full_msg , file = logfile )
148+ with open (self .logfile , 'a' ) as f :
149+ print (full_msg , file = f )
146150 except :
147151 """ Multiprocessing writing to files can create race
148152 conditions. Rather fail silently than crash the
0 commit comments