Text File

Simon Faulkner News at Titanic.co.uk
Thu Jan 13 02:21:26 EST 2000


Magic,

I am sure this will get me finished.

Now,  if you will come over and predict next weeks Lotto numbers my
life will be perfect!

Cheers

Simon


On 13 Jan 2000 00:32:27 +0100, mlh at vier.idi.ntnu.no (Magnus L.
Hetland) wrote:

>Simon Faulkner <news at titanic.co.uk> writes:
>
>> Hi All,
>> 
>> I would like to write a CGI program that diskplays a small (<1k) text
>> file on a web page and saves any changes made by the browser back to
>> the same file.
>> 
>> Any sugestions to help me get started?
>> 
>> Specifically
>> 
>> Which data type should I use and how do I read the text  file into
>> it?
>
>Just do:
>
>  file = open("filename.txt")
>  text = file.read()
>  file.close()
>
>And there it is - as a string. Put that into a text-area in your HTML
>output for the user to edit. When you get the result, you'll probably
>get it in a manner similar to this:
>
>  data = FieldStorage()
>  text = data["text"].value()
>
>  file = open("filename.txt","w")
>  file.write(text)
>  file.close()
>
>And there you are. Now all you need to do is build the CGI stuff and
>HTML around it :)
>
>> 
>> Cheers  
>> 
>> 
>> Simon
>> 

Simon Faulkner



More information about the Python-list mailing list