Last active
May 26, 2017 04:13
-
-
Save brun0xff/acd72f0d4a822d1b2eb3cba296e2d945 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
code = """ | |
\""" this is a comment \""" | |
#comment one | |
\""" this is another fucking comment \""" | |
a = 4 | |
b = 2 | |
\""" now im gonna to test my code \""" | |
print a + b #test like awesome fucking genius | |
a = 5 #i have no more idea for put in here | |
b = 7 | |
print a + 5 #sum basic | |
\""" | |
holy shit! | |
\""" | |
""" | |
def removing_comments(str_code): | |
code = str_code.strip() | |
text = '' | |
i = 0 | |
while '#' in code: | |
if code[i] == '#': | |
while i < len(code) and code[i] != '\n': | |
text = text + code[i] | |
i += 1 | |
code = code.replace(text, '') | |
text = '' | |
i = 0 | |
i += 1 | |
code = code.strip() | |
text = '' | |
i = 0 | |
while '\"""' in code and i < len(code)-3: | |
if code[i] + code[i+1] + code[i+2] == '\"""': | |
text = text + code[i] + code[i+1] + code[i+2] | |
i = i + 3 | |
while i < len(code)-3 and code[i] + code[i+1] + code[i+2] != '\"""': | |
text = text + code[i] | |
i += 1 | |
text = text + code[i] + code[i+1] + code[i+2] | |
code = code.replace(text, '') | |
text = '' | |
i = 0 | |
i += 1 | |
return code.strip() | |
code = removing_comments(code) | |
print 'result' | |
print code | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment