How to create/read/write to/from a file in Mojo

from os import remove

def main():
    name = "some_file.txt"

    with open(name, "w") as f:
        f.write("new contents 🔥")

    with open(name, "r") as f:
        contents = f.read()
        print(contents)
    
    remove(name)
3 Likes

Well, yea… So, literally the same as in python?)

Useful for Advent of Code 2024 :slight_smile:

1 Like