1

I've noticed that when I copy an output cell from my Jupyter (iPython) notebook and post it into my Stack Overflow question, the format gets mangled at times.

Is there a clean way to transfer my output (even input cell) to a Stack Overflow post which includes the in/out labels on the side of the cells?

Sample:

enter image description here

I've also noticed that some users are able to import the Jupyter notebook cells into their post. For example, the highest rated answer was able to incorporate the in and out cells:

How do I get the row count of a Pandas dataframe?

  • 4
    What do you mean it gets mangled? – πάντα ῥεῖ May 7 '17 at 0:48
  • 2
    Can you provide a screenshot or some kind of visual example? – Anthony Pham May 7 '17 at 1:57
  • also, jupiter or jupyter? What's that? – Journeyman Geek May 7 '17 at 5:20
  • @JourneymanGeek: This. – Nathan Tuggy May 7 '17 at 5:49
  • This got nothing to do with Stack Overflow or Stack Exchange. What you get in the question/answer body when pasting is whatever inside the clipboard. The "Jupyter" or whatever it is responsible for putting contents in the clipboard. You can submit a bug in their forums. – Shadow May 7 '17 at 9:38
  • @anthony-pham I've updated. Thank you. – moondra May 7 '17 at 14:55
  • 1
    Unfortunately this is on hold right now (voted to reopen since your screenshot) so I can't post an answer but your problem is just a formatting problem on your end. Either highlight all your pasted data and press ctrl-k (or the "code" button), or surround it in <pre> tags, and you'll get those nice fixed-width text blocks. As for the misaligned columns it's probably just tab widths, after you do code/pre, you may have to tweak column alignments manually, but just look at the live preview. See also meta.stackoverflow.com/questions/251361/…. – Jason C May 7 '17 at 15:12
  • 1
    Btw another good trick is if you see a post with formatting that you like but you don't know how to do it, click the "edit" button under the post and look at the markdown source in the editor. – Jason C May 7 '17 at 15:13
  • Jupyter also uses Markdown "at its base", so some level of compatibility is to be expected. Perhaps it is a case of different Markdown flavours (that is, restricting the use of Markdown in a Jupyter Workbook to some subset of Markdown could make it work)? – Peter Mortensen May 7 '17 at 16:06
  • @PeterMortensen Perhaps, but, looking at the OP's screenshot, it was a case of copying table-ish text and pasting it straight into the editor without formatting it, the same difficulty you'd expect when e.g. copying + pasting straight from Excel or something without indenting it in the editor (see how none of the rows except the header are indented, that'd look awful if posted). – Jason C May 7 '17 at 16:08
  • @JasonC Thanks for the tips. I will see if I can understand their markdown code via edit. – moondra May 7 '17 at 19:36
  • Well, to post tables of text, see this – Shadow May 8 '17 at 6:56
3

I think the Jupyter qtconsole may be what you are looking for.

In your notebook, use the magic command %qtconsole.

Then you can copy the output of this as code to Stack Overflow.

You must log in to answer this question.

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