https://github.com/rec/xmod
🌱 Turn any object into a module 🌱
https://github.com/rec/xmod
modules objects python tools
Last synced: 3 months ago
JSON representation
🌱 Turn any object into a module 🌱
- Host: GitHub
- URL: https://github.com/rec/xmod
- Owner: rec
- License: mit
- Created: 2020-07-10T14:42:46.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-03-20T18:25:48.000Z (almost 2 years ago)
- Last Synced: 2025-06-10T09:02:34.947Z (8 months ago)
- Topics: modules, objects, python, tools
- Language: Python
- Homepage: https://rec.github.io/xmod/
- Size: 646 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG
- Funding: FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# 🌱 Turn any object into a module 🌱
Callable modules! Indexable modules!?
Ever wanted to call a module directly, or index it? Or just sick of seeing
`from foo import foo` in your examples?
Give your module the awesome power of an object, or maybe just save a
little typing, with `xmod`.
`xmod` is a tiny library that lets a module to do things that normally
only a class could do - handy for modules that "just do one thing".
## Example: Make a module callable like a function!
# In your_module.py
import xmod
@xmod
def a_function():
return 'HERE!!'
# Test at the command line
>>> import your_module
>>> your_module()
HERE!!
## Example: Make a module look like a list!?!
# In your_module.py
import xmod
xmod(list(), __name__)
# Test at the command line
>>> import your_module
>>> assert your_module == []
>>> your_module.extend(range(3))
>>> print(your_module)
[0, 1, 2]
### [API Documentation](https://rec.github.io/xmod#xmod--api-documentation)