Bash-like brace expansion

John Haxby john.haxby at
Mon Aug 24 17:50:11 CEST 2009

Peter Waller wrote:
> Okay, I got fed up with there not being any (obvious) good examples of
> how to do bash-like brace expansion in Python, so I wrote it myself.
> Here it is for all to enjoy!
> If anyone has any better solutions or any other examples of how to do
> this, I'd be glad to hear from them.

That was a little while ago and while I found Peter's BraceExpand was a 
good start it wasn't quite what I wanted.  It's not quite the same as 
bash: for example, BraceExpand("{1,3..5}") gives "1 3 4 5" but bash 
gives "1 3..5" (use "{1,{3..5}}") and bash turns all of "{a..z}", 
"{z..a}, "{10..-10}" into sequences.

My version is a little shorter, mostly because it's heavily recursive so 
it may fail spectacularly on some pathological cases :-)

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
URL: <>

More information about the Python-list mailing list