raw_input

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marcello Pietrobon

    raw_input

    Hello,
    even if I learned something about Python,
    still I don't know how to do ask the input from a user on the command line

    This is my ( not working ) code:
    if ( not os.path.exists( dirname) ):
    msg = 'The directory \'%s\' does not exist. Create it [y/n]
    ?' % dirname
    c = raw_input( msg ).lower
    if ( c == 'y' or c == 'yes' ):
    os.makedirs( dirname)
    else:
    raise Exception( 'directory \'%s\' not created,
    impossible to continue !' % dirname )


    Thank you for any answers,
    Marcello



  • rzed

    #2
    Re: raw_input

    Marcello Pietrobon <teiffel@attglo bal.net> wrote in
    news:mailman.77 9.1082425126.20 120.python-list@python.org :
    [color=blue]
    > if ( not os.path.exists( dirname) ):
    > msg = 'The directory \'%s\' does not exist. Create
    > it [y/n]
    > ?' % dirname
    > c = raw_input( msg ).lower
    > if ( c == 'y' or c == 'yes' ):
    > os.makedirs( dirname)
    > else:
    > raise Exception( 'directory \'%s\' not created,
    > impossible to continue !' % dirname )
    >
    >[/color]

    1. lower()(not lower) invokes the method
    2. with that change, this code works as expected when I run it form a
    win2k command line, from an interactive session, or from Idle.

    --
    rzed

    Comment

    Working...