Forum: Poser Python Scripting


Subject: How do I write to a file?

Anthony Appleyard opened this issue on Jul 17, 2021 ยท 9 posts


adp001 posted Sat, 14 August 2021 at 8:08 AM

structure posted at 8:02AM Sat, 14 August 2021 - #4425190

AFAIK it is not necessay in P3 - I will run tests as soon as I am able.

This is only true for files open for reading. And even then it is simply good practice to wrap file access in:

with open(filename, mode) as filehandle:
    for line in filehandle:
        print(line)
        ...
        print("teststring", file=filehandle)

Read the docs if you need to know why. Your own test may only cover a fraction of the wisdom found in the Python documentation :)