raw_input

M

Marcello Pietrobon

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
 
R

rzed

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 )

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top