Creating files from code
Is there a way to create a file from code? I've tried using a python script:
then:
but I have been getting this error:
4 Replies
You can use the
open()
function in a context manager in Mojo the same way you would in python, there's no need to interop any python code for this.
However, I don't think Mojo supports opening a file in "x" mode yet, so you'll need to ensure that the file doesn't already exist manuallyThat's the problem, I want to literally create a file
"w" mode also creates the file
The only difference from "x" mode is that it will overwrite an existing file with the same name (if it's there) instead of throwing an exception
Huh, really?
I'm going to have to try that when I get home
Yep, that works well
honestly i'm surprised i didn't think of this earlier