Re: 'indent'ing Python in windows bat

Discussion in 'Python' started by Ian Kelly, Sep 18, 2012.

  1. Ian Kelly

    Ian Kelly Guest

    On Mon, Sep 17, 2012 at 7:08 PM, David Smith <> wrote:
    > 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)


    How about:

    if sR == 'Cope':
    sys.exit(1)
    elif sR == 'Perform':
    sys.exit(2)
    else:
    sys.exit(3)

    I don't really understand why you're trying to keep it all on one line.
     
    Ian Kelly, Sep 18, 2012
    #1
    1. Advertisements

  2. Ian Kelly

    Roy Smith Guest

    In article <>,
    Ian Kelly <> wrote:

    > On Mon, Sep 17, 2012 at 7:08 PM, David Smith <> wrote:
    > > 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)

    >
    > How about:
    >
    > if sR == 'Cope':
    > sys.exit(1)
    > elif sR == 'Perform':
    > sys.exit(2)
    > else:
    > sys.exit(3)
    >
    > I don't really understand why you're trying to keep it all on one line.


    sys.exit({'Cope':1, 'Perform':2}.get(sR, 3))
     
    Roy Smith, Sep 18, 2012
    #2
    1. Advertisements

  3. Ian Kelly

    Hans Mulder Guest

    On 18/09/12 05:01:14, Ian Kelly wrote:
    > On Mon, Sep 17, 2012 at 7:08 PM, David Smith <> wrote:
    >> 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)

    >
    > How about:
    >
    > if sR == 'Cope':
    > sys.exit(1)
    > elif sR == 'Perform':
    > sys.exit(2)
    > else:
    > sys.exit(3)
    >
    > I don't really understand why you're trying to keep it all on one line.


    He's using Windows.

    If he were on Unix, there'd be no problem:

    python -c 'import sys
    if sR == "Cope":
    sys.exit(1)
    elif sR == "Perform":
    sys.exit(2)
    else:
    sys.exit(3) '

    Unfortunately, the Windows shell doesn't do multi-line strings,
    so he has to cram it all on one line.


    -- HansM
     
    Hans Mulder, Sep 19, 2012
    #3
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Grant Merwitz
    Replies:
    3
    Views:
    9,314
    Grant Merwitz
    Sep 15, 2005
  2. Tom Willis

    windows bat file question

    Tom Willis, Mar 1, 2005, in forum: Python
    Replies:
    11
    Views:
    1,700
    Peter Hansen
    Mar 5, 2005
  3. dt
    Replies:
    4
    Views:
    757
    CBFalconer
    Dec 31, 2006
  4. Joe
    Replies:
    1
    Views:
    434
    Victor Bazarov
    May 22, 2007
  5. Gelonida N
    Replies:
    3
    Views:
    2,667
    Gelonida N
    Aug 11, 2011
  6. David Smith

    'indent'ing Python in windows bat

    David Smith, Sep 18, 2012, in forum: Python
    Replies:
    0
    Views:
    218
    David Smith
    Sep 18, 2012
  7. David Smith

    Re: 'indent'ing Python in windows bat

    David Smith, Sep 18, 2012, in forum: Python
    Replies:
    3
    Views:
    330
    David Smith
    Sep 19, 2012
  8. Albert Hopkins

    Re: 'indent'ing Python in windows bat

    Albert Hopkins, Sep 19, 2012, in forum: Python
    Replies:
    1
    Views:
    239
    Hans Mulder
    Sep 19, 2012
Loading...