GitBook: [master] 44 pages modified

This commit is contained in:
Daniel Spindelbauer
2018-08-20 10:02:34 +00:00
committed by gitbook-bot
parent 31da1d364c
commit 82d7dcf2ff
44 changed files with 321 additions and 303 deletions

View File

@@ -19,31 +19,31 @@ for i in range(2):
_thread.start_new_thread(th_func, (i + 1, i))
```
## Functions
## Methods
### \_thread.start\_new\_thread\(function, args\[, kwargs\]\)
#### \_thread.start\_new\_thread\(function, args\[, kwargs\]\)
Start a new thread and return its identifier. The thread executes the function with the argument list args \(which must be a tuple\). The optional `kwargs` argument specifies a dictionary of keyword arguments. When the function returns, the thread silently exits. When the function terminates with an unhandled exception, a stack trace is printed and then the thread exits \(but other threads continue to run\).
### \_thread.exit\(\)
#### \_thread.exit\(\)
Raise the `SystemExit` exception. When not caught, this will cause the thread to exit silently.
### \_thread.allocate\_lock\(\)
#### \_thread.allocate\_lock\(\)
Return a new lock object. Methods of locks are described below. The lock is initially unlocked.
### \_thread.get\_ident\(\)
#### \_thread.get\_ident\(\)
Return the `thread identifier` of the current thread. This is a nonzero integer. Its value has no direct meaning; it is intended as a magic cookie to be used e.g. to index a dictionary of thread-specific data. Thread identifiers may be recycled when a thread exits and another thread is created.
### \_thread.stack\_size\(\[size\]\)
#### \_thread.stack\_size\(\[size\]\)
Return the thread stack size \(in bytes\) used when creating new threads. The optional size argument specifies the stack size to be used for subsequently created threads, and must be `0` \(use platform or configured default\) or a positive integer value of at least `4096` \(4KiB\). 4KiB is currently the minimum supported stack size value to guarantee sufficient stack space for the interpreter itself.
## Objects
### \_thread.LockType
#### \_thread.LockType
This is the type of lock objects.

View File

@@ -6,15 +6,17 @@ Supported format codes: `b, B, h, H, i, I, l, L, q, Q, f, d` \(the latter 2 depe
## Classes
### class array.array\(typecode\[, iterable\]\)
#### class array.array\(typecode\[, iterable\]\)
Create array with elements of given type. Initial contents of the array are given by an iterable. If it is not provided, an empty array is created.
### array.append\(val\)
## Methods
#### array.append\(val\)
Append new element to the end of array, growing it.
### array.extend\(iterable\)
#### array.extend\(iterable\)
Append new elements as contained in an iterable to the end of array, growing it.

View File

@@ -2,41 +2,41 @@
The `cmath` module provides some basic mathematical functions for working with complex numbers. Floating point support required for this module.
## Functions
## Methods
### cmath.cos\(z\)
#### cmath.cos\(z\)
Return the cosine of `z`.
### cmath.exp\(z\)
#### cmath.exp\(z\)
Return the exponential of `z`.
### cmath.log\(z\)
#### cmath.log\(z\)
Return the natural logarithm of `z`. The branch cut is along the negative real axis.
### cmath.log10\(z\)
#### cmath.log10\(z\)
Return the base-10 logarithm of `z`. The branch cut is along the negative real axis.
### cmath.phase\(z\)
#### cmath.phase\(z\)
Returns the phase of the number `z`, in the range \(-pi, +pi\).
### cmath.polar\(z\)
#### cmath.polar\(z\)
Returns, as a tuple, the polar form of `z`.
### cmath.rect\(r, phi\)
#### cmath.rect\(r, phi\)
Returns the complex number with modulus `r` and phase `phi`.
### cmath.sin\(z\)
#### cmath.sin\(z\)
Return the sine of `z`.
### cmath.sqrt\(z\)
#### cmath.sqrt\(z\)
Return the square-root of `z`.

View File

@@ -1,24 +1,24 @@
# gc
## Functions
## Methods
### gc.enable\(\)
#### gc.enable\(\)
Enable automatic garbage collection.
### gc.disable\(\)
#### gc.disable\(\)
Disable automatic garbage collection. Heap memory can still be allocated, and garbage collection can still be initiated manually using `gc.collect()`.
### gc.collect\(\)
#### gc.collect\(\)
Run a garbage collection.
### gc.mem\_alloc\(\)
#### gc.mem\_alloc\(\)
Return the number of bytes of heap RAM that are allocated.
### gc.mem\_free\(\)
#### gc.mem\_free\(\)
Return the number of bytes of available heap RAM.

View File

@@ -1,14 +1,14 @@
# micropython
## Functions
## Methosd
### micropython.alloc\_emergency\_exception\_buf\(size\)
#### micropython.alloc\_emergency\_exception\_buf\(size\)
Allocate size bytes of RAM for the emergency exception buffer \(a good size is around 100 bytes\). The buffer is used to create exceptions in cases when normal RAM allocation would fail \(eg within an interrupt handler\) and therefore give useful traceback information in these situations.
A good way to use this function is to place it at the start of a main script \(e.g. `boot.py` or `main.py`\) and then the emergency exception buffer will be active for all the code following it.
### micropython.const\(expr\)
#### micropython.const\(expr\)
Used to declare that the expression is a constant so that the compile can optimise it. The use of this function should be as follows:
@@ -23,35 +23,35 @@ Constants declared this way are still accessible as global variables from outsid
This const function is recognised directly by the MicroPython parser and is provided as part of the `micropython` module mainly so that scripts can be written which run under both CPython and MicroPython, by following the above pattern.
### micropython.opt\_level\(\[level\]\)
#### micropython.opt\_level\(\[level\]\)
If `level` is given then this function sets the optimisation level for subsequent compilation of scripts, and returns `None`. Otherwise it returns the current optimisation level.
### micropython.mem\_info\(\[verbose\]\)
#### micropython.mem\_info\(\[verbose\]\)
Print information about currently used memory. If the `verbose` argument is given then extra information is printed.
The information that is printed is implementation dependent, but currently includes the amount of stack and heap used. In verbose mode it prints out the entire heap indicating which blocks are used and which are free.
### micropython.qstr\_info\(\[verbose\]\)
#### micropython.qstr\_info\(\[verbose\]\)
Print information about currently interned strings. If the `verbose` argument is given then extra information is printed.
The information that is printed is implementation dependent, but currently includes the number of interned strings and the amount of RAM they use. In verbose mode it prints out the names of all RAM-interned strings.
### micropython.stack\_use\(\)
#### micropython.stack\_use\(\)
Return an integer representing the current amount of stack that is being used. The absolute value of this is not particularly useful, rather it should be used to compute differences in stack usage at different points.
### micropython.heap\_lock\(\)
#### micropython.heap\_lock\(\)
### micropython.heap\_unlock\(\)
#### micropython.heap\_unlock\(\)
Lock or unlock the heap. When locked no memory allocation can occur and a `MemoryError` will be raised if any heap allocation is attempted.
These functions can be nested, i.e. `heap_lock()` can be called multiple times in a row and the lock-depth will increase, and then `heap_unlock()` must be called the same number of times to make the heap available again.
### micropython.kbd\_intr\(chr\)
#### micropython.kbd\_intr\(chr\)
Set the character that will raise a `KeyboardInterrupt` exception. By default this is set to 3 during script execution, corresponding to `Ctrl-C`. Passing `-1` to this function will disable capture of `Ctrl-C`, and passing `3` will restore it.

View File

@@ -6,13 +6,13 @@ This module provides functions to wait for events on streams \(select streams wh
Polling is an efficient way of waiting for read/write activity on multiple objects. Current objects that support polling are: `pyb.UART`, `pyb.USB_VCP`.
## Functions
## Methods
### select.poll\(\)
#### select.poll\(\)
Create an instance of the `Poll` class.
### select.select\(rlist, wlist, xlist\[, timeout\]\)
#### select.select\(rlist, wlist, xlist\[, timeout\]\)
Wait for activity on a set of objects.

View File

@@ -1,12 +1,12 @@
# sys
## Functions
## Methods
### sys.exit\(retval=0\)
#### sys.exit\(retval=0\)
Terminate current program with a given exit code. Underlyingly, this function raise as `SystemExit` exception. If an argument is given, its value given as an argument to `SystemExit`.
### sys.print\_exception\(exc, file=sys.stdout\)
#### sys.print\_exception\(exc, file=sys.stdout\)
Print exception with a traceback to a file-like object file \(or `sys.stdout` by default\).

View File

@@ -2,9 +2,9 @@
This module implements conversions between binary data and various encodings of it in ASCII form \(in both directions\).
## Functions
## Methods
### ubinascii.hexlify\(data\[, sep\]\)
#### ubinascii.hexlify\(data\[, sep\]\)
Convert binary data to hexadecimal representation. Returns bytes string.
@@ -14,15 +14,15 @@ Convert binary data to hexadecimal representation. Returns bytes string.
If additional argument, `sep` is supplied, it is used as a separator between hexadecimal values.
{% endhint %}
### ubinascii.unhexlify\(data\)
#### ubinascii.unhexlify\(data\)
Convert hexadecimal data to binary representation. Returns bytes string. \(i.e. inverse of `hexlify`\)
### ubinascii.a2b\_base64\(data\)
#### ubinascii.a2b\_base64\(data\)
Convert Base64-encoded data to binary representation. Returns bytes string.
### ubinascii.b2a\_base64\(data\)
#### ubinascii.b2a\_base64\(data\)
Encode binary data in Base64 format. Returns string.

View File

@@ -8,7 +8,7 @@ This module provides native support for cryptographic algorithms. Its loosely
## **Methods**
### crypto.getrandbits\(bits\)
#### crypto.getrandbits\(bits\)
Returns a bytes object filled with random bits obtained from the hardware random number generator.

View File

@@ -77,35 +77,35 @@ Note that bitfield operations are independent of target byte endianness, in part
## Module Contents
### class uctypes.struct\(addr, descriptor, layout\_type=NATIVE\)
#### class uctypes.struct\(addr, descriptor, layout\_type=NATIVE\)
Instantiate a "foreign data structure" object based on structure address in memory, descriptor \(encoded as a dictionary\), and layout type \(see below\).
### uctypes.LITTLE\_ENDIAN
#### uctypes.LITTLE\_ENDIAN
Layout type for a little-endian packed structure. \(Packed means that every field occupies exactly as many bytes as defined in the descriptor, i.e. the alignment is 1\).
### uctypes.BIG\_ENDIAN
#### uctypes.BIG\_ENDIAN
Layout type for a big-endian packed structure.
### uctypes.NATIVE
#### uctypes.NATIVE
Layout type for a native structure - with data endianness and alignment conforming to the ABI of the system on which MicroPython runs.
### uctypes.sizeof\(struct\)
#### uctypes.sizeof\(struct\)
Return size of data structure in bytes. Argument can be either structure class or specific instantiated structure object \(or its aggregate field\).
### uctypes.addressof\(obj\)
#### uctypes.addressof\(obj\)
Return address of an object. Argument should be bytes, `bytearray` or other object supporting buffer protocol \(and address of this buffer is what actually returned\).
### uctypes.bytes\_at\(addr, size\)
#### uctypes.bytes\_at\(addr, size\)
Capture memory at the given address and size as bytes object. As bytes object is immutable, memory is actually duplicated and copied into bytes object, so if memory contents change later, created object retains original value.
### uctypes.bytearray\_at\(addr, size\)
#### uctypes.bytearray\_at\(addr, size\)
Capture memory at the given address and size as `bytearray` object. Unlike `bytes_at()` function above, memory is captured by reference, so it can be both written too, and you will access current value at the given memory address.

View File

@@ -4,41 +4,41 @@ This module implements binary data hashing algorithms. MD5 and SHA are supported
## Constructors
### class uhashlib.md5\(\[data\]\)
#### class uhashlib.md5\(\[data\]\)
Create a MD5 hasher object and optionally feed data into it.
### class uhashlib.sha1\(\[data\]\)
#### class uhashlib.sha1\(\[data\]\)
Create a SHA-1 hasher object and optionally feed data into it.
### class uhashlib.sha224\(\[data\]\)
#### class uhashlib.sha224\(\[data\]\)
Create a SHA-224 hasher object and optionally feed data into it.
### class uhashlib.sha256\(\[data\]\)
#### class uhashlib.sha256\(\[data\]\)
Create a SHA-256 hasher object and optionally feed data into it.
### class uhashlib.sha384\(\[data\]\)
#### class uhashlib.sha384\(\[data\]\)
Create a SHA-384 hasher object and optionally feed data into it.
### class uhashlib.sha512\(\[data\]\)
#### class uhashlib.sha512\(\[data\]\)
Create a SHA-512 hasher object and optionally feed data into it.
## Methods
### hash.update\(data\)
#### hash.update\(data\)
Feed more binary data into hash.
### hash.digest\(\)
#### hash.digest\(\)
Return hash for all data passed through hash, as a bytes object. After this method is called, more data cannot be fed into hash any longer.
### hash.hexdigest\(\)
#### hash.hexdigest\(\)
This method is NOT implemented. Use `ubinascii.hexlify(hash.digest())` to achieve a similar effect.

View File

@@ -2,17 +2,17 @@
This modules allows to convert between Python objects and the JSON data format.
## Functions
## Methods
### ujson.dumps\(obj\)
#### ujson.dumps\(obj\)
Return `obj` represented as a JSON string.
### ujson.loads\(str\)
#### ujson.loads\(str\)
Parse the JSON `str` and return an object. Raises `ValueError` if the string is not correctly formed.
### ujson.load\(fp\)
#### ujson.load\(fp\)
Parse contents of `fp` \(a `.read()`-supporting file-like object containing a JSON document\). Raises `ValueError` if the content is not correctly formed.

View File

@@ -9,41 +9,41 @@ The filesystem has `/` as the root directory and the available physical drives a
* `/flash` the internal flash filesystem
* `/sd` the SD card \(if it exists\)
## Functions
## Methods
### uos.uname\(\)
#### uos.uname\(\)
Return information about the system, firmware release version, and MicroPython interpreter version.
### uos.chdir\(path\)
#### uos.chdir\(path\)
Change current directory.
### uos.getcwd\(\)
#### uos.getcwd\(\)
Get the current directory.
### uos.listdir\(\[dir\]\)
#### uos.listdir\(\[dir\]\)
With no argument, list the current directory. Otherwise list the given directory.
### uos.mkdir\(path\)
#### uos.mkdir\(path\)
Create a new directory.
### uos.remove\(path\)
#### uos.remove\(path\)
Remove a file.
### uos.rmdir\(path\)
#### uos.rmdir\(path\)
Remove a directory.
### uos.rename\(old\_path, new\_path\)
#### uos.rename\(old\_path, new\_path\)
Rename a file.
### uos.stat\(path\)
#### uos.stat\(path\)
Get the status of a file or directory.
@@ -60,23 +60,23 @@ The return value is a tuple with the following 10 values, in order:
* `st_mtime`: time of most recent content modification.
* `st_ctime`: time of most recent metadata change.
### uos.getfree\(path\)
#### uos.getfree\(path\)
Returns the free space \(in KiB\) in the drive specified by path.
### uos.sync\(\)
#### uos.sync\(\)
Sync all filesystems.
### uos.urandom\(n\)
#### uos.urandom\(n\)
Return a bytes object with n random bytes.
### uos.unlink\(path\)
#### uos.unlink\(path\)
Alias for the `remove()` method.
### uos.mount\(block\_device, mount\_point, \* , readonly=False\)
#### uos.mount\(block\_device, mount\_point, \* , readonly=False\)
Mounts a block device \(like an SD object\) in the specified mount point. Example:
@@ -87,11 +87,11 @@ uos.unmount(path)
Unmounts a previously mounted block device from the given path.
### uos.mkfs\(block\_device or path\)
#### uos.mkfs\(block\_device or path\)
Formats the specified path, must be either `/flash` or `/sd`. A block device can also be passed like an SD object before being mounted.
### uos.dupterm\(stream\_object\)
#### uos.dupterm\(stream\_object\)
Duplicate the terminal \(the REPL\) on the passed stream-like object. The given object must at least implement the `read()` and `write()` methods.

View File

@@ -19,21 +19,21 @@ $
Counted repetitions `({m,n})`, more advanced assertions, named groups, etc. are not supported.
## Functions
## Methods
### ure.compile\(regex\)
#### ure.compile\(regex\)
Compile regular expression, return `regex object`.
### ure.match\(regex, string\)
#### ure.match\(regex, string\)
Match regex against `string`. Match always happens from starting position in a string.
### ure.search\(regex, string\)
#### ure.search\(regex, string\)
Search regex in a string. Unlike match, this will search string for first position which matches regex \(which still may be 0 if regex is anchored\).
### ure.DEBUG
#### ure.DEBUG
Flag value, display debug information about compiled expression.
@@ -41,17 +41,17 @@ Flag value, display debug information about compiled expression.
Compiled regular expression. Instances of this class are created using `ure.compile()`.
### regex.match\(string\)
#### regex.match\(string\)
### regex.search\(string\)
#### regex.search\(string\)
### regex.split\(string, max\_split=-1\)
#### regex.split\(string, max\_split=-1\)
## Match objects
Match objects as returned by `match()` and `search()` methods.
### match.group\(\[index\]\)
#### match.group\(\[index\]\)
Only numeric groups are supported.

View File

@@ -8,13 +8,13 @@ See corresponding CPython module for comparison.
Functions below which expect a network address, accept it in the format of `(ipv4_address, port)`, where `ipv4_address` is a string with dot-notation numeric IPv4 address, e.g. `8.8.8.8`, and port is integer port number in the range 1-65535. Note the domain names are not accepted as `ipv4_address`, they should be resolved first using `socket.getaddrinfo()`.
## Functions
## Methods
### socket.socket\(socket.AF\_INET, socket.SOCK\_STREAM, socket.IPPROTO\_TCP\)
#### socket.socket\(socket.AF\_INET, socket.SOCK\_STREAM, socket.IPPROTO\_TCP\)
Create a new socket using the given address family, socket type and protocol number.
### socket.getaddrinfo\(host, port\)
#### socket.getaddrinfo\(host, port\)
Translate the host/port argument into a sequence of 5-tuples that contain all the necessary arguments for creating a socket connected to that service. The list of 5-tuples has following structure:

View File

@@ -2,9 +2,9 @@
This module provides access to Transport Layer Security \(often known as "Secure Sockets Layer"\) encryption and peer authentication facilities for network sockets, both client-side and server-side.
## Functions
## Methods
### ssl.wrap\_socket\(sock, keyfile=None, certfile=None, server\_side=False, cert\_reqs=CERT\_NONE, ca\_certs=None\)
#### ssl.wrap\_socket\(sock, keyfile=None, certfile=None, server\_side=False, cert\_reqs=CERT\_NONE, ca\_certs=None\)
Takes an instance `sock` of `socket.socket`, and returns an instance of ssl.SSLSocket, a subtype of `socket.socket`, which wraps the underlying socket in an SSL context. Example:

View File

@@ -6,25 +6,25 @@ Supported size/byte order prefixes: `@, <, >, !`.
Supported format codes: `b, B, h, H, i, I, l, L, q, Q, s, P, f, d` \(the latter 2 depending on the floating-point support\).
## Functions
## Methods
### ustruct.calcsize\(fmt\)
#### ustruct.calcsize\(fmt\)
Return the number of bytes needed to store the given `fmt`.
### ustruct.pack\(fmt, v1, v2, ...\)
#### ustruct.pack\(fmt, v1, v2, ...\)
Pack the values `v1, v2, ...` according to the format string `fmt`. The return value is a bytes object encoding the values.
### ustruct.pack\_into\(fmt, buffer, offset, v1, v2, ...\)
#### ustruct.pack\_into\(fmt, buffer, offset, v1, v2, ...\)
Pack the values `v1, v2, ...` according to the format string `fmt` into a buffer starting at `offset`. `offset` may be negative to count from the end of buffer.
### ustruct.unpack\(fmt, data\)
#### ustruct.unpack\(fmt, data\)
Unpack from the `data` according to the format string `fmt`. The return value is a tuple of the unpacked values.
### ustruct.unpack\_from\(fmt, data, offset=0\)
#### ustruct.unpack\_from\(fmt, data, offset=0\)
Unpack from the `data` starting at `offset` according to the format string `fmt`. `offset` may be negative to count from the end of buffer. The return value is a tuple of the unpacked values.

View File

@@ -14,9 +14,9 @@ This requires a Real Time Clock \(RTC\). On systems with underlying OS \(includi
If actual calendar time is not maintained with a system/MicroPython RTC, functions below which require reference to current absolute time may behave not as expected.
## Functions
## Methods
### utime.gmtime\(\[secs\]\)
#### utime.gmtime\(\[secs\]\)
Convert a time expressed in seconds since the Epoch \(see above\) into an 8-tuple which contains: `(year, month, mday, hour, minute, second, weekday, yearday)` If `secs` is not provided or `None`, then the current time from the RTC is used.
@@ -29,39 +29,39 @@ Convert a time expressed in seconds since the Epoch \(see above\) into an 8-tupl
* `weekday` is 0-6 for Mon-Sun
* `yearday` is 1-366
### utime.localtime\(\[secs\]\)
#### utime.localtime\(\[secs\]\)
Like `gmtime()` but converts to local time. If `secs` is not provided or `None`, the current time from the RTC is used.
### utime.mktime\(\)
#### utime.mktime\(\)
This is inverse function of `localtime`. Its argument is a full 8-tuple which expresses a time as per `localtime`. It returns an integer which is the number of seconds since `Jan 1, 2000`.
### utime.sleep\(seconds\)
#### utime.sleep\(seconds\)
Sleep for the given number of `seconds`. `seconds` can be a floating-point number to sleep for a fractional number of seconds. Note that other MicroPython ports may not accept floating-point argument, for compatibility with them use `sleep_ms()` and `sleep_us()` functions.
### utime.sleep\_ms\(ms\)
#### utime.sleep\_ms\(ms\)
Delay for given number of milliseconds, should be positive or 0.
### utime.sleep\_us\(us\)
#### utime.sleep\_us\(us\)
Delay for given number of microseconds, should be positive or 0
### utime.ticks\_ms\(\)
#### utime.ticks\_ms\(\)
Returns uptime, in milliseconds.
### utime.ticks\_us\(\)
#### utime.ticks\_us\(\)
Just like `ticks_ms` above, but in microseconds.
### utime.ticks\_cpu\(\)
#### utime.ticks\_cpu\(\)
Same as `ticks_us`, but faster.
### utime.ticks\_diff\(old, new\)
#### utime.ticks\_diff\(old, new\)
Measure period between consecutive calls to `ticks_ms()`, `ticks_us()`, or `ticks_cpu()`. The value returned by these functions may wrap around at any time, so directly subtracting them is not supported. `ticks_diff()` should be used instead. "old" value should actually precede "new" value in time, or result is undefined. This function should not be used to measure arbitrarily long periods of time \(because `ticks_*()` functions wrap around and usually would have short period\). The expected usage pattern is implementing event polling with timeout:
@@ -73,11 +73,11 @@ while pin.value() == 0:
raise TimeoutError
```
### utime.time\(\)
#### utime.time\(\)
Returns the number of seconds, as an integer, since the Epoch, assuming that underlying RTC is set. If an RTC is not set, this function returns number of seconds since power up or reset\). If you want to develop portable MicroPython application, you should not rely on this function to provide higher than second precision. If you need higher precision, use `ticks_ms()` and `ticks_us()` functions, if you need calendar time, `localtime()` without an argument is a better choice.
### utime.timezone\(\[secs\]\)
#### utime.timezone\(\[secs\]\)
Set or get the timezone offset, in seconds. If `secs` is not provided, it returns the current value.