首页 > 解决方案 > 读取文件并尝试补全数据库中缺失的信息

问题描述

到目前为止,我将其拆分为已完成和未完成,但我不确定如何尝试恢复丢失的数据,这是一个完整行的示例:

Ahmad Omar;802424333;10 April 2000;0550123456;A10B20;Audi;2018;15 April 2020;17 April 2020;350

如果可能的话,我们应该恢复名称 ids dob 汽车名称和型号年份,并且是否可以更改此代码,以便读取文件夹中的所有文件而不是读取文件

  def splitCompleteAndIncomplete():
      f = open("temp.txt","r")
      completeFile = open("CarRentalCompleted.txt","w")
      incompleteFile = open("CarRentalMissing.txt","w")
      for row in f.readlines():
        li = row.split(";")
        incompleteFlag=0
        for i in li:
          if len(i) == 0:
            incompleteFlag=1
        if(incompleteFlag == 1):
          incompleteFile.write(row)
        else:
          completeFile.write(row)
      f.close()
    splitCompleteAndIncomplete()

标签: python

解决方案


Import the os module and read the documentation for os.path.listdir() and os.path.join() methods. You can prompt to input a folder destination and listdir method will list all files in the directory and join method will complete the file location. This will surely work, if there's any problem do reply


推荐阅读