I want to parse block comments in python. I order to do that I need to find comments section in .py file.
For example, my sample.py contains
'''
This is sample file for testing
This is sample file for development
'''
import os
from os import path
def somefun():
return
I want to parse the comments section for which I am trying to do following in sampleparsing.py
tempfile = open('sample.py', 'r')
for line in tempfile:
if(line.find(''''') != -1):
dosomeoperation()
break
Since if(line.find(''''') != -1): assumes as remaining lines below as commented how to replace this string to find comments?
I tried keeping '\' (escape character) in between but I could not find out solution for this issue.
I need following two lines after parsing in sampleparsing.py:
This is sample file for testing
This is sample file for development
import sample; print sample.__doc__?Python, Guido Von Rossum, approves of using multi-line strings as multi-line comments. See here: twitter.com/gvanrossum/status/112670605505077248