[英]Why does my code bring an error up randomly?
嘿,我目前正在尝试构建一个程序,从文本文件中提取信息并将其放入新创建的文件夹和文本文件中,但它似乎有点错误。 我的问题是我收到此错误代码:
Traceback (most recent call last): File "C:/Users/Rene/PycharmProjects/draft/prog.py", line 52, in <module>
new_file = open(next_path, "w+") FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Rene\\PycharmProjects\\draft\\pioranges\\BU raises 040\\SB calls\\BB raises 125\\BU calls\\SB minclicks\\BB calls\\BU minclicks\\SB calls\\BB minclicks\\BU calls\\SB minclicks\\BB calls\\BU minclicks\\SB folds\\BB jams\\BU folds\\40040.1.40125.1.5.1.5.1.5.1.5.1.5.0.3.0.txt'
但这似乎是随机的。 因此,当我使用我需要的所有文件运行脚本时,它处理 800 左右,其他一些文件集处理 2000 等,但是当我删除已经处理的文件时,它不会停止在之前停止它的文件上(即使它如果我不删除任何内容,总是停在同一个文件上),而是停在 200-5000 个文件的范围内,这对我来说似乎完全随机。
这是我的代码
import glob
import os
f = glob.glob("*.txt")
for x in range(len(f)):
file_name = f[0]
file = open(file_name, "r")
periods = file_name.count(".")
next_path = "C:\\Users\\Rene\\PycharmProjects\\draft\\pioranges\\"
sizes = file_name.split(".")
postions = ["LJ", "HJ", "CO", "BU", "SB", "BB"]
first_pos = "BU"
abc = postions.index(first_pos)
open_raiser = postions[abc:]
for i in range(len(sizes)-1):
if sizes[0] == "0":
next_path += open_raiser[0] + " folds" + "\\"
open_raiser.pop(0)
sizes.pop(0)
elif sizes[0] == "1":
next_path += open_raiser[0] + " calls" + "\\"
sizes.pop(0)
open_raiser.append(open_raiser[0])
open_raiser.pop(0)
elif sizes[0] == "3":
next_path += open_raiser[0] + " jams" + "\\"
open_raiser.pop(0)
sizes.pop(0)
elif sizes[0] == "5":
next_path += open_raiser[0] + " minclicks" + "\\"
sizes.pop(0)
open_raiser.append(open_raiser[0])
open_raiser.pop(0)
else:
next_path += open_raiser[0] + " raises " + sizes[0][2:] + "\\"
open_raiser.append(open_raiser[0])
open_raiser.pop(0)
sizes.pop(0)
if not os.path.exists(next_path):
os.makedirs(next_path)
lines = [line.rstrip('\n') for line in open(file_name)]
string = ""
while len(lines) > 0:
hand = lines.pop(0) + ":"
value = lines.pop(0).split(";", maxsplit=1)[0] + ","
string += hand + value
next_path += file_name
print(next_path)
new_file = open(next_path, "w+")
new_file.write(string)
new_file.close()
f.pop(0)
这些文件都是 2-5kb 大,所以它不应该是 memory 问题,对于我应该如何解决这个问题真的一无所知。
提前致谢
找到了答案,是由于文件路径的 260 个字符限制
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.