tags:

views:

40

answers:

1

For a Bash completion script I need to get all the variables from an installed Python module that match a pattern. I want to use only Python-aware functionality, to avoid having to parse comments and such.

+3  A: 

You can use python -c to execute a one-line Python script if you want. For example:

bash$  python -c "import os; print dir(os)"

If you want to filter by a pattern, you could do:

bash$  python -c "import os; print [x for x in dir(os) if x.startswith('r')]"
['read', 'readlink', 'remove', 'removedirs', 'rename', 'renames', 'rmdir']
Daniel DiPaolo
Thank you, that was just the thing! The resulting code: `python -c "import invenio.config; print dir(invenio.config)" | tr -s "', '" "\n" | grep ^CFG_`
l0b0