Ask coding questions

← Back to all posts
Python
LittleNomster (112)

is there a way to group code in python, like a command i dont know about, it would be very helpful

Answered by mwilki7 (1130) [earned 5 cycles]
View Answer
Comments
hotnewtop
mwilki7 (1130)

One hack I can think of is putting a bracket inside a comment

# {
    def func():
        print("Code here")
# }

Now you should be able to click the little plus symbol and collapse the code.

LittleNomster (112)

@mwilki7 thanks that solves half of it, the only issue i see is that i cant use variables

mwilki7 (1130)

@LittleNomster
Looks like I tested the # thing before even testing if it worked without.

For the repl you posted I think the error lies with the following print statements not being inside the main function

LittleNomster (112)

@mwilki7 a simplification of this is
#{
code here
as long as you hit tab before your code it will become essentially a folder

Vandesm14 (2624)

Can you give me an example of what you would want your code to look like before and after grouping?

LittleNomster (112)

@Vandesm14 i want something like def main command, where theres a little + button on the side and i can collapse certain sections

LittleNomster (112)

the only issue is you cant use the command twice

LittleNomster (112)

i prefer orginized coding