Creating Python class wrapper for a command line tool

Edvard Majakari edvard+news at majakari.net
Wed May 26 14:29:47 EDT 2004


Rico Huijbers <E.A.M.Huijbers at REMOVEstudent.tue.nl> writes:

> I am by no means a professional Pythonist... but it doesn't seem too bad
> to me to check for each kwarg whether it's type is boolean and if so, just
> add it to the command line as a flag instead of as a value parameter. And
> data arguments can be passed in the *args tuple.

Wow - I had to test it and didn't work. Then I remembered it would
probably work with Python2.3, and it did. But the thingamajick must work
with Python2.2.

> obj = Wrapper("MUNGE1:x1:y:z:frob1", "MUNGE2:x2:y:z:frob2",
> "MUNGE3:x3:y:z:frob3", optimize=True, use_bar=foo, threshold=10,
> name="Alley cat")
>
> This just wraps everything in the constructor. Alternatively, you could go
> for setting each command-line parameter via a method flag.

Yes - well, command line options are not necessary a must, so I thought to
separate those from data (which *is* compulsory for the thing to work).

> Combining the two methods seems ugly to me, though.

I admit, it is not as pretty. But the command I'm using takes lots and
lots of parameters, flags etc. and one reason in having a Python interface
is to avoid very long parameter lists (if constructor is not given any
keyword arguments, some sane defaults are assumed for them).

But thanks for the follow-up!

-- 
#!/usr/bin/perl -w
$h={23,69,28,'6e',2,64,3,76,7,20,13,61,8,'4d',24,73,10,'6a',12,'6b',21,68,14,
72,16,'2c',17,20,9,61,11,61,25,74,4,61,1,45,29,20,5,72,18,61,15,69,20,43,26,
69,19,20,6,64,27,61,22,72};$_=join'',map{chr hex $h->{$_}}sort{$a<=>$b}
keys%$h;m/(\w).*\s(\w+)/x;$_.=uc substr(crypt(join('',60,28,14,49),join'',
map{lc}($1,substr $2,4,1)),2,4)."\n"; print;



More information about the Python-list mailing list