Python Forum

Full Version: file.write not working properly
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
The best way to do it is with the 'with' statement. You don't need to call the close() method and the file is automatically closed.
with open("cd4.txt", "w") as fhand:
    code...code...code
Ah, I didn't know it could be done that way. I've only been doing python for about 2 months now. I like it.
Pages: 1 2