how to improve simple python shell script (to compile list of files)

Jari Aalto jari.aalto at cante.net
Sat Oct 15 14:40:00 EDT 2005


"Chris F.A. Johnson" <cfajohnson at gmail.com> writes:

> On 2005-10-15, Jari Aalto wrote:
>    Don't indent:
>
> function compile ()
> {
>          python -c '
> import os, sys, py_compile;
> i = 0;
> for arg in sys.argv:
>       file  = os.path.basename(arg);
>       dir   = os.path.dirname(arg);
>       i += 1;
>       if i > 1  and os.path.exists(dir):
>           os.chdir(dir);
>           print "compiling %s\n" % (file);
>           py_compile.compile(file);
>   '  $*
> }

Thanks, is there equivalent to this Perl statement in Python?

   @list = @ARGV[1 .. @ARGV];

or something similar so that I could avoid the 1 > 1 (sys.argv) check
altogether?

Jari




More information about the Python-list mailing list