tags:

views:

102

answers:

4

I want to write the text (which I get from AJAX) to a file, and then read it.

+4  A: 

The tutorial covers this.

Ignacio Vazquez-Abrams
+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
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
+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