How to break a loop when inputting unspecified raw_input?

Posted by user1874510 on Stack Overflow See other posts from Stack Overflow or by user1874510
Published on 2012-12-04T04:42:38Z Indexed on 2012/12/04 5:04 UTC
Read the original article Hit count: 127

Filed under:
|
|

I want to write an interface using a while loop and raw_input.

My code looks like this:

while True:
    n = raw_input("'p' = pause, 'u' = unpause, 'p' = play 's' = stop, 'q' = quit)
    if n.strip() == 'p':
        mp3.pause()
    if n.strip() == 'u':
        mp3.unpause()
    if n.strip() == 'p':
        mp3.play()
    if n.strip() == 's':
        mp3.stop()
    if n.strip() == 'q':
        break

But I want it to break if I input anything that isn't specified in the raw_input.

    if not raw_input:
        break

Returns and IndentationError: unindent does not match any outer indentation level.

        if not raw_input:
            break

Does not return any error but doesn't work as I want it to. As far as I know, it does nothing at all.

Also, if there's a cleaner way to write my loop, I love to hear it.

© Stack Overflow or respective owner

Related posts about python

Related posts about while-loop