1

I am able to execute the following, where it uses each member of the list to create a different path:

diagnoses = ['DS','FXS']
path = "Transcripts{dirsep}*{diagnosis}{dirsep}*.txt".format(dirsep=os.sep, diagnosis=diagnoses)

However, the following raises an error:

path = os.path.join('Transcripts',diagnoses,'*.txt')

Can I use os.path.join to get multiple paths?

2 Answers 2

3

If what you are looking for is to use os.path.join to create the output

Transcripts/*['DS', 'FXS']/*.txt

you could simply cast your diagnoses list to a string like so.

os.path.join('Transcripts', '*'+str(diagnoses), '*.txt')
Sign up to request clarification or add additional context in comments.

Comments

2

You would have to use some kind of iteration, like this list comprehension:

>>> paths = [os.path.join('Transcripts', diagnose, '*.txt') for diagnose in diagnoses]
>>> paths
['Transcripts\\DS\\*.txt', 'Transcripts\\FXS\\*.txt']

4 Comments

Thanks. The first one does work, though, and the * works.
I'm not sure it's answered, as this doesn't address the fact that what I have in the first example works and the * operator works
If what you are looking for is to use os.path.join to create "Transcripts/*['DS', 'FXS']/*.txt", you could simply cast your diagnoses list to a string. os.path.join('Transcripts', '*'+str(diagnoses), '*.txt')
That is exactly what I'm looking for. Thanks! Could you make it into an answer?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.