Show More
@@ -649,23 +649,24 b' python-profiler package from non-free.""")' | |||||
649 |
|
649 | |||
650 | sys.argv = [filename] + args # put in the proper filename |
|
650 | sys.argv = [filename] + args # put in the proper filename | |
651 |
|
651 | |||
|
652 | if 'n' in opts: | |||
|
653 | name = os.path.splitext(os.path.basename(filename))[0] | |||
|
654 | else: | |||
|
655 | name = '__main__' | |||
|
656 | ||||
652 | if 'i' in opts: |
|
657 | if 'i' in opts: | |
653 | # Run in user's interactive namespace |
|
658 | # Run in user's interactive namespace | |
654 | prog_ns = self.shell.user_ns |
|
659 | prog_ns = self.shell.user_ns | |
655 | __name__save = self.shell.user_ns['__name__'] |
|
660 | __name__save = self.shell.user_ns['__name__'] | |
656 |
prog_ns['__name__'] = |
|
661 | prog_ns['__name__'] = name | |
657 | main_mod = self.shell.user_module |
|
662 | main_mod = self.shell.user_module | |
658 |
|
663 | |||
659 | # Since '%run foo' emulates 'python foo.py' at the cmd line, we must |
|
664 | # Since '%run foo' emulates 'python foo.py' at the cmd line, we must | |
660 | # set the __file__ global in the script's namespace |
|
665 | # set the __file__ global in the script's namespace | |
661 | # TK: Is this necessary in interactive mode? |
|
666 | # TK: Is this necessary in interactive mode? | |
662 | prog_ns['__file__'] = filename |
|
667 | prog_ns['__file__'] = filename | |
663 | else: |
|
668 | else: | |
664 | # Run in a fresh, empty namespace |
|
669 | # Run in a fresh, empty namespace | |
665 | if 'n' in opts: |
|
|||
666 | name = os.path.splitext(os.path.basename(filename))[0] |
|
|||
667 | else: |
|
|||
668 | name = '__main__' |
|
|||
669 |
|
670 | |||
670 | # The shell MUST hold a reference to prog_ns so after %run |
|
671 | # The shell MUST hold a reference to prog_ns so after %run | |
671 | # exits, the python deletion mechanism doesn't zero it out |
|
672 | # exits, the python deletion mechanism doesn't zero it out |
General Comments 0
You need to be logged in to leave comments.
Login now