Directory for python repl?
I have a program where I want to look through a folder for data. How would I list that directory if I upload the folder to my repl?
os.listdir() will show everything in the directory including files and directories. Docs here
If you want files only, you could either filter this down using
os.path Docs here:
from os import listdir from os.path import isfile, join onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
or you could use
os.walk() (Docs here) which gives a list of directories and files separately. If you only want the top directory you can just break the first time it yields
from os import walk found_files =  for (dirpath, dirnames, filenames) in walk(mypath): found_files.extend(filenames) break
If you want to put the files in a list you can use
.extend() Docs Here
If this helped, please hit the check button and leave an upvote.