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 2, 2019 in Python by ana1504.k
• 7,910 points
1,555 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 2, 2019 by SDeb
• 13,300 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
1,794 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
665 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
• 69,220 points
10,552 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,510 points
28,122 views
0 votes
2 answers
+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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,434 views
0 votes
1 answer
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,300 points
3,999 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP