Python library to generate and execute code dynamically
Project description
codeg
Codeg (code generator) is a python library that allows you to generate python code dynamically.
This library is still a work in progress
Quickstart
Let's say you want to generate the following class dynamically
class Animal:
def __init__(name: str):
self.name = name
You can use the following code
import codeg
code_cls = codeg.cls("Animal")
code__init = code_cls.method(
"__init__", attributes=[codeg.Attribute("name", annotation=str)]
)
code__init.line("self.name = name")
code_cls.print() # print the generated code
Animal = code_cls.build() # eval the code and get it on a variable
animal = Animal("rex")
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
codeg-0.2.0.tar.gz
(9.5 kB
view hashes)
Built Distribution
codeg-0.2.0-py3-none-any.whl
(15.8 kB
view hashes)