Skip to content

Commit d52f82a

Browse files
committed
updated python version verification so it doesn't break on future python 4 release
1 parent c08a886 commit d52f82a

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

memory_profiler.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@
3131
line_cell_magic = lambda func: func
3232
magics_class = lambda cls: cls
3333

34-
PY3 = sys.version_info[0] == 3
34+
PY2 = sys.version_info[0] == 2
3535

3636
_TWO_20 = float(2 ** 20)
3737

38-
if PY3:
38+
if PY2:
39+
import __builtin__ as builtins
40+
else:
3941
import builtins
4042
def unicode(x): return str(x)
41-
else:
42-
import __builtin__ as builtins
4343

4444
# .. get available packages ..
4545
try:
@@ -903,18 +903,18 @@ def inner_wrapper(f):
903903
# globally defined (global variables is not enough
904904
# for all cases, e.g. a script that imports another
905905
# script where @profile is used)
906-
if PY3:
906+
if PY2:
907907
def exec_with_profiler(filename, profiler):
908908
builtins.__dict__['profile'] = profiler
909-
# shadow the profile decorator defined above
910909
ns = dict(_CLEAN_GLOBALS, profile=profiler)
911-
with open(filename) as f:
912-
exec(compile(f.read(), filename, 'exec'), ns, ns)
910+
execfile(filename, ns, ns)
913911
else:
914912
def exec_with_profiler(filename, profiler):
915913
builtins.__dict__['profile'] = profiler
914+
# shadow the profile decorator defined above
916915
ns = dict(_CLEAN_GLOBALS, profile=profiler)
917-
execfile(filename, ns, ns)
916+
with open(filename) as f:
917+
exec(compile(f.read(), filename, 'exec'), ns, ns)
918918

919919

920920
class LogFile(object):

0 commit comments

Comments
 (0)