In ipython (0.10.2), I'd like to run with bash shell style (or glob.glob) expansion. I'd like to do something like these and have the arguments expand out just as they would if I were in bash. Is this possible?
filenames = !ls *.sbet
run sbet.py $filenames
# fails because filenames is a list
# or the simpler case:
run sbet.py *.sbet
# failes with "*.sbet" being directly passed in without being expanded.
Suggestions? Thanks!
The return of filenames = !ls *.sbet
is a special list, with a few extra attributes:
filenames.l
- the listfilenames.s
- a whitespace-separated stringfilenames.n
- a newline-separated stringdo filenames?
in IPython for more info.
So to pass the args to run, you want filenames.s
:
filenames = !ls *.sbet
run sbet.py $filenames.s
If you have a regular list, then you will need to turn it into a string yourself, before passing to run:
filenames = glob.glob('*.sbet')
filenames_str = ' '.join(filenames) # you will need to add quotes if you allow spaces in filenames
run sbet.py $filenames_str
You might make a feature request for automatic expansion of file globs when passed to %run
if run foo.py *.sbet
is valuable to you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With