[Tutor] (no subject)

Light light_zls at 163.com
Wed Jul 6 17:52:44 CEST 2005


You could use this:

import os
fp = open(os.path.expanduser('~')+r'\Desktop\myFile', 'r')

Light


> In python under windows, how can I create and access a file on the
> Desktop? The following do NOT work: fp = open(r'Desktop\myFile','r')
> fp = open(r'\Desktop\myFile','r')
> fp = open(r'c:\Desktop\myFile','r')
> fp = open(r'c:\Windows\Desktop\myFile','r')
>
> I don't want to drill into c:\Documents and Setting\... because the
> user name is often obscure AND not all desktop files appear in the
> same subdir. of that. For example some are in 'All Users" or 'Default
> User'.
>
> Michael Huster,
> Simpson University
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list