emergent/swarm/evolutionary systems etc

Mickel Grönroos mickel at csc.fi
Fri Apr 2 07:09:45 EST 2004


On Fri, 2 Apr 2004, Peter MacKenzie wrote:

> import sys

You don't need the sys module for file I/O.

> file = 'myfile.txt'
> open(file,'r+b')
> file.write("some string of what you want to write")
> file.close()

"file" is a str object containing the string "myfile.txt". What you need
to do is catch the return value (a file object) of the open() function and
use that for writing:

file = "myfile.txt"
fh = open(file, "r+") ## Do you need "b" (binary) for a text file?
fh.write("something")
fh.close()

Cheers,

/Mickel

--
Mickel Grönroos, application specialist, linguistics, Research support, CSC
PL 405 (Tekniikantie 15 a D), 02101 Espoo, Finland, phone +358-9-4572237
CSC is the Finnish IT center for science, www.csc.fi




More information about the Python-list mailing list