读取目录中的文件无法像Python中那样工作

时间:2018-10-14 06:40:59

标签: python-3.x file

我在读取一个目录中的文件时遇到了麻烦,我已经设置了该目录的路径,即path_frms,然后使用glob.glob以精确格式(.frms)列出了该文件的列表。这个效果很好,结果是:

"Reading file c:/users/*censor*/desktop/copy\file1.frm 
1       SourceObject    =   "14VOB0525"
.
reading code
.
3       SourceObject    =   "14VOB0532"

Reading file c:/users/*censor*/desktop/copy\file2.FRM 

然后它停止在读取文件2之后的文件,老实说,我不知道问题可能在哪里。 我的代码有一部分,不想发布整个代码,有点长。

files = []
for file in glob.glob(path_frms):
    files.append(file)

print(files)
for read_file in files:
    print("Reading file " + read_file)
    with open(read_file, "r") as rf:
        rf_read = rf.readlines() 
        for each_line in rf_read: 

谢谢您的帮助。 祝你有美好的一天

0 个答案:

没有答案
相关问题