Reputation: 122142
Often i only need the 2nd thing
that was returned from a function; for example the code below where i want get a list of .txt
files and get the filenames without the extension:
import os, glob
indir = "/home/alvas/whatever/"
for infile in glob.glob(os.path.join(indir,'*'):
PATH, FILENAME = os.path.split(infile)
FILENAME.rstrip(".txt")
Instead of doing:
PATH, FILENAME = os.path.split(infile)
I could also do:
FILENAME = os.path.split(infile)[1]
Are there other ways of doing this?
Upvotes: 0
Views: 70
Reputation: 32521
One idiomatic way is to do
_, FILENAME = os.path.split(infile)
With the convention that _
is a variable that you are discarding or ignoring.
Upvotes: 4