Skip to main content
Namespaces - Names are labels for identification. We use a name to refer to a thing. Several objects can have the same name, and this can create problems, calling out 'Robert' in a crowd, for instance. A thing can have many names, and this is ok, you call your friend Robert, Bob.

MicroPython has two groups of names:
  1.  implicit
  2.  explicit

We also have symbols +, *, - and alike.

Implicit names are keywords and builtins. Keywords defined the language and can not be
reuse.

Statement in = 23 will give you SyntaxError, while id = 23 is ok. The difference is that the word in is a keyword and
id is a builtin.

Names created in our codes, functions, class, variables, are examples of explicit names. You can delete an explicit name using del. You will get NameError if you try to delete an implicit name.

There are two types of object:
  1.  basic
  2.  composite
Basic objects are single value objects like integer, character, float, character, and boolean. Composite objects are a multivalued object like string, array, dictionary, class, and function. The value of a basic object is its proper value. The value of a composite object is its reference.

Each name has three scopes:
  1. global
  2. nonlocal
  3. local
If we are at the topmost level in our program then globals() == locals() will give True.   The keyword global in a function will refer to a variable in the global namespace.

Scopes and namespaces are related, nested,  sort of matryoshka dolls.

We can use a class to create a namespace in MicroPython. We can accomplish this by:

class NS:
    pass

x = NS()
x.a = 1
x.b = 'one'


MicroPython is Python, quiet but not quiet.

Comments

Popular posts from this blog

Custom made - Sometimes, it is nice to be able to build custom made things. Thanks to Damien George and all the clever people at micropython.org for making it easy. So that, to custom build a micropython is not that difficult. Why do you want to build customize firmware anyway? Well, you might want to include some functionalities of your own and removed some functionalities from the standard distribution. The choices are there for you to make. I have a few changes that I want to make in micropython. version header -kaki5 (pronounce kaki-lima) an additional thread cleanup function for esp32 add frozen modules CryptoXo and uasyncio remove help, upip, and webrepl camera C module for esp32 camera board These are accomplished by modifying and adding files. py/makeversionhdr.py py/modthread.c extra/CryptoXo.py, extra/uasyncio.py, and manifest.py mpconfigport.h main.c and modcamera.c I also want to remove some modules specifically, help, upip, and webrepl from esp32
Multi-threading : I previously used an uasyncio webcam server. This time around, I am testing a multi-thread webcam server. The result is promising. A multi-thread server seems to give a better throughput. The program logic is simpler when compared to the server based on uasyncio. The server is a four threaded application, two for port 80, one for port 81, and port 82 runs on the main thread, which blocks the REPL.  You can start a dedicated thread for port 82 if you do not want to block the REPL. I found pix/7 gives the best performance. A spe/2 will reduce the image size but give you a grayscale image. Please see my previous blog if all these seem mysterious to you. I have compiled a new firmware, MicroPython v1.11-571-g7e374d231.  You can download the new firmware from my repository at GitHub. The soft reset is not functioning properly. You need to do a hard reset. I also include four new functions in modcamera.c: pixformat agcgain aelevels aecvalue The pixformat chan
Micropython - v1.11-498 introduced a few changes in the source-code directory structure. Changes to specific files, as previously described in esp32-cam , will no longer work. A simple working summary on how to build esp32-cam firmware is described below: Make a recursive copy of ports/esp32 to ports/esp32-cam, and you will need to modify the following files: 1) ports/esp32-cam/main.c 2) ports/esp32-cam/Makefile 3) ports/esp32-cam/modcamera.c 4) ports/esp32-cam/mpconfigport.h 5) ports/esp32-cam/boards/manifest.py 6) ports/esp32-cam/boards/sdkconfig.base Or, you can just download a precompiled Micropython v1.11-498 from firmware.bin at GitHub if you want to save some work. However, I encourage you to compile the firmware yourself. You will learn a lot and you can choose to modify anything to your liking. The modcamera.c includes something new. The still photo was taken using these settings; pix =8, con =2, qua =10, and spe =2. You will understand those parameters, later