@@ -28,9 +28,9 @@ def _get_memory(pid):
2828 # .. subprocess.check_output appeared in 2.7, using Popen ..
2929 # .. for backwards compatibility ..
3030 out = subprocess .Popen (['ps' , 'v' , '-p' , str (pid )],
31- stdout = subprocess .PIPE ).communicate ()[0 ].split ('\n ' )
31+ stdout = subprocess .PIPE ).communicate ()[0 ].split (b '\n ' )
3232 try :
33- vsz_index = out [0 ].split ().index ('RSS' )
33+ vsz_index = out [0 ].split ().index (b 'RSS' )
3434 return float (out [1 ].split ()[vsz_index ]) / 1024
3535 except :
3636 return - 1
@@ -116,7 +116,7 @@ def _find_script(script_name):
116116 if os .path .isfile (fn ):
117117 return fn
118118
119- print >> sys .stderr , 'Could not find script %s' % script_name
119+ print >> sys .stderr , 'Could not find script {0}' . format ( script_name )
120120 raise SystemExit (1 )
121121
122122
@@ -141,10 +141,11 @@ def add_function(self, func):
141141 """ Record line profiling information for the given Python function.
142142 """
143143 try :
144- code = func .func_code
144+ code = func .__code__
145145 except AttributeError :
146146 import warnings
147- warnings .warn ("Could not extract a code object for the object %r" % (func ,))
147+ warnings .warn ("Could not extract a code object for the object {0!r}"
148+ .format (func ))
148149 return
149150 if code not in self .code_map :
150151 self .code_map [code ] = {}
@@ -208,8 +209,8 @@ def show_results(prof, stream=None):
208209
209210 if stream is None :
210211 stream = sys .stdout
211- template = '%6s %12s %10s %-s '
212- header = template % ('Line #' , 'Mem usage' , 'Increment' , 'Line Contents' )
212+ template = '{0:>6} {1:>12} {2:>10} {3:<} '
213+ header = template . format ('Line #' , 'Mem usage' , 'Increment' , 'Line Contents' )
213214 stream .write (header + '\n ' )
214215 stream .write ('=' * len (header ) + '\n ' )
215216
@@ -225,8 +226,7 @@ def show_results(prof, stream=None):
225226 lines_normalized = {}
226227
227228 # move everything one frame up
228- keys = lines .keys ()
229- keys .sort ()
229+ keys = sorted (lines .keys ())
230230 increment = {}
231231 lines_normalized [code .co_firstlineno + 1 ] = lines [keys [0 ]]
232232 while len (keys ) > 1 :
@@ -238,14 +238,14 @@ def show_results(prof, stream=None):
238238 for l in linenos :
239239 mem = ''
240240 inc = ''
241- if lines_normalized . has_key ( l ) :
241+ if l in lines_normalized :
242242 mem = max (lines_normalized [l ])
243243 inc = mem - mem_old
244244 mem_old = mem
245- mem = '% 5.2f MB' % mem
246- inc = '% 5.2f MB' % inc
245+ mem = '{0: 5.2f} MB' . format ( mem )
246+ inc = '{0: 5.2f} MB' . format ( inc )
247247 line = linecache .getline (filename , l )
248- stream .write (template % (l , mem , inc , line ))
248+ stream .write (template . format (l , mem , inc , line ))
249249
250250if __name__ == '__main__' :
251251 from argparse import ArgumentParser
0 commit comments