1 Replies - 4665 Views - Last Post: 13 August 2009 - 05:18 AM Rate Topic: -----

#1 Solris  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 09-November 08

create a file on desktop

Post icon  Posted 12 August 2009 - 10:40 PM

Hi all,


Need help. At the moment been trying to create a file, but I want to know how I can have the file created in a specific location. for example, I tried to create a text file on my desktop, but when i excute the code, nothing happens. can someone help?

filename = ("C:/Users/Solris/Desktop","test.txt")



what am i doing wrong? do i need to imprt a module or somthing?

Is This A Good Question/Topic? 0
  • +

Replies To: create a file on desktop

#2 Nallo  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 161
  • View blog
  • Posts: 247
  • Joined: 19-July 09

Re: create a file on desktop

Posted 13 August 2009 - 05:18 AM

You must tell the python interpreter, that you want to open a file for writing (if it doesnt exist python will create it).
The python command for opening a file is open. So:
filehandler = open("C:/Users/Solris/Desktop/test.txt", "w")
filehandler.close()


This will create an empty file test.txt in C:/Users/Solris/Desktop.

For more about handling files in python you might want to read the documentation on python.org:
http://docs.python.o...d-writing-files

This post has been edited by Nallo: 13 August 2009 - 05:20 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1