__init__.py (package definer) Raspberry.py (where the show() function is defined) afTest07.py (a program which calls the show() functionThe files __init__.py and Raspberry.py must be editted here in this folder but they must also be uploaded to the Thonny package folder called PiIX07 before they are usable. (These modules can also be stored in an IX package as a backup copy, but this copy would be a third copy of the exact same modules. Unfortunately Thonny packages require more work on the part of the programmer than the python3 IX packages.)
As a temporary sidenote . . . . it turns out that when a programmer uses both Thonny and Python3 versions of a package named "IX_08_pkg" in a Sandbox folder, all the following superfluous copies of the same modules become necessary:Returning to the minimal Thonny package definition PiIX07, the Raspberry.py file will house the Thonny show() function. The file afTest07.py is the Thonny application that calls show(). It must keep its same name unchanged but can be editted in this folder (but not anywhere else). Using the correct "import" syntax, the program afTest07.py can call any of the functions or modules in the PiIX07 package.
/home/pi/Sandbox/__init__.py the module by whose presence Thonny detects this to be a package folder /home/pi/Sandbox/afTest08.py the main test module that uses (calls) the modules in IX_08_pkg.py * /home/pi/Sandbox/IX_08_pkg.py a copy of each function in the IX_08_pkg package for initial editing by the programmer [This copy can be used for initial editting and module testing by the programmer.] [It is believed (but not known for certain) that functions outside of a class definition are permitted by Thonny] * Thonny/IX_08_pkg.py a copy of each function in the IX_08_pkg.py package for use only by Thonny * /home/pi/Sandbox/IX_08_pkg.py a copy of each function in the IX_08_pkg package for python3 to make a copy named *.pyc * /home/pi/Sandbox/IX_08_pkg.bu a copy of each function in the IX_08_pkg package to serve as a backup * /home/pi/Sandbox/IX_08_pkg.pyc a copy of each function in the IX_08_pkg package for use only by python3From the point of view of the programmer, all five copies of the modules (marked by an "*" above) in the package named IX_08_pkg should (at least initially) be identical. If more than one function (module) exists in the package named IX_08_pkg, it should be included in every module marked above with an asterisk ("*"). During the initial development and testing of each function, for ease of testing, the function will probably also exist as a separate python source file in the Sandbox folder. But once the function has been satisfactorily tested, it must be moved (or copied) into the 5 packages marked with an "*". The author apologizes for the complexity of these copies. But this is the situation because the developers of Python3 (for RPi and many other computers) and Thonny (for RPi and Pico) do not yet agree on their package definitions and mechanisms.
from Raspberry import Raspberry
#Raspberry.py in piIX07 on 2022BFeb28 by D@CC # Python code to illustrate the Module class Raspberry: # First we create a constructor for this class # and add members to it, here: models def __init__(self): self.models = ['Pi', 'Pico', 'Generic', 'Other'] #def end # A normal print function def outModels(self): print('These are the available models for Raspberry:') for model in self.models: print('\t%s ' % model) # the "\t" defines the format to use #for end #def end def show(self,str1,int2): #arg1 of self doesn't count as a "calling argument" print('str1:',str1,'int2:',int2) print('\t %s %d' % (str1 , int2) ) print('returning "xyz"') print('end of show.py') return "xyz" #def end #class end
#afTest07.py in Desktop/PiIX03/ # on 2022BFeb28 by D@CC # my first working import of one of my Thonny packages # Import classes from your brand new package # Package folder PiIX07 contains 2 files: __init__.py and Raspberry.py from PiIX07 import Raspberry # Create an object of Raspberry class & call its method IX = Raspberry() print("I created an object named IX") print("I am not yet using the 4 models") IX.outModels() isP=1 abcd="a123b" # invoke the show function for this object # resultStr=IX.show("abcd",isP) resultStr=IX.show("abcd",isP) resultStr=IX.show("efgh",isP) print(resultStr) #from Cars.Audi.a8 import get_buy print("exit afTest07.py") #prerequisites in Thonny Package Library # folder IX # __init__.py # Raspberry.py # Source: 1: http://geeksforgeeks.org/create-access-python-package # Title: Create and Access a Python Package # By: Chinmoy Lenka On 15 Feb, 2018 # Source 1 does not work for Thonny packages # Source 2 works for Thonny packages # Source: 2: https://www.tutorialspoint.com/create-and-access-a-python-package # ThonnyPackageLibrary: /home/pi/.local/lib/python3.7/site-packages # To view Library a)thonny b)Tools c)Target: user site packages #Documentation: /home/pi/Desktop/PythonPackageCreation.txt # Note 3: I will develop afTest.py in Desktop/PiIX07/ # the package will be PiIX07 containing show2.py and outModels # their references will be IX.show and IX.outModels # One object will be created named IX of class Raspberry # This program, /Desktop/PiIX07/afTest07.py, will be used for testing # Note 4 The names of the app folder and the package folder match. # See PythonPackagesNotes.txt # also changed the name of this app. # Note 5 I discovered that I could not use the editor while # Tools-Package was open. I needed to edit the package # routines elsewhere. I also discovered that it is not # the folder of the app that is "married" to the package. # It seems that the name of the app (or the contents of # the app) were "married" to the package. So I changed # the name of the app to "force" a new marriage of the # app to the revised package. I wonder if it was really # necessary to change the name of the package, but I # did, just to be safe. It then worked with the newly # editted package. Sweet success at last! # I was able to edit the app and run it again using the # package. Note that I did not change the name of the app itself. #end of afTest07.py
I created an object named IX I am not yet using the 4 models "abcd" 1 "abcd" 1 returning xyz 1 exit afTest07.pyNote that the following import statement caused the function "show" to be imported as part of the object type Raspberry:
from PiIX03 import RaspberryThis had the effect of "inserting" the code for show() as if it were actually part of the code of afTest03.py. This is exactly what we needed the package to do. The next section explains how to create the Thonny package.
Python Package Creation Example On 2022BFeb27 by David4ColeCanada@gmail.com 1. Create a directory and name it Cars [all the following modules will be placed in this dir.] 2. Then create the first 3 modules. [Create the file named Bmw.py] #Bmw.py in Cars # Python code to illustrate the Modules class Bmw: # First we create a constructor for this class # and add members to it, here models def __init__(self): self.models = ['i8', 'x1', 'x5', 'x6'] #def end # A normal print function def outModels(self): print('These are the available models for BMW') for model in self.models: print('\t%s ' % model) #for end #def end #class end #Audi.py in Cars # Python code to illustrate the Module class Audi: # First we create a constructor for this class # and add members to it, here models def __init__(self): self.models = ['q7', 'a6', 'a8', 'a3'] #def end # A normal print function def outModels(self): print('These are the available models for Audi') for model in self.models: print('\t%s ' % model) #for end #def end def outModel_a8(self): print('These are the available a8 models for Audi') for model in self.models: if model=='a8': print('\t%s ' % model ) #if end #for end #def end #class end #Nissan.py in Cars # Python code to illustrate the Module class Nissan: # First we create a constructor for this class # and add members to it, here models def __init__(self): self.models = ['altima', '370z', 'cube', 'rogue'] #def end # A normal print function def outModels(self): print('These are the available models for Nissan') for model in self.models: print('\t%s ' % model) #for end #def end #class end #__init__.py in Cars (can be empty) from Bmw import Bmw from Audi import Audi from Nissan import Nissan #sample.py # Import classes from your brand new package from Cars import Bmw from Cars import Audi from Cars import Nissan # Create an object of Bmw class & call its method ModBMW = Bmw() ModBMW.outModels() # Create an object of Audi class & call its method ModAudi = Audi() ModAudi.outModels() # Create an object of Nissan class & call its method ModNissan = Nissan() ModNissan.outModels() #getbuyProgram.py #from Cars.Audi.a8 import get_buy #Now call the function from anywhere: get_buy(1) #this method has not been (but must be) defined print("end of getbuyProgram.py") #end of getbuyProgram.py Source: Thonny Packages Title: This worked for Thonny as of 2022BFeb23 I am still modifying it replacing Cars with IX Thonny uses its own virtual environment by default. Open "Tools => Manage packages" or "Tools => Open system shell" in order to install into this environment. For completeness I will add that once you are in the Thonny System Shell you can run either "pip" or "pip3" to install the module you need. 1. Tell Thonny to include the Tools menu 2. Restart Thonny, then click on "Tools" 3. Select "Manage Packages" 4. Read "Target: user site packages from /home/pi/.local/lib/python3.7/site-packages This dialog lists all available packages, but allows upgrading and uninstalling only packages from /home/pi/.local/lib/python3.7/site-packages . New packages will be also installed into this directory. Other locations must be managed by alternative means. Source: https://www.youtube.com/watch?v=Oo-B98WWre8 Title: Thonny: The Beginner-Friendly Python Editor By Krishelle hardson-Hurley Source: http://geeksforgeeks.org/create-access-python-package Title: Create and Access a Python Package By Chinmoy Lenka On 15 Feb, 2018 NB This doesn't work for Thonny /PythonPackageCreation.txtOther resources pertaining to PiIX07 are in the zip file in Source 3. These txt files are:
HowToManageThonnyPackage.txt PythonPackageCreation.txt PythonPackagesNotes.txt
Name: Arguments (passed): Author (if known): Classes (defined for use): Command List (if prg): Date (written): External Functions called: Files Used: Globals (for ext. use): Globals (int. use only): Help (or Manual): Import From Pkg.: Imports Pkg. Used: Prerequisite (Object/Function): Python Verson: 2, 3, Thonny Result (return/yield): Version (latest):
import pir2A import pir2DataWhen a function [e.g. isTypeStr() ] or subroutine in the package is referenced, the reference is preceded by the name of the package as shown below:
if pir2A.isTypeStr(targTempL0) : . . statements. . . #if endThe actual isTypeStr() function is a little more complex, but no more will be said about it here.
g_targTempL0 = targTempL0 # BAD CODEI have written a pair of subroutines (named set... and get...) to resolve this issue. The preferred statement (to replace the above bad code) is:
pir2.set_global("g_targTempL0", targTempL0) # GOOD CODE . . . . targTempL0 = pir2A.get_global("g_targTempL0") # GOOD CODEThe second statement shown above can be used later to dynamically retrieve the global value. In fact, both statements operate dynamically making use of the current value of the global variable. This process needs these global variables to be declared in the pir2A.access_global() subroutine. Not all global variables need to be declared in this fashion, only those that need to be dealt with in the main application routine. Using these routines (statements) has facilitated my use of Python global variables.
input (ageStr) if isTypeStr(ageStr) : . . . else : . . . #if end
def access_global_list_definition(): #by D@CC # This must be defined in the pir2A.py module (not the calling program) # it should be called ONCE during main program initialization # But it can be called from anywhere using # pir2A.access_global_list_definition() global gAL gAL="" gAL=gAL+"."+"g_targTempL0" ; global g_targTempL0 gAL=gAL+"."+"g_gALtest" ; global g_gALtest nCount=2 returnValue = "globalAList was defined containing a global Count of : ",nCount #print("gAL:"+gAL) return returnValue #def end def access_global(gName,AorR,value): #by D@CC # This must be defined in the pir2A.py # It doesn't need to be called from outside the pir2A.py # check if in the gAL (globalAccessList) global gAL gAL1="" gAL1=gAL1+"."+"g_targTempL0" ; global g_targTempL0 gAL1=gAL1+"."+"g_gALtest" ; global g_gALtest # all globabls used here must be pre-defined here in this list, # but their values need not be pre-defined # With some additional work, this will be only # done in access_global_list_definition() nCount=2 #print("in access_global,gAL:"+gAL) #print("gAL:"+gAL) #print("found:", gAL.find(".") ) #print("found:"+gName,gAL.find(gName)) if gAL.find(gName)==-1 : #print("didn't find:"+gName) print("ERROR global Name cannot be accessed:"+gName) returnValue = gName+" ERROR: is not in the globalAccessList!" else: # match/case don't work yet in Python if gName == "g_gALtest": if AorR == "Assign": g_gALtest = value else: returnValue = g_gALtest if gName =="g_targTempL0": if AorR == "Assign": g_targTempL0 = value else: returnValue = g_targTempL0 #if end if AorR=="Assign" : if isTypeStr(value): returnValue=gName+" was assigned value:"+value+":" else: returnValue=gName+" was assigned value:"+str(value)+":" #if end else: continueDoh=1 #if end #if end return returnValue #def end def get_global(gName): #by D@CC global gAL #print("in get_global,gAL:"+gAL) #this is usually called from outside the pir2A.py # it can be called e.g. gALtest = pir2A.get_global("g_gALtest") return access_global(gName,"Retrieve","na") #def end def set_global(gName,value): #by D@CC #print("in set_global, gName:"+gName) #this is usually called from outside the pir2A.py # it can be called e.g. pir2A.set_global("g_gALtest",value) # WARNING: it will over-ride the current value of this global value access_global(gName,"Assign",value) if isTypeStr(value): returnValue= gName+" was set="+value else: returnValue= gName+" was set="+str(value) #doesn't work if value is not a string return returnValue #def end def get_targTempL0(str1): returnValue = access_global("g_targTempL0","Retrieve","na") return returnValue #def end def isTypeStr(vName): # there is a better version of this somewhere on my computer Ttype=type(vName) if Ttype=="": return True else: return False #def end #/global_and_isTypeStr.py
isInstance() standard python function: used in f3() in my Article 155) mid() used in f3() & IX vector functions (in my Article 164) mid() using in MySQL mid$() used in PicoMite MMBASIC pack() defined in Tkinter, the GUI package pack() defined in textpack by O'Reilly (Source 08)
For python3, it is not even necessary to precede the printSho() by the package name. Furthermore it is not necessary to use the IX_textunpack.py routine to unpack the package. Of course, if desired, the functions can be unpacked and placed in different folders or included in the calling programs. I normally place the test programs and the package in a folder named IX (that is located in the Desktop folder.) To facilitate packing and unpacking, I place the IX_textpack.py and IX_textunpack.py programs in the Desktop folder. Usually, I also prefix "IX_" in front of the names of my versions of the textpack and textunpack program names. Do not be surprised to notice that, when using the package, Python makes a (modfified) copy of the package with an extension of ".pyc" .from IX_package_py import printSho progName="printSho_test.py" printSho() print("end of "+progName) #end printSho_test.py
$> python ..\IX_textpack.py spam.txt eggs.txt ham.txt > packed.allWhen using this syntax, the IX_textpack.py routine must be located in the folder above the files.
This complete package is merely the big text file seen in Source 10.IX_textpack.py packs a list of files into a package IX_textunpack.py unpacks ALL the files from an existing package IX_textselect.py selects (unpacks) a SINGLE file from an existing package IX_textpack.txt explains HOW to use IX_textpackPkg_py.txt IX_textnames.py lists the filenamess in a package (deprecated . . . use n.py] IX_textadd.py adds a file to the package (deprecated. . . use IX_textpack.py with ">>" instead) n.py lists the various contents of the package
The current filenames in that package are:>$ python3 n.py < IX_textpack_pkg.py
My thanks to O'Reilly (Source 08) for documenting this (or his) package concept.#Be sure to precede the Pkg name with a "<". IX_textunpack.py IX_textselect.py IX_textpack.txt IX_textpack.py IX_textadd.py n.py nShowDefs.py *** end of list by n.py
My current emphasis will be on the above packages marked by an asterisk. These packages are limited to source code and text documents. Some of these documents will contain ascii characters (e.g. Windows NoteBook txt documents) while others will contain Unicode characters (e.g. Raspberry MousePad txt documents). I plan to make use of the Consolas-10 monospaced font whenever possible. The creation of many of these package libraries will take a long time and is a project that will realistically never be complete. Other packages will evolve and will move through many development phases. I have begun to only use the suffix "_pkg" for package names that contain python functions (not programs). For this reason the set of textpack programs are now stored in "IX_textpack_programs.py" which is a package but contains no externally callable functions.Package Name Contents --------------------- ------------------------------------------------ * adcRead_pkg.py python RPi functions for adc sensing of voltages (Source 11) * adcRead_programs.py python RPi programs for adc sensing (Source 16) adcRead_test.py needs to import adcRead_pkg.py * functionList_pkg.py routine used by n.py to list the function names in a statement IX_DataSheets.Sources.txt Electronic DataSheet Sources (e.g. pdf.html) IX_diagnostics_py.py python diagnotics for Raspberry Pi Hardware * GPIO_pkg.py pir2 & GPIO functions (possible duplicates in other pkgs) IX_ICH180R2_A.php php & html routines for the future ICH180R2 website IX_MIC.php php & html routines for the MehInCharge website * IX_MMBasic_pkg.bas functions, subroutines and programs written in Basic * IX_MMBasic_notes.txt text files about MMBasic for PicoMite hardware * IX_package_py.py precursor to the IX_py.py package IX_pi_py.py python functions for pi computers IX_pi_notes.txt Miscellaneous notes about Pi computers IX_pi_sources.txt My Sources of Pi Information IX_pico_py.py python functions for pico computers IX_picoMite.bas software written in basic for PicoMite hardware IX_pir2.py python functions for the PiR2 controller IX_pir2_info pir2 information IX_pir2models.py python functions for the various PiR2 controllers IX_projects_py.py python software for various projects IX_py.py python functions common to pi&pico computers IX_python_info python 2 & 3 language information IX_RPi_hardware.txt Raspberry Pi Hardware Descriptions * IX_testPrograms_py.py various programs to test hardware and software * IX_textpack_pkg.py IX_text pack/unpack/select/etc & n programs (Source 10) deprecated replaced by IX_textpack_programs.py * IX_textpack_programs.py IX_text pack/unpack/select/etc & n.py programs (Source 17) IX_thonny_pkg.py IX functions to become a thonny package
(L-R) 3v3, AIN3, AIN2, AIN1, AIN0 and GND WARNING: sensing voltages higher than 3v3 will harm the board. WARNING: when sensing a voltage, a wire must also be connected to GND.
Click on the photo to enlarge it. SeeedStudio Board RPi ADS1115 (upside-down) |
Click on the photo to enlarge it. SeeedStudio Board RPi ADS1115 |
#! /usr/bin/python3The shebang line must be the first line of any program using this Unix "trick". The "quick and easy" copy of the "IX_textnames.py" (the program that lists the files in an IX package) is called "n.py". To easily list the names of all the files in the "IX_textpack_pkg.py" package (presuming it is in the Desktop folder) simply type:
>$ cd Desktop >$ ./n.py < IX_textpack_pkg.pyIt will list the filenames (as shown above just before the "Python Packages" heading). To tell Unix or Linux to run such programs in "quick Terminal" mode, the following command is needed once:
>$ cd Desktop >$ sudo chmod +x n.py
The "import" statements shown above apply to packages that are imported from the local computer, not from packages that are external to the computer. To be made available to any web-surfer "External Packages" must be carefully prepared and uploaded to a site recognized by the creators of python. For example, certain "help information" must be included. Although, they may apply to "External Packages", this article only reports results of the testing of "nonExternal Packages", those created by a programmer who stores them on his/her local computer in the same folder as the main application program. There are 3 different ways of importing functions. They are shown below:# needs to have adcRead_pkg.py in the same folder as adcRead_test.py # needs from adcRead_pkg import adcRead,adcReadInit # needs cd Desktop #Import syntax A # from adcRead_pkg import adcRead,adcReadInit # (only lets the program directly call the listed routines) # or #Import syntax =B # # from adcRead_pkg import * # (lets the program directly call any of the routines in the pkg) # or #Import syntax C # # import adcRead_pkg # (to call any imported routine in the pkg using this syntax, # the name of the routine must be preceded by "adcRead_pkg." ) #When using Import syntax A: # #from adcRead_pkg import adcRead,adcReadInit #(actually its name is adcRead_pkg.py)
# Import Syntax A #from adcRead_pkg import adcRead,adcReadInit # (only lets the program directly call the listed routines) # or # Import Syntax B #from adcRead_pkg import * # (lets the program directly call any of the routines in the pkg) # or # Import Syntax C #import adcRead_pkg # (to call any imported routine from the pkg using this syntax, # its name must be preceded by the package name: "adcRead_pkg." )The package named "adcRead_pkg.py" contains 2 externally callable functions named adcRead,adcReadInit. Syntax A and Syntox B can be used to import these 2 functions. Many other internally called functions also exist in the adcRead_pkg.py. They are also imported regardless of which of the 3 Import syntax is used. The program that uses the 2 adcRead functions will function correctly regardless of which Import Syntax is used. However, if the user accidentally defines a function having the same name as a function that already exists in the adcRead_pkg, Python may have difficulty deciding which function to use. Syntax A will "hide" the function in the package, so Python will only use the function defined by the user. Syntax C requires that the user prefix the function from the package with the name of the package if that function is to be used. Syntax C will use the function defined by the user, if no package prefix is used. Syntax B might be confused as to which function to use. Therefore I try not to use Symtax B. I hate having to prefix my function-names with the package-name so I refrain from using Syntax C. Therefore I recommend that users use Syntax A. Notice that the package name specified in the import statement omits the ".py" and must not include pathing information specifying a path to the package.
import adcRead_v13 as adcReadIf the user has different versions of a function available, he can distinguish which version he/she wishe to use by using the word "as" in the the import statement. I have not experimented with the use of the word "as" in the import statement. Note that I have made a version of the IX_textnames.py with the name "n.py". I made this program callable from the terminal command line by using the "chmod" command. I have included the "shebang comment" as the first line of the n.py so that it can be used in bash commands in terminal mode. For me, this facilitates listing most of the notable names included in any IX_package. To list the names of all functions in the IX_package named IX_textpack_pkg.py (in the current folder), I only need to type the command shown below:
>$ ./n.py < IX_textpack_pkg.pyDon't forget to include the "<" when using "n.py" (as I often forget to type it.) It took me considerable research to discover that I needed to prefix the "n.py" with "./" for the "shebang" (aka "hashbang" ) to work.
pi@raspberrypi:~/Desktop $ ./n.py < adcRead_pkg.py #::: Be sure to precede the Pkg name with a "<". #::: n.py v03 reports the def's adcRead_pkg.py def MUX(n): def swap2Bytes(c): def prepareLEconf(BEconf): def LEtoBE(c): def BEtoLE(c): def resetChip(RESET_ADDRESS, RESET_COMMAND): def alerted(self, arg): def do_q(self, arg): def mydo_1(self,BUS,AINn): def shutdown(self): def adcRead(BUS,nChannel=0) : def adcReadInit(I2C_BUS=1,icNumber="ADS1115") : #::: end of list of nShowDefs.pyIt is interesting to see that some of the "def"s listed above have a first argument of "self". These "def"s are methods defined for a class (even though the "class" statement might not listed.)
./n.py -h < adcRead_pkg.pyThis is the "help: command for the IX_textpack_pkg.py system. It will return the following:
>$ ./n.py -h any >$ >$ #:::: Help for python n.py [IX pkg nameslist.py prgm] >$ #:::: Syntax: ./n.py [args] < pkg >$ #:::: args=acdghimosuv_ >$ #:::: a:all,c:class,d:def,g:global,h:help,i:import,m:marker,o:OReilly,s:source:, u:used functions,v:v_ versions eg ixv_",_:"__" Dunder-names (Source 17) >$ #:::: marker is #:::::::::textpak=> >$ $:::: NB Use IX_textpack.py to create a package. >$ $:::: ( Cudos to O'Reilly for textpack.py ) >$
pi@raspberrypi:~/Sandbox $ python3 n.py -md < adcRead_pkg.py #::: Enhanced n.py v02 [IX pkg names list prg -h for help]: # 1 m adcRead_pkg.py # 26 def MUX(n): # 34 def swap2Bytes(c): # 39 def prepareLEconf(BEconf): # 45 def LEtoBE(c): # 53 def BEtoLE(c): # 60 def resetChip(RESET_ADDRESS, RESET_COMMAND): # 83 def alerted(self, arg): # 90 def do_q(self, arg): # 94 def mydo_1(self,BUS,AINn): # 143 def shutdown(self): # 151 def adcRead(BUS,nChannel=0) : # 200 def adcReadInit(I2C_BUS=1,icNumber="ADS1115") : # 230 eof #::: end of list by n.py v02Another improvement is that n.py can list the functions that are called by each of the routines in the package. This can be a very long list. An effort has been made to exclude the most-common standard Python functions from this list. The list is called the used-function list. By not listing the Python-defined functions, the remaining functions listed are primarily those that are defined in the routines that are imported. An example of the output excluding the 'used functions" is shown below:
pi@raspberrypi:~/Sandbox $ python3 n.py -a < adcRead_pkg.py #::: Enhanced n.py v02 [IX pkg names list prg -h for help]: # 1 m adcRead_pkg.py # 9 import cmd, time, logging, smbus, RPi.GPIO as GPIO # 11 #Source: https://smartypies.com/projects/ads1115-with-raspberrypi-and-python/ads1115runner/ #DC # 16 # BUS = adcReadInit(I2C_BUS,icNumber) # create BUS class object # 26 def MUX(n): # 34 def swap2Bytes(c): # 39 def prepareLEconf(BEconf): # 45 def LEtoBE(c): # 53 def BEtoLE(c): # 60 def resetChip(RESET_ADDRESS, RESET_COMMAND): # 65 class ADS1115Runner(cmd.Cmd): # 83 def alerted(self, arg): # 90 def do_q(self, arg): # 94 def mydo_1(self,BUS,AINn): # 129 global g_adcValue # 143 def shutdown(self): # 149 #class end ADS1115Runner() # 151 def adcRead(BUS,nChannel=0) : # 162 #Source: https://smartypies.com/projects/ads1115-with-raspberrypi-and-python/ads1115runner/ #DC # 173 # GPIO. for ALERTPIN class is not used #DC # 192 global g_adcValue # 200 def adcReadInit(I2C_BUS=1,icNumber="ADS1115") : # 203 # usage of global variables # 204 # global g_adcValue # 230 eof #::: end of list by n.py v02The small additions are the "import", "class" and "source:". Even the class methods can be identified by their first argument of "self". Even the names of the "passed parameters" are visible. The occassional line of "noisy" information appears (such as the word "class" in the "GPIO" line. But the truly useful information outweighs this noise, imho.) The output generated by n.py that includes the used-functions can be quite long. Below, I will only cite the functions used (called) by the class. The functions used (called) by the methods defined by the class definition are:
# 65 class ADS1115Runner(cmd.Cmd): # 65 ADS1115Runner() # 66 cmdloop() # 68 cmdLoop() # 78 do_1() # 78 do_2() # 83 alerted() # 83 def alerted(self, arg): # 85 read_word_data() # 88 alerted() # 90 do_q() # 90 def do_q(self, arg): # 92 do_q() # 94 mydo_1() # 94 def mydo_1(self,BUS,AINn): # 106 resetChip() # 107 write_byte() # 112 prepareLEconf() # 114 MUX() # 115 prepareLEconf() # 119 write_word_data() # 124 read_word_data() # 125 LEtoBE() # 129 global g_adcValue # 130 adcRead() # 132 test_adcRead() # 141 mydo_1() # 143 shutdown() # 143 def shutdown(self): # 147 shutdown() # 149 #class end ADS1115Runner()The output shown above is the actual uneditted output from n.py. It is truly remarkable how good an overview one gets when all of the "used" functions are listed in the order that they are called. If one is familiar with the nature of the purpose of the class definition, the overview is very informative.
a all (a: outputs all except "u") (all outputs all info including "u") c class d def g globals h help i imports m marked files o O'Reilly-marked files s sources (Source:) u used-functions (routines called) v version definition "v_" e.g. "ixv_=3" _ double underscore ("__" e.g. __name__ or __init__ )The amount of information that can be produced is truly impressive. The command list can contain an underscore (i.e. "_"). This is not included in "a" nor in "all". But "_" can be combined with any other command line letters. Very few of my programs make use of the "__" system variables. But the "_" commmand is available to search for "__" variables if needed by anyone in the future.
#def functionList(testStr="", v="") : #pass; ixv_=3 #returnValue=functionList_v03(testStr) #if v=="?" : return returnValue,ixv_ #return returnValue #def end #def functionList_v03( testStr) : # by D@CC on 2022DApr07 #. . . . #. . . . function definition statements go here # . . . . #return anyValue #def end functionList_v03 def mainroutine() : #main program used to test the functionList function from functionList_pkg import functionList ixv_=17 #ixv_ is the version of t.py line="abc = aStr(1000*unixTime() ) + bigI(333)" print("line:"+line+":") fList=functionList(line) for x in fList : # python3 is needed for end= below print(x, end=" " ) #for end print() print("vsn of t.py: ",ixv_) print( "vsn of functionList: ", functionList("",v="?")[1]) return #def end if __name__ == '__main__' : mainroutine() #end of t.py ixv_=17
In the above program, note that:
1. The main program does not include the version number of the function named "functionList". 2. The main program does not need to cite the extra (last) argument, the version number. 3. The version number of "functionList" can be obtained and output. 4. The program references "functionList" but the actual function used is "functionList_v03". 5. The actual version number "3" appears in source code mandatorily in only 2 "nearby" places. 6. The above program will print: >$ line:abc = aStr(1000*unixTime() ) + bigI(333): >$ aStr unixTime bigI >$ vsn of t.py: 17 >$ vsn of functionList: 3
GENERAL-PURPOSE MODULES Module returns calls/Uses args ******************** ********* ********** ******* acquire_buttonPush() 0 if Down obj GPIO btn_pin acquire_digIn0() 1 if High obj GPIO btn_pin acquire_piIP() IPstr osCommand() none acquire_piOS() OSstr osCommand() none acquire_piSN() SNstr osCommand() none acquire_procTemp() Tempstr(C) osCommand() none add_event_detect() na obj GPIO comment askVerbose() False if Verbose input() isQuerrying control_audioTV() na osCommand() sound fileName control_digOut0() na obj GPIO do_pin,onOne control_piArea() na g_piAreaStr roomStr control_redLED() na obj GPIO pin,onOne helloTask() na na na informUserWait() na time isVerbose,DT,down5 isLogAvailable() na os,askVerbose logfileName manageTasks() na g_startTimeArray na osCommand() reply os, g_fileArray commandStr queuehelloTask() na g_startTimeArray, na g_hellloTaskNumber, unixTime() sortableDateTime() DateTime str time. parts timeIn unixTime() tStr time. str() na PYTHON & EXTERNAL MODULES Module returns calls/Uses args ******************** ********* ********** ******* .exists() True if exists os.path. fileName .input() True if HIGH obj GPIO. pin .isnumeric() True if digits anyStr. na .output() na obj GPIO. pin,1/0 .setmode() na obj GPIO. p/b .setup() na obj GPIO. pin,I/O,i=1 .strftime() str time. %Y &m etc PiR2-SPECIFIC MODULES Module returns calls/Uses args ******************** ********* ********** ******* appendToLog() pir2-specific array() pir2-specific control_fromOwner() pir2-specific createLogCopy() pir2-specific createNewEmptyLogTask() pir2-specific displayHeader() pir2-specific displayLog() pir2-specific getControl_fromOwner() pir2-specific getsize() pir2-specific identifyTask() pir2-specific initializeTask() pir2-specific openLog2() pir2-specific piR2_attrFromStr() pir2-specific pir2_convertMIC_ControlTask() pir2-specific piR2_findStrInArray() pir2-specific pir2_initGPIO() pir2-specific piR2_ioDeviceAttribute() pir2-specific pir2_performAorC() pir2-specific pir2versions() pir2-specificThe modules listed above include both general-purpose functions that can be used elsewhere and specific modules for the PiR2 control system. This list was created using routines n.py and stripWord1.py A description of each general-purpose function will be added at a later date.