Mojo module
file
Implements the file based methods.
These are Mojo built-ins, so you don't need to import them.
For example, here's how to read a file:
var f = open("my_file.txt", "r")
print(f.read())
f.close()
var f = open("my_file.txt", "r")
print(f.read())
f.close()
Or use a with
statement to close the file automatically:
with open("my_file.txt", "r") as f:
print(f.read())
with open("my_file.txt", "r") as f:
print(f.read())
Structs
-
FileHandle
: File handle to an opened file.
Functions
-
open
: Opens the file specified by path using the mode provided, returning a FileHandle.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!
😔 What went wrong?