2

Many StackOverflow questions or answers involve pasting code from iPython into the question/answer.

This results in things like this:

In [32]: print np.random.random([2, 2])
[[ 0.36687173  0.34079422]
 [ 0.61761034  0.17372093]]

In [33]: type(np.random)
Out[33]: module

Clearly the 32 and 33 are not interesting to future readers of this question, but how do I go about getting rid of them?

Sometimes I edit them to look like In []: and I've seen some people whose answers look like In :

Is there a nice way of dealing with this?

Or should they just be left and actually it doesn't matter that much, and I should go and get on with my life?

3
  • 2
    When I cut and paste from IDLE I leave the prompt (>>>) in, to demonstrate that it's an interactive example (i.e. showing inputs and outputs) rather than a standalone code snippet and (hopefully) thereby prevent people trying to run the outputs and getting confused.
    – jonrsharpe
    Commented Jul 24, 2015 at 14:23
  • 2
    @jonrsharpe the >>> are much less controversially a good idea. Often I find myself putting these in manually for the very reason you suggest!
    – LondonRob
    Commented Jul 24, 2015 at 14:25
  • I have wondered about this issue many times in the past. What I usually do is after trial and error and finding the "final answer", I just start a new IPython session and copy/paste lines one by one so I get the "correct" numeration. Commented May 3, 2016 at 15:43

1 Answer 1

4

I don't think there is harm in leaving the line numbers. It's output from the IPython environment, thus (should be) well known to users in the python tags.

It's similar to pasting a stack trace that says the error is on line 5000, but you've only posted the 10 lines of relevant code around line 5000. There is no need to "fix" the stack trace if the question shows the appropriate snippet of code.

Don't waste time removing (or worse, renumbering) these lines. There are more important things that can be fixed. The question, as posted with the IPython numbers, is perfectly readable.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .