Python 3.x 更换输出长度不同的控制台输出
我有一个程序,搜索给定存储库中的文件,检查它们是否包含字符串Python 3.x 更换输出长度不同的控制台输出,python-3.x,loops,Python 3.x,Loops,我有一个程序,搜索给定存储库中的文件,检查它们是否包含字符串 print("Searching files for string...") for folder, dirs, files in os.walk(some_path): for file in files: if file.endswith(".st") or file.endswith(".jsp"): fullpath = os.path.join(folder, file)
print("Searching files for string...")
for folder, dirs, files in os.walk(some_path):
for file in files:
if file.endswith(".st") or file.endswith(".jsp"):
fullpath = os.path.join(folder, file)
# print fullpath
print(fullpath, end="\r", flush=True)
time.sleep(0.5)
# end print fullpath
with open(fullpath, 'r') as read_file:
for (line_number, line) in enumerate(read_file):
if search_term in line:
results_array.append({
"filepath": fullpath,
"line": line_number + 1
})
我想打印控制台的完整路径,但替换该行,而不是在循环迭代时控制台充满输出。对于当前代码,经过几次迭代后,输出开始与前面的行合并,我认为这是因为每次迭代的路径大小不同
e、 g.输出当前代码:
/somepath/example/hello-world.jspfirm.jspidgetsconfig.jsppjspdeals.jsp
如何修复此问题,使每个完整路径都可以打印并干净地删除?
打印(完整路径,end=“\r\n”,flush=True)
。这应该是不可行的,这只会让每个输出都有自己的行,这不是你想要的吗?印刷干净意味着什么?