I've written a couple of simple command line/terminal Python programs to parse the data files from the experiment-running software we use in our psychology lab. The programs are going to be used by people who are generally computer savvy, but not necessarily up to speed with full-blown unix style commands with flags, so I generally just have the program ask questions like "Which file do you want to process?" and have the user pick from a list, like this:
import textwrap
import os
import sys
def get_folder():
""" Print a numbered
list of the subfolders in the working directory
(i.e. the directory the
script is run from),
and returns the directory
the user chooses.
"""
print(textwrap.dedent(
"""
Which folder are your files located in?
If you cannot see it in this list, you need
to copy the folder containing them to the
same folder as this script.
"""
)
)
dirs = [d for d in os.listdir() if os.path.isdir(d)] + ['EXIT']
dir_dict = {ind: value for ind, value in enumerate(dirs)}
for key in dir_dict:
print('(' + str(key) + ') ' + dir_dict[key])
print()
resp = int(input())
if dir_dict[resp] == 'EXIT':
sys.exit()
else:
return dir_dict[resp]
Are there any implementations of these kinds of file choosers floating around in Python libraries? I've generally just been quickly implementing them myself whenever I need one, but I just end up having to copy and paste the code from file to file and modify for the specific case I'm using them for.