How do I remove all annotations from the Python code?
I made a code to find a pair of #
or "
and erase the contents of it
Occasionally, a problem occurs when the "
is used as a string.
Isn't there a Python built-in function or any other external library function that does this?
python syntax blocks-comments
As far as I know, there's no such function. But it's not that there's no way at all, and it might be possible if you use the function of the editor (such as Faicham).
'In quotation marks
bound
Remove multi-line annotation ''
uncommented_code = re.sub(re.compile(r"'''.*'''",re.DOTALL ) ,"" ,_CODE)
"""In double quotation marks
bound
Remove multi-line annotation """
uncommented_code = re.sub(re.compile(r'""".*"""',re.DOTALL ) ,"" ,uncommented_code)
Remove comments marked #
uncommented_code = re.sub(re.compile(r"#.*[\n\Z]" ) ,"\n" ,uncommented_code)
You can do it like this.
© 2024 OneMinuteCode. All rights reserved.