Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

history -o works but history with -n produces identical results #3738

Closed
pleabargain opened this issue Jul 23, 2013 · 10 comments
Closed

history -o works but history with -n produces identical results #3738

pleabargain opened this issue Jul 23, 2013 · 10 comments
Milestone

Comments

@pleabargain
Copy link

I want to export/ print the input and the output from history but:

%history -n 10-11 -o

and

%history -o -n 10-11
produce the same results

Is this a bug?

here's the notebook
history issue starts at line 19 in notebook
http://pastebin.com/XpFd5QkT

historyscreenshot

@Carreau
Copy link
Member

Carreau commented Jul 23, 2013

What are you expecting ?

%history [-n] [-o] [-p] [-t] [-f FILENAME] [-g [PATTERN [PATTERN ...]]]
               [-l [LIMIT]] [-u]
               [range [range ...]]

It seem that you missread the docs and are expecting a [-n range [range ...]] [-o range [range ...]], which is not the usage of %history

@pleabargain
Copy link
Author

I humbly request the command that will print the user input from line 10-11 with the output.

As I read: -o also print outputs for each input.
But no -o command with a range seems to work

I understood in Fernando's video http://www.youtube.com/watch?feature=player_embedded&v=bP8ydKBCZiY that a user could print only the input and the output of the history if so desired.

I've tried these variations none of which produced the only the input and not the output:
%history -n 10-11 -o
%history -o -n 10-11
%history -n -o 10-11
and
%history -o 10-11 -n 10-11 (which threw: UsageError: unrecognized arguments: 10-11)

Even
%history -o 10-11
only prints the input and not the output

Curiously
%history -o

produced only input which makes me wonder is -o is working at all.

I would appreciate your assistance in the correct command for including input strings and the output.

Here's the updated gist:
https://gist.github.com/pleabargain/6062926

your help is appreciated.
Dennis

@Carreau
Copy link
Member

Carreau commented Jul 23, 2013

Yes, but for the output to be printed, there need to be an output... in your example 10 and 11 do not have output so -o has no effects. I'll close but feel free to continue to ask questions.

@Carreau Carreau closed this as completed Jul 23, 2013
@pleabargain
Copy link
Author

Thanks for the quick reply BUT line 11 (now 39) does have output:
In [39]:

IPython.display?
Object IPython.display not found.

It's an error message. Doesn't that count as output? That is part of my goal is to get the error messages so that they can be documented/explained.

Further, if I do

print ('darn')
the output 'darn' is not returned when I
%history -o 40

-o means output right?
Please see screengrab.
nooutputscreenshot

thank you

@ivanov ivanov reopened this Jul 23, 2013
@Carreau
Copy link
Member

Carreau commented Jul 23, 2013

No there is no output.
there are displayed things.

In [1]: print 'foo'
foo

no output, only display

In [2]: 'foo'
Out[2]: 'foo'

output, which value is 'foo'

hence

In [3]: hist -n -o 1-2
   1: print 'foo'
   2: 'foo'
'foo'

@Carreau Carreau closed this as completed Jul 23, 2013
@pleabargain
Copy link
Author

Thank you for your time but I think there is a bug in the latest ipython because I do not get the same results as you.
differentresultsscreenshot

@Carreau
Copy link
Member

Carreau commented Jul 23, 2013

In [40]: print ('darn')
darn

In [41]: history -o 40
print ('darn')

In [42]: history -n -o 40-41
  40: print ('darn')
  41: history -o 40

No I get the same as you. darnis not an output, it is a displayed value. if you don't have Out[x] it will not show in his -o.

@pleabargain
Copy link
Author

I was operating with the definitions of input was anything that a user entered and that output was anything that the computer spits out. Semantics problem, I guess.

Ok, that said, how do I tell Ipython that I want to copy/log of all displayed values/outputs? The error messages are valuable to me.

many thanks,
Dennis

@Carreau
Copy link
Member

Carreau commented Jul 24, 2013

I was operating with the definitions of input was anything that a user entered and that output was anything that the computer spits out. Semantics problem, I guess.

No there is basically the same difference as the return value of a function and the function printing something

Ok, that said, how do I tell Ipython that I want to copy/log of all displayed values/outputs? The error messages are valuable to me.

You can try to use the %%capture magic, but I'm not sure of how much it can capture though.

@ivanov
Copy link
Member

ivanov commented Jul 24, 2013

@pleabargain what you want to do is use the %%capture magic

%%capture your_var
%history -o 40

and then you'll have your_var.stdout available as a string, same with your_var.stderr, and coming soon in #3744, the rich displays, as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants