[Pythonmac-SIG] Writing

JoanCarles Casasín joanca@typerware.com
Thu, 01 Feb 2001 18:12:51 +0200


On 1/2/01 00:12, "mark brady" <brady@mmm.com> wrote:

> I am attempting to write text to a file.  I've opened the file  (I think)
> using macfs StandardPutFile.  Here are my questions: Does this
> actually open a file?  What method can the FSSpec file use to actually
> write?  write() doesn't seem to work.

Try this:

import macfs

def writestuff(stuff):
        f, ok = macfs.StandardPutFile("Save text as:", ".txt")
        if ok:
            filedata = open(f.as_pathname(), "w")
            filedata.write(stuff)
            filedata.close()

writestuff("The stuff you want to write")

[:]  jc, tw®