I am attempting to make a python script that imports a given file.
Then on the import of the file, I am pulling a value from in the filename to determine what function to run.
I will then eventually extend this to pull all files from a folder rather than explicitly pass it a specific file.
The format of the file names is always the following:
I am wondering if there is a better and more efficient way to pull Value from the above example than what I have given below?
Here is my code:
from os.path import splitext, basename under = '_' base = basename(splitext(filename_goes_here)) value = base[base.find(under)+len(under):base.rfind(under)]
I am aware I can merge my two lines of code above into one line but it would be very unsightly.
Examples of the filenames are:
//path/to/file/GAME_team_2017.csv //path/to/file/GAME_player_2017.csv //path/to/file/GAME_rules_2017.csv
The sample output of the above files would be:
'team' 'player' 'rules'