•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Python section within the Software Development category of DaniWeb, a massive community of 402,750 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,442 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Python advertiser: Programming Forums
Views: 2863 | Replies: 3
![]() |
•
•
Join Date: May 2005
Posts: 8
Reputation:
Rep Power: 0
Solved Threads: 0
Hey there, i need some help with a simple cgi script.
i cannot get it to write output to a file.
here is the script.
it works, in that it returns the correct info to the browser,
but it does not write a text file.
i need to be able with this script to store on my disk what is input
in the html form.
any suggestions ?
Edit/Delete Message
i cannot get it to write output to a file.
here is the script.
#!/usr/bin/python
import cgi
form = cgi.FieldStorage()
Customer = form['Customer'].value
Field = form['Field'].value
data = [Customer, Field]
reshtml = """Content-Type: text/html\n
<html>
<head><title>Customer Data</title></head>
<body>
<h1>Customer Data</h1>
<p>Here ya go</p>
</body>
</html>"""
print reshtml + 'Customer =' + data[0]
print ' ' + ' Field = ' + data[1]
# this is where the script fails to do anything....
OutFile = open("/home/nephish/Test.txt", "w")
OutFile.write("Here is a spot of text to input")
OutFile.close
it works, in that it returns the correct info to the browser,
but it does not write a text file.
i need to be able with this script to store on my disk what is input
in the html form.
any suggestions ?
Edit/Delete Message
•
•
Join Date: Oct 2004
Location: Mojave Desert
Posts: 2,425
Reputation:
Rep Power: 9
Solved Threads: 173
I ran a quick test and on my Windows XP Box it seems to be the file path it balks at. I had to give it the full file path (or at least back to where python.exe sits)
[php]
try:
# needs full file path!
OutFile = open("/home/nephish/Test.txt", "w")
OutFile.write("Here is a spot of text to input")
OutFile.close()
print "File successfully written"
except IOError:
print "Cannot open file for writing"
[/php]
[php]
try:
# needs full file path!
OutFile = open("/home/nephish/Test.txt", "w")
OutFile.write("Here is a spot of text to input")
OutFile.close()
print "File successfully written"
except IOError:
print "Cannot open file for writing"
[/php]
May 'the Google' be with you!
![]() |
•
•
•
•
•
•
•
•
DaniWeb Python Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- CGI script gathering browser info (C++)
- Formmail cgi script (Perl)
- guestbook cgi script won't return reply page???? (Perl)
- My CGI Script gives me this error...What am I missing? (Perl)
Other Threads in the Python Forum
- Previous Thread: python power
- Next Thread: how do i read the last line of a text file?



Linear Mode