Balderdash
Balderdash
MModular
Created by bhavnicksm on 9/17/2023 in #questions
How do I open files to read/write in Mojo?
When you call a function, which throws an exception you need either to catch and handle it or define in your function by using key 'raises' its given to its caller to handle it.
30 replies
MModular
Created by bhavnicksm on 9/17/2023 in #questions
How do I open files to read/write in Mojo?
It's a working example .. you may add raises to your main function ?
30 replies
MModular
Created by bhavnicksm on 9/17/2023 in #questions
How do I open files to read/write in Mojo?
from pathlib.path import cwd
from pathlib.path import Path

from python import Python

fn main() raises:
let currentPath = cwd()
let file = currentPath/"my_file.txt"

with open(file, "w") as f:
f.write("Hello, world!")

with open(file, "r") as f:
print(f.read())

let os = Python.import_module("os")
os.remove(file.path)
from pathlib.path import cwd
from pathlib.path import Path

from python import Python

fn main() raises:
let currentPath = cwd()
let file = currentPath/"my_file.txt"

with open(file, "w") as f:
f.write("Hello, world!")

with open(file, "r") as f:
print(f.read())

let os = Python.import_module("os")
os.remove(file.path)
30 replies
MModular
Created by Three chickens in the green bag on 9/19/2023 in #questions
GitHub Actions/Runner - Mojo
Nice 👍
7 replies
MModular
Created by Three chickens in the green bag on 9/19/2023 in #questions
GitHub Actions/Runner - Mojo
Maybe you can try it without the export. Just echo 'key="value"' >> $GITHUB_PATH echo 'MODULAR_HOME="/home/runner/.modular"' >> $GITHUB_PATH echo 'PATH="/home/runner/.modular/pkg/packages.modular.com_mojo/bin:$PATH"' >> $GITHUB_PATH
7 replies
MModular
Created by msthil2 on 9/12/2023 in #questions
Mojo Install Hanging in Codespaces
Had the same issue. I interrupted installer (by pressing CTRL+C) and setup env variables ... echo 'export MODULAR_HOME="$HOME/.modular"' >> ~/.bashrc echo 'export PATH="$MODULAR_HOME/pkg/packages.modular.com_mojo/bin:$PATH"' >> ~/.bashrc source ~/.bashrc and after that i could run mojo.
5 replies