How to show python code snippets in GeoNet questions

2683
5
Jump to solution
04-09-2015 10:02 AM
SepheFox
Frequent Contributor

I'm sorry to ask such a rookie question, but I notice some people are able to display snippets of python code in questions and answers on GeoNet, just as it might appear Python Win, or other python editing software, and maintaining all its formatting. Is this just a screen shot, a snip, or something else? It looks like other people are able to edit and then repost the code, so I don't think it's a graphic. Thanks!

1 Solution

Accepted Solutions
BlakeTerhune
MVP Regular Contributor
5 Replies
BlakeTerhune
MVP Regular Contributor
SepheFox
Frequent Contributor

Thanks for the reply, Blake. That seems pretty straightforward. So, how does one copy or edit the code block when replying to a question? Is it a simple copy and paste?

0 Kudos
BlakeTerhune
MVP Regular Contributor

You can copy and paste the code because it is still just text. However, keep in mind that the editor in GeoNet is a rich text editor so it will try to keep any formatting that was on the original text. So if you copy a small portion of text from a code block with syntax highlighting and paste it into your reply, it will display with the same color and font but might be missing the background that's added when it's actual syntax highlighting. So if you try to copy and paste code like that, it might look weird.

I find it's better to paste it into notepad (or some text editor that strips formatting) and then copy it from there and paste it into GeoNet. Once it's back in the GeoNet editor, you can apply syntax highlighting again and it will look like it should.

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

Do all your editing in your IDE then...and only then...should you copy it over and format it.  Editing it when it is formatted is really bad and frustrating.  I find it much easier to highlight the whole block, hit the bigold Delete key, then copy and paste the good stuff back in and reformat.  Don't believe me?  Do a time trial

SepheFox
Frequent Contributor

Great! Thanks for the help guys!

0 Kudos