mirror of
https://github.com/sascha-hemi/pycom-documentation.git
synced 2026-03-21 09:04:12 +01:00
GitBook: [master] 334 pages and 4 assets modified
This commit is contained in:
committed by
gitbook-bot
parent
1694c83fcd
commit
260e81c8e8
34
documentation-notes/replscript.md
Normal file
34
documentation-notes/replscript.md
Normal file
@@ -0,0 +1,34 @@
|
||||
# REPL vs Scripts
|
||||
|
||||
Users of this documentation should be aware that examples given in the docs are under the expectation that they are being executed using the MicroPython REPL. This means that when certain functions are called, their output may not necessarily be printed to the console if they are run from a script. When using the REPL many classes/functions automatically produce a printed output displaying the return value of the function to the console. The code snippet below demonstrates some examples of classes/functions that might display this behaviour.
|
||||
|
||||
## Basic Arithmetic
|
||||
|
||||
```python
|
||||
1 + 1 # REPL will print out '2' to console
|
||||
1 + 1 # Script will not return anything the console
|
||||
print(1 + 1) # Both the REPL and a script will return '2' to the console
|
||||
```
|
||||
|
||||
## Calling Methods
|
||||
|
||||
```python
|
||||
import ubinascii
|
||||
|
||||
ubinascii.hexlify(b'12345') # REPL will print out "b'3132333435'" to the console
|
||||
ubinascii.hexlify(b'12345') # Script will not return any the console
|
||||
```
|
||||
|
||||
In order to use these functions that do not print out any values, you will need to either wrap them in a `print()` statement or assign them to variables and call them later when you wish to use them.
|
||||
|
||||
For example:
|
||||
|
||||
```python
|
||||
# immediately print to console when using a script
|
||||
print(1 + 1)
|
||||
# or save variable to for later
|
||||
value = 1 + 1
|
||||
# do something here...
|
||||
print(value)
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user