On Wed, 6 Jul 2005, Michael Huster wrote:
> 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'. Hi Michael, One issue that might be relevant is that it appears you're asking Python to open a file in read mode ('r'). Are you sure that you don't meant to open a file in write mode ('w') instead? > 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') For the problem that you're running into now, it does seem like you need to open the file in write mode to get it to create new files. Next time, it might be helpful to show how they don't work. What kind of error message do you see when you execute those statements? The reason we ask this is because, in some cases, an error has less to do with what you're doing, and more with an external situation outside of Python. One general principle for error reporting is to make sure to provide enough information that someone else can try it, and enough output that we know that the person will recognize that they're seeing the same error that you're seeing. It also helps because if we see an error message, we can also help explain what the error message means. That way, next time you see a similar error message, you have a better chance to understand what the silly system is really trying to say. *grin* Best of wishes to you! _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor