User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 9606
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

STICKY: Use code tags when posting Python code

Wed Aug 13, 2014 11:33 pm

When posting python code use the code tag like this:

Code: Select all

If true :
    do_this
    and_this
as indentations don't show up when posting without the code tags, (all "unnecessary" spaces are removed) and indentations with spaces (normally 4 spaces) are vital to Python!

you can either press the code "button", then paste inside the tags, or you can paste the code, and while it is still highlighted press the code button.

regarding spaces versus tabs:
My own choice is to preferably instead of multiple spaces consequently use tabs instead. Some edit tools can change a specific number of spaces into a tab, or a tab into a specific number of spaces, you can use that to change all spaces in a code block to tabs, first select all text, then convert all tabs to spaces, then select all groups of (4 or 8 spaces) into tabs again, rinse and repeat, that should solve many "mixed spaces and tabs" problems. you can optically see when there is still a "lost space", or an excess tab, and remove it. the trick is to stay consistent.
Pasting inside a code block will work with spaces or tabs though.

Return to “Python”

Who is online

Users browsing this forum: No registered users and 18 guests