Re: Bash-like brace expansion

2009-08-24 Thread John Haxby
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

Re: Bash-like brace expansion

2009-03-26 Thread Peter Waller
On Mar 24, 5:39 pm, Peter Waller peter.wal...@gmail.com wrote: I've since heard that a 'better way' would be to use pyparsing. Also, I saw that python has dropped the idea of having recursive regular expressions at the moment. I've written a pyparsing parser which is very much shorter and

Bash-like brace expansion

2009-03-24 Thread Peter Waller
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. #~ BraceExpand.py

Re: Bash-like brace expansion

2009-03-24 Thread Peter Waller
Okay, yuck. I didn't realise that posting would mangle the code so badly. Is there any better way to attach code? I'm using google groups. On Mar 24, 12:28 pm, Peter Waller peter.wal...@gmail.com wrote: Okay, I got fed up with there not being any (obvious) good examples of how to do bash-like

Re: Bash-like brace expansion

2009-03-24 Thread bearophileHUGS
Peter Waller: Is there any better way to attach code? This is a widely used place (but read the contract/disclaimer first): http://code.activestate.com/recipes/langs/python/ Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Bash-like brace expansion

2009-03-24 Thread Peter Waller
2009/3/24 Tino Wildenhain t...@living-examples.com The simple {foo} expansion you mention should be quite easily handled with re.sub and a function as argument. So not much more then a few lines of code. Could this approach be made to handle recursive expansion? From the example with the

Re: Bash-like brace expansion

2009-03-24 Thread Peter Waller
What one really wants is a re option capable of handling recursive structures, something along the lines of what PHP has: http://uk2.php.net/manual/en/regexp.reference.php Under the 'Recursive Patterns' heading. As far as I am aware, no such thing exists for Python (yet?). 2009/3/24 Peter

Re: Bash-like brace expansion

2009-03-24 Thread Tino Wildenhain
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

Re: Bash-like brace expansion

2009-03-24 Thread Ben Finney
Peter Waller peter.wal...@gmail.com writes: Okay, yuck. I didn't realise that posting would mangle the code so badly. Is there any better way to attach code? Yes: Use a news client other than Google Groups. I'm using google groups. Fix that, first. -- \ “Are you pondering what I'm

Re: Bash-like brace expansion

2009-03-24 Thread Nick Craig-Wood
Peter Waller peter.wal...@gmail.com 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! Interesting! Might I suggest some unit tests? You can then test all

Re: Bash-like brace expansion

2009-03-24 Thread Peter Waller
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! Interesting! Might I suggest some unit tests?  You can then test all the corner cases (unmatched brackets, empty brackets, etc

Re: Bash-like brace expansion

2009-03-24 Thread Paul McGuire
On Mar 24, 12:39 pm, Peter Waller peter.wal...@gmail.com wrote: Maybe I might re-implement this with pyparsing and some unit tests. In your pyparsing efforts, you might draw some insights from this regex inverter (that is, given an re such as [AB]\d, returns A0 through B9) on the pyparsing