1

I would like to run certain parts of the code and not all of the code while code that I don't want to execute can be sourced out, but remain in the program for future use.

Current code:

for i in v:

    with open('text.txt'.format(i), 'w') as in_file:
        in_file.write(xxx)

    with open('text.txt'.format(i), 'w') as in_file:
        in_file.write(xxx)

One way I know is to use "#" to make it a comment but this is very time wasting because sometimes I have more than 100 lines of codes I do not want to execute and should I just # all of it? Is there a good way to source out 100 lines of codes? I even tried """ < --- but it just make it a comments and usually when running the program the codes within """ """ are still executable.

Expected to source out:

for i in v:

    with open('text.txt'.format(i), 'w') as in_file:
        in_file.write(xxx)

  this>> # with open('text.txt'.format(i), 'w') as in_file:
   this >> #     in_file.write(xxx)
2
  • 1
    Commenting out with # is the best answer - typically you'll have your editor help you with large blocks of code. You can also surround with """ or indent and add if False:, but these are not as good.
    – Amadan
    Aug 29, 2018 at 4:59
  • thank you sir for the answer. I understand
    – JJson
    Aug 29, 2018 at 5:03

2 Answers 2

1

There is no current method for block comments.

Your editor (if you are using an IDE) will have an option to add and remove multiple line comments.

1
  • I see. Alright, thank you so much sir for answering.
    – JJson
    Aug 29, 2018 at 5:03
1

Sorry, I can't comment on this because of the reputation limitation.

If you are using an IDE, you may be able to comment each line using some shortcut key. for example, you can use CTRL+/ in Visual Studio Code. It will put a single line comment '#' in every line of the selected block. Google shortcut keys of your IDE.

Not the answer you're looking for? Browse other questions tagged or ask your own question.