challenge コメントの削除

ソースコードからコメント部分を削除するプログラム decomment を書いてください.
すくなくとも,decomment を記述したのと同じ言語で書かれているソースコードが
扱えるようにしてください.



Posted feedbacks - Python

初投稿
泥です。
初めてre使った
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
import re, sys

try :
    f = open(sys.argv[1], "r")
    raw_str = f.read()
    f.close()
except :
    print "file read error"

sharpe = re.compile(".*#.*")
s_quote = re.compile("'''")
d_quote = re.compile('"""')

de_sharpe_str = ""
tmp = raw_str.split("\n")
for i in tmp:
    de_sharpe_str += sharpe.split(i)[0] + "\n"

x = [s_quote.split(de_sharpe_str)[x]for x in range(0, len(s_quote.split(de_sharpe_str)), 2)]
y = [d_quote.split(de_sharpe_str)[x]for x in range(0, len(x), 2)]

print "\n".join(y)

Index

Feed

Other

Link

Pathtraq

loading...