今日の SeeMe for Linux バックアップ。

Iinifile クラスで lng を読み込むと糞遅いので又 InifileReader クラスを作ったけど
class InifileReader():
def __init__(self, filename):
self.filename = filename
def __get_value(self, section, key):
if os.path.exists(self.filename):
section_in = False
f = open(self.filename)
try:
for linenn in f:
line = linenn.strip()
if line == "":
continue
if section_in:
if "=" in line:
pos = line.index("=")
if key == line[:pos]:
return line[pos+1:]
if len(line) > 2 and line[0] =="[" and line[-1] == "]":
return None
if len(line) > 2 and line[0] =="[" and line[-1] == "]":
if section == line[1:-1]:
section_in = True
finally:
f.close()
return None
File オブジェクトでループができてしまうんだ、これはかなり微妙。
StreamReader とか専用のクラスを作っている .NET のほうが遥に解りやすいんですけど。
改行が含まれてしまうので strip() しないと面倒くさいし。
それと .NET をやった後に Python の open() を使うと少し変な気分。
finally で open したファイルを閉じる必要は Python では無いわけだが .NET では必須。
IronPython ではどっち?