Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pcattori/require.py
Relative imports in Python, inspired by Node.js `require`
https://github.com/pcattori/require.py
Last synced: 2 months ago
JSON representation
Relative imports in Python, inspired by Node.js `require`
- Host: GitHub
- URL: https://github.com/pcattori/require.py
- Owner: pcattori
- License: mit
- Created: 2016-08-12T23:53:02.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-12-02T03:12:45.000Z (about 8 years ago)
- Last Synced: 2024-04-22T15:25:07.690Z (9 months ago)
- Language: Python
- Homepage:
- Size: 70.3 KB
- Stars: 1
- Watchers: 4
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
[![PyPI version](https://badge.fury.io/py/require.py.svg)](https://badge.fury.io/py/require.py)
[![Build Status](https://travis-ci.org/pcattori/require.py.svg?branch=master)](https://travis-ci.org/pcattori/require.py)# require.py
Inspired by [require.js](http://requirejs.org/)
## Install
```bash
$ pip install require.py
```## Usage
```python
from require import require
mod = require('relative/path/to/module.py')# alternatively, use absolute path
mod = require('/absolute/path/to/module.py')
```## Example
directory structure:
- test/
- bar-directory/
- bar.py
- foo-directory/
- foo.py```python
# bar-directory/bar.py
CONST = 'string constant'def hello():
return 'world'
``````python
# foo-directory/foo.py
from require import require
bar = require('../bar-directory/bar.py')print bar.CONST
print bar.hello()
print dir(bar)
```