는 다음 스크립트를 감안할 때 :ConfigParser가 디스크에 즉시 쓰지 않는 이유는 무엇입니까?
$ touch test.conf
$ python tests.py # this is what I've named the above
$ $ cat test.conf
[test]
2012-10-10_231439 = oh hey there
그러나 당신이 time.sleep (1) 모든 항목의 주석을 해제하는 경우 :에 의해 그림과 같이 그것은 단지, 파일에 하나 개의 항목을 작성합니다
import ConfigParser
from datetime import datetime
import time
def write_stuff():
section = "test"
item = "oh hey there"
conf_filename = "test.conf"
conf = ConfigParser.ConfigParser()
conf.readfp(open(conf_filename, 'r', 0))
timestamp = datetime.now().strftime("%Y-%m-%d_%H%M%S")
conf.set(section, timestamp, item)
with open(conf_filename, "w", 0) as conf_file:
# time.sleep(1)
conf.write(conf_file)
write_stuff()
write_stuff()
write_stuff()
write_stuff()
나타나다. 이상하게도 (어쨌든, 나에게) write_stuff()를 한 번 호출하고 쉘에서 스크립트를 빠르게 연속적으로 호출하면이 문제가 발생합니다. 일단 파이썬이 종료되면 디스크에 무엇이든지 디스크에 저장 될 것이라고 생각합니다. 무슨 일이야?
환경 : 파이썬 2.7.3 맥 OS X에서 10.8
* facepalm * 나는 그 말이 맞다고 생각한다 :) 고마워. –