PyGolf is a python code shortener.
PyGolf takes a valid python code as input and outputs an equivalent code with fewer characters.
You can find examples of reduced code in the folder code_example. These examples mainly come from CodinGame's Clash of Code game.
You can install this project directly from pypi with pip install pygolf
You can call it using either pygolf
or python -m pygolf
.
You can:
- Give some code with
-c
,pygolf -c "print( 2 )"
- Give an input and output file,
pygolf -i input_file -o output_file
- Shorten code in clipboard with
pygolf -cb
(usefull while doing a clash of code)
To modify the clipboard, pygolf
requires pyperclip. You might have some issues such as Could not find a copy/paste mechanism for your system
. If so, refer to pyperclip guidelines.
PyGolf
uses astroid to parse and apply transformations on the abstract syntax tree (AST).
PyGolf
parses and unparses the AST several times through phases. Each phase comes with rules.
If you want to contribute, please refer to the CONTRIBUTING.md file.