https://github.com/ericlbuehler/pyo3_smd_example
Example of pyo3_special_method_derive
https://github.com/ericlbuehler/pyo3_smd_example
Last synced: 5 months ago
JSON representation
Example of pyo3_special_method_derive
- Host: GitHub
- URL: https://github.com/ericlbuehler/pyo3_smd_example
- Owner: EricLBuehler
- Created: 2024-06-17T06:22:02.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-06-17T12:41:21.000Z (almost 2 years ago)
- Last Synced: 2025-02-08T22:42:36.485Z (over 1 year ago)
- Language: Python
- Size: 9.77 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Example of [pyo3_special_method_derive](https://crates.io/crates/pyo3_special_method_derive)
This is an example of the pyo3_special_method_derive crate, demonstrating the `__dir__`, `__dict__`, `__str__`/`__repr__`, and `__getattr__` features on structs and enums in both printing and debugging use cases.
## Install
- Install maturin in a virtual env: `pip install maturin[patchelf]`
- Install the example: `matuin develop -r`
## Example
```py
import pyo3_smd_example
person = pyo3_smd_example.Person()
# Person(name="Name here", age=0, address=Address.House(country="Country here", city="City here", street="Street here", street_number=4294967295))
print(person)
# person.__dict__={'address': Address.House(country="Country here", city="City here", street="Street here", street_number=4294967295), 'name': 'Name here', 'age': 0}
print(f"{person.__dict__=}")
# person.address.__dict__={'city': 'City here', 'country': 'Country here', 'street': 'Street here', 'street_number': 4294967295}
print(f"{person.address.__dict__=}")
# person.name='Name here'
print(f"{person.name=}")
# person.address.country='Country here'
print(f"{person.address.country=}")
# dir(person)=['address', 'age', 'name']
print(f"{dir(person)=}")
# dir(person.address)=['city', 'country', 'street', 'street_number']
print(f"{dir(person.address)=}")
```