| 1 |
#!/usr/bin/env python |
| 2 |
|
| 3 |
from __future__ import print_function, division, absolute_import |
| 4 |
import sys |
| 5 |
import os |
| 6 |
import os.path |
| 7 |
import glob |
| 8 |
from optparse import OptionParser |
| 9 |
|
| 10 |
from petl import __version__ |
| 11 |
from petl import * |
| 12 |
|
| 13 |
parser = OptionParser( |
| 14 |
usage="%prog [options] expression", |
| 15 |
description="Evaluate a Python expression. The expression will be " |
| 16 |
"evaluated using eval(), with petl functions imported.", |
| 17 |
version=__version__) |
| 18 |
|
| 19 |
options, args = parser.parse_args() |
| 20 |
|
| 21 |
try: |
| 22 |
(expression,) = args |
| 23 |
except ValueError: |
| 24 |
parser.error("invalid number of arguments (%s)" % len(args)) |
| 25 |
r = eval(expression) |
| 26 |
|
| 27 |
if r is not None: |
| 28 |
if isinstance(r, Table): |
| 29 |
print(look(r)) |
| 30 |
else: |
| 31 |
print(str(r)) |