Skip to content

sammi-turner/Python-To-Mojo

Repository files navigation


Python To Mojo

Python code snippets with their Mojo equivalents.


Mojo Playground

A Mojo programming environment is available from the Mojo product page.


Local installation

At the time of writing, Mojo is available for Ubuntu-based linux distros, MacOS (M1 and M2) and WSL2 on Windows.


Environment variables

These are at the end of my .bashrc file on Ubuntu.

export MODULAR_HOME="/home/user/.modular"
export PATH="/home/user/.modular/pkg/packages.modular.com_mojo/bin:$PATH"
export MOJO_PYTHON_LIBRARY="/usr/lib/x86_64-linux-gnu/libpython3.10.so"

These are at the end of my .zshrc file on my M2 Mac.

export MODULAR_HOME="/Users/sammiturner/.modular"
export PATH="/Users/sammiturner/.modular/pkg/packages.modular.com_mojo/bin:$PATH"
export MOJO_PYTHON_LIBRARY="/opt/homebrew/bin/python3"

Editor recommendation

Due to the Mojo ecosystem being in its infancy right now, I recommend using VSCode as your editor, with the Error Lens and Mojo extensions installed.


Shell aliases

To save time building and running my Mojo code, I have added some aliases to my .bashrc file.

# MOJO ALIASES
alias mbr='mojo build app.mojo && ./app'
alias mba='mojo build app.mojo'
alias mra='./app'

AI Code Generation

Large Language Models (LLMs) are only effective for me because I don't trust their output.

I always test the code that they generate!

However, given that Python3 is a mature language that is fairly popular in academia and industry, there is a suprising amount of training data for them to work with.

Once you have generated the code that you want in Python3, manually making the changes required to turn it into valid Mojo code is not so hard.


Learning Python with LLMs

This prompt template is good for learning Python idioms.

What is the idiomatic way to [do the thing you want to do]
in Python3?

Function Generation With LLMs

This prompt template is good for generating Python functions.

Write a [name] function in Python3 that takes
[name the parameters and their types] and returns
a [type] such that [describe what the function does].
Then show me the code.

About

Python code snippets with their Mojo equivalents.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages