On Tue, Jan 10, 2012 at 11:24 PM, Dave Angel <d...@davea.name> wrote: > On 01/10/2012 04:53 PM, Hugo Arts wrote: >> >> 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'd want to do one of three things there: > > 1) use forward slashes > "C:/Users/hugo/Desktop/file.txt" > which Windows will use happily for nearly every purpose. > > 2) use raw strings > > r"C:\Users\hugo\Desktop\file.txt" > > 3) or escape the backslashes: > > "C:\\Users\\hugo\\Desktop\\file.txt" >
whoops. think before you type. Thanks for the correction _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor