Python Forum
Algorithm for extracting comments from Python source code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Algorithm for extracting comments from Python source code
#7
@Gribouillis

The example you provided is in parantheses, so it will be considered as not comment. Of course, people can do different strange variations, but these cases are very rare and I can leave them. I need a common algorithm for common case.

Thank you for you suggestion, I edited #3 for such cases
my_dict = {
    "key1": "not comment",
    "key2": 
        "Not comment"
}

my_list = [
    "Not comment",
    "Not comment"
]
1. IF there are no characters (except whitespaces) before the opening quotes (on the line of code where these quotes are)
2. AND IF there are no characters (except whitespaces) after the closing quotes (on the line where these quotes are)
3. AND IF the line is not between ( ) or [ ] or { }
4. AND IF the previous line of code does not end with \
Reply


Messages In This Thread
RE: Algorithm for extracting comments from Python source code - by Pavel1982 - Feb-28-2024, 09:52 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  delivery exe without source code py loky62 2 391 Apr-04-2024, 05:47 PM
Last Post: loky62
  Error on import: SyntaxError: source code string cannot contain null bytes kirkwilliams2049 7 7,178 Aug-03-2023, 06:00 PM
Last Post: Gribouillis
  How do I add comments from a text-file to an array of folders? clausneergaard 2 1,841 Feb-08-2023, 07:45 PM
Last Post: Larz60+
  python move specific files from source to destination including duplicates mg24 3 1,142 Jan-21-2023, 04:21 AM
Last Post: deanhystad
  Python Snippets Source kucingkembar 0 663 Oct-18-2022, 12:50 AM
Last Post: kucingkembar
  Inserting line feeds and comments into a beautifulsoup string arbiel 1 1,226 Jul-20-2022, 09:05 AM
Last Post: arbiel
  Correct the algorithm of image filter code saoko 6 2,100 May-08-2022, 05:06 PM
Last Post: saoko
  Rock paper scissors in python with "algorithm" Agat0 23 6,237 Mar-01-2022, 03:20 PM
Last Post: Agat0
  Long-term stable source to get news headlines with Python? sandufi 4 1,990 Dec-23-2021, 09:48 AM
Last Post: sandufi
  Delete multiple comments with a single API call (facebook) Ascalon 0 2,354 Dec-04-2021, 08:33 PM
Last Post: Ascalon

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020