I know this may be a repetitive question but it has a special point which i can't find out.
I'm trying to retrieve files from a directory in my python application. The function below retrieves a proportion of files based on testOrTrain
variable. Here is my code:
def get_files_in_dir(directory,trainOrTest):
file_names_list = []
for file_name in glob.glob(directory):
file_names_list += [file_name]
#1 for train_data and 0 for test_data
if trainOrTest == 1:
proportion = len(os.listdir(directory))*65/100
return file_names_list[:int(proportion)]
elif trainOrTest == 0:
proportion = len(os.listdir(directory))*35/100
return file_names_list[int(proportion):]
# return file_names_list
And here is the function in which i use it:
def training_data():
for i in range(1,2):
p = 'C'+'%.2d' % i
file_path = os.path.join('ohsumed-all',str(p),'*')
for file in get_files_in_dir(file_path,1):
file_data = get_text_file_data(file)
print(file_data)
This code gives me the error "No such file or directory". The strange thing about this code is that when i delete the if
parts and just simply return files_names_list(the part of code in the comment), it works fine.
Does somebody know what is happening here?
By the way, i'm working on wsl(ubuntu)
question from:
https://stackoverflow.com/questions/65872368/strange-issue-on-retrieving-a-proportion-of-files-from-a-directory-no-such-file 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…