使用循环从不同文件中提取数据

时间:2017-04-16 04:24:36

标签: python text

我想从文本文件(txtU2)中提取一些数据,这是在循环中完成的,因为我的文本文件存在的文件夹发生了变化!
我尝试了三种编写代码的方法,但所有这些代码都不正确:

# 1) with open("D:/Prozhey/%d'%(jj+1)/txtU2.txt", "rb") as f: # Open file in read-binary mode

# 2) with open("D:/Prozheye_Avval/JOB/%d"%(jj+1) + "/txtU2.txt", "rb") as f: # Open file in read-binary mode

# 3)
with open('D:/Prozheye_Avval/JOB/%d'%(jj+1) + '/txtU2.txt', "rb") as f: # Open file in read-binary mode
    lines = f.readlines() # Load all lines
x2 = []
U2 = []

有人能告诉我正确的吗?

0 个答案:

没有答案