我不太确定这个问题是否已经得到了回答,我也不确定如何查找它,所以我在这里试试运气
我对Python相当陌生,需要解决这个参数:使用从2.txt
文件中提取的数据创建一个新文件
我有以下.txt
文件:
# empList
# format: Employee number, First name, Last name, Department, Rate
201701013,Simona,Morasca,Finance,450;
201011003,Mitsue,Tollner,Marketing,750;
201409015,Leota,Dilliard,Finance,365;
199512017,Sage,Wieser,MIS,750;
199708003,Kris,Marrier,Admin,750;
# empMR
# format: Employee number, month, days worked
201612010,4,18;
201710017,4,12;
201701013,4,20;
201011003,4,24;
201409015,4,26;
199512017,4,28;
199708003,4,21;
我努力实现的目标是:
我有这个代码,我正在试验,但唉,我仍然无法解决这个问题
while True:
with open("empList.txt", "r") as f1, open("empMR.txt", "r") as f2:
data1 = f1.read()
data2 = f2.read()
x1 = data1.strip().split(';')
x2 = data2.strip().split(',')
for (line1, line2) in (x1, x2):
line1 = line1.strip().split(',')
print(line2)
与此同时,我正在尝试先打印所有内容,以便查看代码是否正常工作,因为编写一个文件需要花费大量时间,打印时也一样
现在是所需的输出:
我应该从empList
获得:员工编号、员工姓名、部门和费率;然后从empMR
开始,我应该得到这个月,而且这些天都在工作。把它打印出来(或者用这些数据创建一个新文件),这样我就可以继续工作了
我不知道我说的是否有道理,但如果你需要澄清,请告诉我。谢谢
您可以这样做:
输出将是一个列表。但您可以轻松地修改此选项:
以下是您可以做的:
输出:
相关问题 更多 >
编程相关推荐