0

my program should parse /classifiers folder and go throught some calc. Here is a paths for folders:

classifiers_path = os.path.join('C:/Users/feature/classifiers')

Here is a lines of code, that parses that folder:

        for i in os.path.join(classifiers_path + '/*.pkl'):
        # Pulling the model from the path
        model = joblib.load(i)

While debugging i have paths like this:

C:/Users/feature/classifiers\\T1.pkl

So it breaks with FileNotFoundError, How to avoid this double \, and it should be written, for unix/windows? Thanks

Relyativist
  • 56
  • 1
  • 11

1 Answers1

0

As is stated in the comments, you should be iterating through the files in the directory, not through the string resulting from os.path.join(). So instead, iterate through the list of files in your classifiers_path directory resulting from passing it to os.listdir() like this:

for i in os.listdir(os.path.join(classifiers_path)):
        if i.endswith('.pkl'):
            model = joblib.load(i)
kamses
  • 465
  • 2
  • 10