def extract(code):
    res = []
comment = None
stringio = StringIO.StringIO(code)
for toktype, tokval, begin, end, line in tokenize.generate_tokens(stringio.
    readline):
    if toktype != tokenize.COMMENT:
        res.append((toktype, tokval))
else:
    print(tokenize.untokenize([(toktype, tokval)]))
return tokenize.untokenize(res)
Extracting comments from Python Source Code