'indent'ing Python in windows bat

Tim Roberts timr at probo.com
Mon Sep 17 23:59:44 EDT 2012


David Smith <davids at invtools.com> wrote:
>
>I'm converting windows bat files little by little to Python 3 as I find 
>time and learn Python.
>The most efficient method for some lines is to call Python like:
>python -c "import sys; sys.exit(3)"
>
>How do I "indent" if I have something like:
>if (sR=='Cope'): sys.exit(1) elif (sR=='Perform') sys.exit(2) else 
>sys.exit(3)
>
>My sole result in many attempts is "Syntax Error."

The other responses asking "why" are excellent, but this will do that
specific job:

    sys.exit( {'Cope':1,'Perform':2}.get(sR,3) )

The best way to convert a batch file to Python is to convert the whole file
to a Python script.
-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the Python-list mailing list