On Tue, Jan 10, 2012 at 8:31 PM, Adrian <kellyadr...@hotmail.com> wrote: > Hi guys, > I know that if i dont include any path information, python looks in the > current directory for the file. My question is how do i specify a file path > to open a file saved on my desktop for example. > > Thanks all > > Adrian >
Just write the path like you would anywhere else, there is nothing special about how python handles this. # this is where my desktop is located on my windows 7 machine, but it differs per operating system of course f = open("C:\Users\hugo\Desktop\file.txt", 'r') # you can also use relative paths, like "two directories up from the current and then into the media directory" # forward slashes here, that's what they use on essentially everything that isn't windows f = open("../../media/file.txt", 'r') if you want to be cross-platform, you should take a look at the os.path module. HTH, Hugo _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor