Ipython "source" command? #1001

Closed
antoine-levitt opened this Issue Nov 15, 2011 · 6 comments

Comments

Projects
None yet
3 participants
@antoine-levitt

If I have a file named test.py with

print a

in it, and if I do this in ipython:

a = 1
%run "test.py"

it'll complain that it doesn't know a, because the environment is different. Any way Ipython could implement a bash-like "source" command that'll treat the script just as if it was entered in the interpreter? That kind of stuff is especially useful when using ipython as a matlab-like environment for scientific computing (do some computation, and then some plots of it or something)

@takluyver

This comment has been minimized.

Show comment
Hide comment
@takluyver

takluyver Nov 15, 2011

Member

It's already there: %run -i test.py.

There's a long paragraph in the docstring describing the normal behaviour before we explain the -i option, but I'm not sure if it can easily be improved.

Member

takluyver commented Nov 15, 2011

It's already there: %run -i test.py.

There's a long paragraph in the docstring describing the normal behaviour before we explain the -i option, but I'm not sure if it can easily be improved.

@takluyver takluyver closed this Nov 15, 2011

@antoine-levitt

This comment has been minimized.

Show comment
Hide comment
@antoine-levitt

antoine-levitt Nov 15, 2011

15/11/11 14:53, Thomas

It's already there: %run -i test.py.

There's a long paragraph in the docstring describing the normal
behaviour before we explain the -i option, but I'm not sure if it can
easily be improved.

Oh right, thanks! I actually didn't see the docstring, because I did

%run??

which didn't have anything useful. %run? does. Is this expected, or is
it a bug?

15/11/11 14:53, Thomas

It's already there: %run -i test.py.

There's a long paragraph in the docstring describing the normal
behaviour before we explain the -i option, but I'm not sure if it can
easily be improved.

Oh right, thanks! I actually didn't see the docstring, because I did

%run??

which didn't have anything useful. %run? does. Is this expected, or is
it a bug?

@takluyver

This comment has been minimized.

Show comment
Hide comment
@takluyver

takluyver Nov 15, 2011

Member

You're welcome!

%run?? shows the source of the function. We then don't show the docstring
separately, because it's there in the source.This is working as expected
for me in 0.11 and in master.

Member

takluyver commented Nov 15, 2011

You're welcome!

%run?? shows the source of the function. We then don't show the docstring
separately, because it's there in the source.This is working as expected
for me in 0.11 and in master.

@antoine-levitt

This comment has been minimized.

Show comment
Hide comment
@antoine-levitt

antoine-levitt Nov 15, 2011

15/11/11 15:27, Thomas

You're welcome!

%run?? shows the source of the function. We then don't show the docstring
separately, because it's there in the source.This is working as expected
for me in 0.11 and in master.

I don't have the docstring in the source:

$ %run??
Type: Magic function
Base Class: <type 'instancemethod'>
String Form:<bound method TerminalInteractiveShell._pylab_magic_run of <IPython.frontend.terminal.interactiveshell.TerminalInteractiveShell object at 0x2465c50>>
Namespace: IPython internal
File: /usr/local/lib/python2.7/dist-packages/IPython/core/magic.py
Definition: %run(self, parameter_s='')
Source:
@skip_doctest
def _pylab_magic_run(self, parameter_s=''):
Magic.magic_run(self, parameter_s,
runner=mpl_runner(self.shell.safe_execfile))

$

15/11/11 15:27, Thomas

You're welcome!

%run?? shows the source of the function. We then don't show the docstring
separately, because it's there in the source.This is working as expected
for me in 0.11 and in master.

I don't have the docstring in the source:

$ %run??
Type: Magic function
Base Class: <type 'instancemethod'>
String Form:<bound method TerminalInteractiveShell._pylab_magic_run of <IPython.frontend.terminal.interactiveshell.TerminalInteractiveShell object at 0x2465c50>>
Namespace: IPython internal
File: /usr/local/lib/python2.7/dist-packages/IPython/core/magic.py
Definition: %run(self, parameter_s='')
Source:
@skip_doctest
def _pylab_magic_run(self, parameter_s=''):
Magic.magic_run(self, parameter_s,
runner=mpl_runner(self.shell.safe_execfile))

$

@takluyver

This comment has been minimized.

Show comment
Hide comment
@takluyver

takluyver Nov 15, 2011

Member

Ah, I didn't know we overrode magic_run for pylab. I don't think there's
anything we actually need to fix there, since %run? still works correctly.

Member

takluyver commented Nov 15, 2011

Ah, I didn't know we overrode magic_run for pylab. I don't think there's
anything we actually need to fix there, since %run? still works correctly.

@fperez

This comment has been minimized.

Show comment
Hide comment
@fperez

fperez Nov 15, 2011

Member

Agreed, I think it's OK to leave it closed, the behavior is completely consistent: run?? is showing the correct sources, it's just that in this case the source is a wrapper around the original. But with run? showing the true docstring, it's working as desigined.

Member

fperez commented Nov 15, 2011

Agreed, I think it's OK to leave it closed, the behavior is completely consistent: run?? is showing the correct sources, it's just that in this case the source is a wrapper around the original. But with run? showing the true docstring, it's working as desigined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment