https://github.com/sammi-turner/python-to-mojo
Python code snippets with their Mojo equivalents.
https://github.com/sammi-turner/python-to-mojo
mojo mojolang python3
Last synced: 5 months ago
JSON representation
Python code snippets with their Mojo equivalents.
- Host: GitHub
- URL: https://github.com/sammi-turner/python-to-mojo
- Owner: sammi-turner
- License: mit
- Created: 2023-09-29T23:30:55.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-11-17T22:03:30.000Z (over 1 year ago)
- Last Synced: 2025-10-19T20:42:26.922Z (9 months ago)
- Topics: mojo, mojolang, python3
- Language: Mojo
- Homepage:
- Size: 278 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Python To Mojo
Python code snippets with their Mojo equivalents.
## Mojo Playground
A Mojo programming environment is available from the Mojo product [page](https://www.modular.com/mojo).
## 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.
```sh
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.
```sh
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](https://youtu.be/KYEAiTBbNT8?si=_jTQnoe3cj3ViLYB).
## Shell aliases
To save time building and running my Mojo code, I have added some aliases to my .bashrc file.
```sh
# 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.
```