Python AST with preserved comments

0 votes
I can get AST without comments using

import ast
module = ast.parse(open('/path/to/module.py').read())
 

Could you show an example of getting AST with preserved comments ?
Feb 1 in Python by ana1504.k
• 7,890 points
124 views

1 answer to this question.

0 votes
The ast module doesn't include comments. The tokenize module can give you comments, but doesn't provide other program structure.
answered Feb 1 by SDeb
• 13,210 points

Related Questions In Python

0 votes
1 answer

How to perform web scraping with python?

Hey, there are various libraries used in ...READ MORE

answered Apr 20, 2018 in Python by aayushi
• 750 points
330 views
0 votes
1 answer

Python comments

Use docstrings for multi-line commenting -  """ Line 1 Line ...READ MORE

answered May 7, 2018 in Python by Nietzsche's daemon
• 4,260 points
35 views
+1 vote
2 answers

Measuring the distance between pixels on OpenCv with Python

You can try this: Mat pts1(nPts, 1, CV_8UC2), ...READ MORE

answered Aug 24, 2018 in Python by Omkar
• 68,480 points
3,622 views
0 votes
1 answer

Create an empty list in python with certain size

Try this instead: lst = [None] * 10 The ...READ MORE

answered Aug 2, 2018 in Python by bug_seeker
• 15,360 points
1,409 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 416 views
0 votes
11 answers
0 votes
1 answer

Increment with ++ in Python

Python doesn't support ++, so we use: number ...READ MORE

answered Nov 8, 2018 in Python by SDeb
• 13,210 points
61 views