kopia lustrzana https://github.com/peterhinch/micropython-samples
Add notes on import.
rodzic
895c1dc81f
commit
e5f1197c8a
|
@ -35,15 +35,13 @@ The file `my_library/foo.py` is only loaded when it becomes clear that
|
||||||
the user and may be changed without affecting its API.
|
the user and may be changed without affecting its API.
|
||||||
|
|
||||||
The "lazy loader" is employed in
|
The "lazy loader" is employed in
|
||||||
[uasyncio](https://github.com/micropython/micropython/tree/master/extmod/uasyncio).
|
[uasyncio](https://github.com/micropython/micropython/tree/master/extmod/uasyncio)
|
||||||
making it possible to write
|
making it possible to write
|
||||||
```python
|
```python
|
||||||
import uasyncio as asyncio
|
import uasyncio as asyncio
|
||||||
e = asyncio.Event() # The file event.py is loaded now
|
e = asyncio.Event() # The file event.py is loaded now
|
||||||
```
|
```
|
||||||
Files are loaded as required.
|
Files are loaded as required. The source code is in `__init__.py`:
|
||||||
|
|
||||||
The source code is in `__init__.py`:
|
|
||||||
[the lazy loader](https://github.com/micropython/micropython/blob/master/extmod/uasyncio/__init__.py).
|
[the lazy loader](https://github.com/micropython/micropython/blob/master/extmod/uasyncio/__init__.py).
|
||||||
|
|
||||||
# 3. Wildcard imports
|
# 3. Wildcard imports
|
||||||
|
@ -55,9 +53,7 @@ from my_module import *
|
||||||
needs to be treated with caution for two reasons. It can populate the program's
|
needs to be treated with caution for two reasons. It can populate the program's
|
||||||
namespace with unexpected objects causing name conflicts. Secondly all these
|
namespace with unexpected objects causing name conflicts. Secondly all these
|
||||||
objects occupy RAM. In general wildcard imports should be avoided unless the
|
objects occupy RAM. In general wildcard imports should be avoided unless the
|
||||||
module is designed to be imported in this way.
|
module is designed to be imported in this way. For example issuing
|
||||||
|
|
||||||
For example issuing
|
|
||||||
```python
|
```python
|
||||||
from uasyncio import *
|
from uasyncio import *
|
||||||
```
|
```
|
||||||
|
|
Ładowanie…
Reference in New Issue