safetyduck
safetyduck

Reputation: 6844

expand shell path expression in python

path = 'foo/{bar1,bar2}'

How to expand to ['foo/bar1', 'foo/bar2'] as the bash shell would? I've tried glob, os.path.realpath and I don't see anything in shutil either.

Upvotes: 1

Views: 867

Answers (2)

Glenn
Glenn

Reputation: 5776

You could get bash to do it for you ;)

paths = subprocess.check_output('bash -c "echo foo/{bar1,bar2}"', shell=True).split()

Upvotes: 2

nosklo
nosklo

Reputation: 222812

There's no builtin way to do that. You'd need to write some parsing code to extract the elements.

Upvotes: 0

Related Questions