Skip to content

Commit

Permalink
Merge pull request petl-developers#139 from florentx/compat
Browse files Browse the repository at this point in the history
drop dependency on argparse, for compatibility with Python 2.6; issue petl-developers#138
  • Loading branch information
alimanfoo committed Jun 22, 2012
2 parents cfe577a + 4461cf2 commit 81758a2
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions bin/petl
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,27 @@ import sys
import os
import os.path
import glob
import argparse
from optparse import OptionParser

from petl import VERSION
from petl.fluent import *

parser = argparse.ArgumentParser(description="Evaluate a Python command (with petl.fluent functions imported).")
parser.add_argument("expression",
help="any valid Python expression - will be evaluated using eval()")
args = parser.parse_args()
parser = OptionParser(
usage="%prog [options] expression",
description="Evaluate a Python expression. The expression will be "
"evaluated using eval(), with petl.fluent functions imported.",
version=VERSION)

r = eval(args.expression)
options, args = parser.parse_args()

try:
(expression,) = args
except ValueError:
parser.error("invalid number of arguments (%s)" % len(args))
r = eval(expression)

if r is not None:
if isinstance(r, FluentWrapper):
print look(r)
else:
print str(r)

0 comments on commit 81758a2

Please sign in to comment.