我有文件 a.txt ,里面是: aaa = bbb,ccc = ddd,eee = fff,。而且我有多个文件( b.txt,c.txt ...),它们类似于: aaa = ggg,asd = fsd,eee = hhh,。我想创建一个新文件 combine.txt ,该文件将尝试在“ =” 签名之前找到相同的字符串,并用“ =”之后的另一个文件中的数据替换它们标志。因此,如果我们查找的是新文件,则新文件( combine.txt )如下所示: aaa = ddd,asd = fsd,eee = fff,使用split()方法(也许有更好的方法:D),但是我是编程新手,所以我需要帮助:)
file1 = open("/home/xxx/Desktop/Input1").read().split(" = ")
for line in a:
Type = line.split(" = ")
a1 = Type[0]
c = Type[1]
file2 = [open("/home/xxx/Desktop/Input2").read()];
for line in file2:
Type = line.split(" = ")
a2= Type[0]
d = Type[1]
output = open("/home/xxx/Desktop/Output1").write();
if(a1 == a2):
print(a1 + ' = ' + d)