[Tutor] Problems with changing directory.

Kent Johnson kent_johnson at skillsoft.com
Sun Aug 22 18:18:41 CEST 2004


Until you get this working it might be better to omit the try block 
completely. Then an exception will give you a stack trace and a precise 
error message. If you don't understand the error message, post it here and 
we will help. Once you have it working you can add in try blocks that catch 
specific, expected errors and handle them in a user-friendly way.

Also, you can test specifically to see if a path exists using os.path.exists().

Kent

At 03:45 PM 8/22/2004 +0100, David Holland wrote:

>As part of my studies in my python I have been trying
>to write a program that will go to a directory and
>search all the files :-
>This is the code :-
>
>def change_dir():
>     y = '/home/david/Documents/pyprogamming/test/'
>     try:
>         os.chdir(y)
>         print "line 53"
>         list_of_files = os.listdir(y)
>         print "line 55"
>         for file in list_of_files:
>             print "line 57"
>             linesone = open_files(file)
>             getlineinfo(linesone)
>             print file
>         print "Directory", y,"does exist"
>     except:
>         print y, "does not exist"
>
>
>However despite the fact that :-
>a) I have imported os
>b) The directory exists
>I get the message :-
>'/home/david/Documents/pyprogamming/test/ does not
>exist'
>However it does ?
>Can any one help ?
>
>
>
>
>
>___________________________________________________________ALL-NEW Yahoo! 
>Messenger - all new features - even more fun!  http://uk.messenger.yahoo.com
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list