python - 读取文件并尝试补全数据库中缺失的信息
问题描述
到目前为止,我将其拆分为已完成和未完成,但我不确定如何尝试恢复丢失的数据,这是一个完整行的示例:
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()
解决方案
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
推荐阅读
- angular - 在 Liferay 7.0 ga6 中创建角度模块
- python - Python 在多个用户上运行相同的脚本/命令
- python - 如何使信号居中以从零开始
- r - 有没有办法在我的 R 中的道路网络分析中解决这个问题?
- amazon-ec2 - 如何将移动应用程序生成的流量(API 调用)列入 EC2 API 服务器的白名单/允许
- javascript - 您应该存储 Google 访问令牌吗?
- ios - UIActivityViewController 完成块问题。当用户“取消”消息时不会被调用
- c++ - 困难的硬币交换算法
- excel - 如何复制并找到最后 125 行?
- unit-testing - 数据库单元测试 - 如何模拟过程中的时间