Python,将关键字之间的txt行附加到另一个txt

Python,将关键字之间的txt行附加到另一个txt,python,string,file,copy,save,Python,String,File,Copy,Save,这里不是一个有经验的用户 我有一个文本文件(export.txt),它是: *NODE several thousand lines like this one several thousand lines like this one several thousand lines like this one *ANY OTHETR WORD 我想将这两个关键字之间的行(都以“*”开头)复制到另一个文件(original.txt)的末尾 已尝试,但尝试复制数据时出错: * * * "Traceb

这里不是一个有经验的用户

我有一个文本文件(export.txt),它是:

*NODE
several thousand lines like this one
several thousand lines like this one
several thousand lines like this one
*ANY OTHETR WORD
我想将这两个关键字之间的行(都以“*”开头)复制到另一个文件(original.txt)的末尾

已尝试,但尝试复制数据时出错:

* * * "Traceback (most recent call last):
File "myscript.py", line 28, in <module>
for line in f:
File "/opt/ansa_15.2.3/meta_post_v15.2.3/../shared_v15.2.3/python/linux64/lib/python3.3/codecs.py",
line 300, in decode (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd3 in position 267: invalid continuation byte"
* * *
***“回溯(最近一次呼叫最后一次):
文件“myscript.py”,第28行,在
对于f中的行:
文件“/opt/ansa_15.2.3/meta_post_v15.2.3/。/shared_v15.2.3/python/linux64/lib/python3.3/codecs.py”,
第300行,解码中(结果,消耗)=自缓冲区解码(数据,自错误,最终)
UnicodeDecodeError:“utf-8”编解码器无法解码位置267处的字节0xd3:无效的连续字节”
* * *
我可以要求一个解决方案吗?谢谢

注意:此解决方案将删除(忽略)返回字符串时未包含的相关字符。仅当您需要剥离它们而不是转换它们时才使用此选项

或者,使用编解码器模块中的open方法读取文件:

import codecs
with codecs.open(file_name, "r",encoding='utf-8', errors='ignore') as fdata:

您使用的是哪种Python版本。不能说得更具体,因为它是一个内置于另一个应用程序中的解释器。啊,是的,我现在看到了显而易见的情况,现在仍然是清晨…:)
str = unicode(str, errors='ignore')
import codecs
with codecs.open(file_name, "r",encoding='utf-8', errors='ignore') as fdata: