943,862 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 451
  • Python RSS
Jan 23rd, 2009
0

writing to a file

Expand Post »
I am trying to write some simple information to a file and i am getting the error message "No such file or directory when i know full well it exists. If you take the url http://www.adamplowman.com/uni_project/log.txt you get the file

heres the code

Python Syntax (Toggle Plain Text)
  1. #!/usr/bin/python
  2.  
  3. print "Creating a text file with the write() method."
  4. text_file = open("http://www.adamplowman.com/uni_project/log.txt", "w")
  5. text_file.write("Line 1\n")
  6. text_file.write("This is line 2\n")
  7. text_file.write("That makes this line 3\n")
  8. text_file.close()
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
adam291086 is offline Offline
61 posts
since Nov 2008
Jan 23rd, 2009
0

Re: writing to a file

It's because the builtin function open can only open a file in your filesystem and not an url. If you want to rewrite a file in your website, you should first write a file in your local file system and then use ftp or some other protocol to copy the file to your website.
Reputation Points: 930
Solved Threads: 668
Posting Maven
Gribouillis is offline Offline
2,655 posts
since Jul 2008
Jan 23rd, 2009
0

Re: writing to a file

I'm pretty sure the http protocol doesn't allow write access.
Featured Poster
Reputation Points: 975
Solved Threads: 140
Posting Virtuoso
scru is offline Offline
1,624 posts
since Feb 2007
Jan 23rd, 2009
0

Re: writing to a file

mmm i am running this from a website and that file in question is stored within another folder will it work then?
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
adam291086 is offline Offline
61 posts
since Nov 2008
Jan 23rd, 2009
0

Re: writing to a file

It could work if you pass a file path to open, like uni_project/log.txt , but nothing that starts whith http://.
Last edited by Gribouillis; Jan 23rd, 2009 at 9:25 am.
Reputation Points: 930
Solved Threads: 668
Posting Maven
Gribouillis is offline Offline
2,655 posts
since Jul 2008
Jan 23rd, 2009
0

Re: writing to a file

i am struggling with this

so if the file i want to write to is located here
http://www.adamplowman.com/uni_project/log.txt

and my code to write to the file is running from here
http://adamplowman.com/cgi-bin/proje...ing_to_file.py

is this possible?
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
adam291086 is offline Offline
61 posts
since Nov 2008
Jan 23rd, 2009
0

Re: writing to a file

Did you try something like "../uni_project/log.txt" ? Also you could use os.getcwd() in your program to see the path to the current dir. It would help build a relative path to your file.
Last edited by Gribouillis; Jan 23rd, 2009 at 9:55 am.
Reputation Points: 930
Solved Threads: 668
Posting Maven
Gribouillis is offline Offline
2,655 posts
since Jul 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: tkinter
Next Thread in Python Forum Timeline: Two questions: wxpython registerhotkey and os.system





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC