How to format Python code as Python snippets on stack overflow since we can only do it as JavaScript or HTML or CSS snippets?
-
3This is probably a question for Meta Stack OverflowJack Deeth– Jack Deeth2022-02-03 20:34:37 +00:00Commented Feb 3, 2022 at 20:34
-
1I would imagine that JS, HTML, and CSS are supported as actual snippets because SO is used on a browser, and those are browser-specific languages. There is no expectation that someone would be able to run Python in a browser so the code cannot be executed in a snippet and instead, you're expected to simply format Python code as "code".Kraigolas– Kraigolas2022-02-03 20:35:46 +00:00Commented Feb 3, 2022 at 20:35
-
1Can you clarify what you're asking? Are you asking about properly formatting (highlighting, etc.) posted Python code or about making it executable? "format Python code" and "Python snippets" are two different things, as snippets are about making code executable.CryptoFool– CryptoFool2022-02-03 20:42:51 +00:00Commented Feb 3, 2022 at 20:42
-
@Python_Guy As others have correctly pointed out, only HTML/JS/CSS are supported. However, using pyodide you can run python in the browser and call it from JS. Using this, my project PyPrez allows you to run Python snippets in your Stack Overflow questions and answersModularizer– Modularizer2022-10-20 01:32:44 +00:00Commented Oct 20, 2022 at 1:32
Add a comment
|
1 Answer
If you mean executable snippets, you can only do this with html/css/js:
p {
color: red;
}
<p>You can't do this with Python... sadly</p>
If you want to simply format a snippet, you can do this:
# This is Python code
printing this:
```python
# This is Python code
```
to do this you have to send key ctrl+k on a new line.