I want to write the text (which I get from AJAX) to a file, and then read it.
+1
A:
f = open( 'filename.txt', 'w+' )
f.write( 'text' )
f.close()
f = open( 'filename.txt', 'r' )
for line in f:
print( line )
f.close()
poke
2010-03-22 09:52:07
A:
The following code for read the content from a file
handle=open('file','r+')
var=handle.read();
print var;
If you want to read a single line use the readline(). If you want to read the whole lines in the file use the readlines() also
The following code for write the content to the files
handle1=open('file.txt','r+')
handle1.write("I AM NEW FILE")
handle1.close();
muruga
2010-03-22 09:53:17
+1
A:
If you can use this in Django view... try somethink like this:
def some_view(request):
text = request.POST.get("text", None)
if text is not None:
f = open( 'some_file.txt', 'w+')
f.write(text)
f.close()
return HttpResponse()
Dingo
2010-03-22 09:59:16