我只是想添加一個字符串到文件結尾,但我無法讓它工作。我得到這個錯誤:在Python中添加文件末尾的東西?
IOError: (9, 'Bad file descriptor')
我得到它的行123這是在下面的代碼,但標有#hashcomment:
pluginlokacija2 = os.path.realpath("%s/plugins"%os.getcwd())
fo = open("%s/TwistedJobs/config.yml"%pluginlokacija2, "wb")
old = fo.read() #this is line no. 123
fo.seek(0)
fo.write("%s\n- %s\n " % (old, event.getPlayer().getName()))
fo.close
在此先感謝,阿馬爾!
P.S.如果您需要更多信息,請在評論中提出要求!
你打開文件進行寫入,但後來試圖從中讀取。 – martineau