[Tutor] raw_input a directory path
Alan Gauld
alan.gauld at btinternet.com
Thu May 13 01:08:20 CEST 2010
"Spencer Parker" <inthefridge at gmail.com> wrote
> Here is the code:
> http://dpaste.com/hold/193862/
First comment: why are you using print followed by raw_input?
You could put the prompt string inside raw_input - if you need
a new line just put a \n in the prompt string. It will shorten and
clarify the code.
> <http://dpaste.com/hold/193862/>It still isn't working for me. I don't see
> it hitting the first for loop or even the second one. It runs without an
> error at all.
What if you put a print to echo the directory value?
> I am inputing the directory as: \\Documents\ and\
> Settings\\user\\Desktop\\test
I don't think you should need the double \\, Python will do that for
you if its reading from raw_input - the print should confirm that.
os.walk has a return value of a tuple with 3 values not 2.
I'd expect a ValueError there... unless the walk returns nothing
which would be true if the directory was empty - or did not exist?
Again use the print to check the directory is valid.
Try using listdir() on it to see if it can read it.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list