Reputation: 1792
I have some folder paths that hold model information:
C:\Users\Latitude User\OneDrive\Projects\xxxx\xxxx\xxxx\Predictions\V1_1234
C:\Users\Latitude User\OneDrive\Projects\xxxx\xxxx\xxxx\Predictions\V2_4567
C:\Users\Latitude User\OneDrive\Projects\xxxx\xxxx\xxxx\Predictions\V3_789
The numbers on the end of the folder are actually MAE numbers of the model, so they will change from time to time. But the V1, V2, V3 wont which is why I would like to hard code them below.
I want to call in those folders but ignore the _1234
at the end. I tried adding a * but it also threw an error:
path = r'C:\Users\Latitude User\OneDrive\Projects\xxxx\xxxx\xxxx\Predictions\\'
model1= 'V1'
model2= 'V2'
deploy1 = run_my_model('Model.csv', path + model1 + '*\\')
deploy2 = run_my_model('Model.csv', path + model2 + '*\\')
OSError: [Errno 22] Invalid argument:
Any ideas on how I could program to call the defined name, ignoring the numbers afterwards? Thanks!
Upvotes: 2
Views: 97
Reputation: 99
Did you try using glob? Glob allows wildcards in the file/folder paths. May be it will be helpful. The code snippet
import glob
for name in glob.glob('V1*/Model.csv'):
print(name)
for name in glob.glob('V2*/Model.csv'):
print(name)
gives following output if you have folders V1_1234 and V2_4567:
V1_1234/Model.csv
V2_4567/Model.csv
Upvotes: 2