ModularM
Modular16mo ago
9 replies
banananas

Creating files from code

Is there a way to create a file from code? I've tried using a python script:
def create_proj(path: str):
    with open(path + "/main.mojo", "x") as f:
        f.write("text goes here")

then:
from python import *

fn create_proj(folder: String) raises:
    Python.add_to_path(".")
    var file = Python.import_module("createproj")
    file.create_proj(folder)

but I have been getting this error:
Unhandled exception caught during execution: module 'createproj' has no attribute 'create_proj'
/home/[USERNAME]/pyregl/.magic/envs/default/bin/mojo: error: execution exited with a non-zero result: 1
Was this page helpful?