Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #29400 > unrolled thread
| Started by | David Smith <davids@invtools.com> |
|---|---|
| First post | 2012-09-17 21:08 -0400 |
| Last post | 2012-09-17 20:59 -0700 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
'indent'ing Python in windows bat David Smith <davids@invtools.com> - 2012-09-17 21:08 -0400
Re: 'indent'ing Python in windows bat Tim Roberts <timr@probo.com> - 2012-09-17 20:59 -0700
| From | David Smith <davids@invtools.com> |
|---|---|
| Date | 2012-09-17 21:08 -0400 |
| Subject | 'indent'ing Python in windows bat |
| Message-ID | <mailman.851.1347930520.27098.python-list@python.org> |
Hello, I'm essentially a newbie in Python. My problem in searching the archives is not knowing what words to use to ask. 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." Thank you for any help.
[toc] | [next] | [standalone]
| From | Tim Roberts <timr@probo.com> |
|---|---|
| Date | 2012-09-17 20:59 -0700 |
| Message-ID | <67sf58h6gtfl8m044rn25un89ic99ur93n@4ax.com> |
| In reply to | #29400 |
David Smith <davids@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@probo.com
Providenza & Boekelheide, Inc.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web