##// END OF EJS Templates
fix #1814 set __file__ when running .ipy files
s8weber -
Show More
@@ -277,20 +277,17 b' class InteractiveShellApp(Configurable):'
277 sys.argv = [ py3compat.cast_bytes(a) for a in sys.argv ]
277 sys.argv = [ py3compat.cast_bytes(a) for a in sys.argv ]
278 try:
278 try:
279 if os.path.isfile(full_filename):
279 if os.path.isfile(full_filename):
280 if full_filename.endswith('.ipy'):
280 self.log.info("Running file in user namespace: %s" % full_filename)
281 self.log.info("Running file in user namespace: %s" %
281 # Ensure that __file__ is always defined to match Python behavior
282 full_filename)
282 self.shell.user_ns['__file__'] = fname
283 self.shell.safe_execfile_ipy(full_filename)
283 try:
284 else:
284 if full_filename.endswith('.ipy'):
285 # default to python, even without extension
285 self.shell.safe_execfile_ipy(full_filename)
286 self.log.info("Running file in user namespace: %s" %
286 else:
287 full_filename)
287 # default to python, even without extension
288 # Ensure that __file__ is always defined to match Python behavior
289 self.shell.user_ns['__file__'] = fname
290 try:
291 self.shell.safe_execfile(full_filename, self.shell.user_ns)
288 self.shell.safe_execfile(full_filename, self.shell.user_ns)
292 finally:
289 finally:
293 del self.shell.user_ns['__file__']
290 del self.shell.user_ns['__file__']
294 finally:
291 finally:
295 sys.argv = save_argv
292 sys.argv = save_argv
296
293
General Comments 0
You need to be logged in to leave comments. Login now