[英]How to copy lines from one file and write them in other file using python?
I have sequence of data as shown below: 我有如下所示的数据序列:
XXXXXXX
DATA = 1,2,3,4,5,6,
7,8,9,10,11,12,14,
15
XXXXXXX
if there is continuation line ends with "," else it has no comma",". 如果有延续行以“,”结尾,则没有逗号“,”。
How can I copy only DATA from given file and write it in other file? 如何仅从给定文件复制DATA并将其写入其他文件? Please help me!
请帮我!
You can do something like this: 您可以执行以下操作:
import re
data_file = open("data.txt", 'r')
data = data_file.read()
search = re.search("DATA\s\=\s((.*\d.+\,?\n)+)", data)
print search.group(1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.