8

I've searched on Google and could not find any information on recommended ways to highlight sections of code with comments.

I'm thinking of something like this:

###########################################################
# This section is clearly labeled using comments so you can 
# instantly identify its purpose within this file.
###########################################################

I see this kind of thing a lot in php for example.

Is there a convention for this kind of thing in python? If not, is there a good reason to avoid it?

If this is generally done using multi-line comments, could someone please provide an example of how it's done in this "headline" style?

EDIT: I know about multi-line comments. But generally I associate these with a single function rather than a section of code. So more specifically I'm thinking something like this for a small game in a single file:

###################################################
#              CONFIGURATION   
##################################################

configuration code...

###################################################
#              HELPER FUNCTIONS
#################################################   

helper functions.....

###################################################
#                 GRAPHICS HANDLING
#######################################################

graphics handling....
3
  • Take a look at this? stackoverflow.com/questions/7696924/… Commented Jul 27, 2019 at 7:56
  • Do you mean highlight the code in comments in IDE? Commented Jul 27, 2019 at 7:57
  • 1
    In Spyder, you can use # %% Section Header to mark a collapsible section of code. I have no idea if that's just in Spyder or a more widespread convention. Commented Sep 14, 2022 at 7:36

1 Answer 1

3
##############
# Game Setup #
##############

code...

##################
# Function Setup #
##################

code...

################
# Screen Setup #
################

code...

That's the kind of thing I meant. Found some good examples in https://github.com/lordmauve/pgzero

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.