0 Members and 1 Guest are viewing this topic.
#test2.pyimport reimport sysx=1while x==x: with open("room.txt", mode="a", encoding="utf-8") as log: log.seek(0) for line in log: if not re.search(("apple"), line): log.write("grape") log.write("\n")
cherryorangestrawberrylemmon
Traceback (most recent call last): File "C:\Users\Jacob\Desktop\bot\test2.py", line 8, in <module> for line in log: File "C:\Python30\lib\io.py", line 1739, in __next__ line = self.readline() File "C:\Python30\lib\io.py", line 1813, in readline while self._read_chunk(): File "C:\Python30\lib\io.py", line 1560, in _read_chunk input_chunk = self.buffer.read1(self._CHUNK_SIZE)AttributeError: 'BufferedWriter' object has no attribute 'read1'
A file opened in "a" mode can't be written to. Only r+ or a+ seem suitable for what you want to do.