4 # updated 2005.07.21, thanks to Jacob Oscarson
5 # updated 2006.03.30, thanks to Mark Eichin
6 # → http://code.activestate.com/recipes/437932-pyline-a-grep-like-sed-like-command-line-tool/
12 # parse options for module imports
13 opts
, args
= getopt
.getopt(sys
.argv
[1:], 'm:')
16 for imp
in opts
['-m'].split(','):
17 locals()[imp
] = __import__(imp
.strip())
23 codeobj
= compile(cmd
, 'command', 'eval')
24 write
= sys
.stdout
.write
26 for numz
, line
in enumerate(sys
.stdin
):
29 words
= [w
for w
in line
.strip().split(' ') if len(w
)]
30 result
= eval(codeobj
, globals(), locals())
31 if result
is None or result
is False:
33 elif isinstance(result
, list) or isinstance(result
, tuple):
34 result
= ' '.join(map(str, result
))
38 if not result
.endswith('\n'):