Pythonのお勉強 Part7
■ このスレッドは過去ログ倉庫に格納されています
0799デフォルトの名無しさん
2005/11/07(月) 01:52:26infile = file('allimport.txt', 'rb').read()
import re
ptn1 = re.compile(r'^¥s*import (.+)$', re.M)
ptn2 = re.compile(r'^¥s*from (.+) import .+$', re.M)
mods = [mod.strip() for mod in ','.join(ptn1.findall(infile)).split(',')] + ¥
[mod.strip() for mod in ','.join(ptn2.findall(infile)).split(',')]
count = {}
for m in mods:
if not count.has_key(m):
count[m] = 0
count[m] += 1
print sorted(count.items(), key=lambda k: k[1], reverse=True)
-----------------
[('pytz.tzinfo', 1577), ('sys', 1271), ('os', 975), ('types', 689), ('string', 516), ('time', 360), ('unittest', 358), ('re', 310), ('wx', 282), ('test', 205), ('Pythoncard', 203), ('Numeric', 198), ...
■ このスレッドは過去ログ倉庫に格納されています