User Tools

Site Tools


python

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
python [2024/10/31 19:57] – created - external edit 127.0.0.1python [2026/04/28 16:34] (current) – [error: externally-managed-environment] donald
Line 1: Line 1:
 ====== Python ====== ====== Python ======
 +
 +===== create window usb install =====
 +
 +=== Using WoeUSB-NG (Recommended GUI) ===
 +<code>
 +sudo apt update
 +sudo apt install git p7zip-full python3-pip python3-wxgtk4.0
 +
 +sudo pip3 install WoeUSB-ng --break-system-packages
 +</code>
 +
 +Run woeusb from the application menu
 +
 +===== error: externally-managed-environment =====
 +
 +<code>
 +pip install <package-name> --break-system-packages
 +</code>
 +
 +===== Testing for odd =====
 +
 +<code>
 +num = 7
 +if num % 2 != 0:
 +    print(f"{num} is odd.")
 +</code>
 +
 +===== Lists =====
 +
 +  * Lists are Python's version of arrays.
 +  * They are mutable and zero based indexed.
 +  * list = ['tom', 'dick', 'harry']
 +  * if 'tom' in list returns true
 +
 +===== Importing code =====
 +
 +  * from //machine import PIN// means get the PIN class from the file machine
 +  * from //ir_rx.nec import nec_8// means get the NEC_8 class from the file nec in the directory ir_rx
 +
 +===== Range =====
 +
 +  * Range is start, stop, step to generate a range of numbers
 +<code>
 +# print 0 - 4
 +for i in range(5):
 +    print(i)
 +</code>
 +
 +
 +
 +    
 +    
 +===== Passing Variables =====
 +
 +  *** Use classes!**
 +  * Python will not change what I think are global variables in functions.
 +  * If, for example, you have a variable xyzzy, and you reference it in a function, python creates a new one.
 +  * So you have to pass in xyzzy if you want to modify it.
 +  * You then have to return it explicitly, because Python returns the value of the last expression.
 +<code>
 +    def incrementXyzzy():
 +       xyzzy = xyzzy + 1
 +    #does not work because xyzzy is a local created on the fly   
 +</code>
 +
 +<code>
 +    def incrementXyzzy(xyzzy):
 +       xyzzy = xyzzy + 1
 +    #xyzzy is passed in and can be incremented. it will be returned   
 +</code>
 +
 +<code>
 +    def incrementXyzzy(xyzzy):
 +       xyzzy = xyzzy + 1
 +    return xyzzy   #explict return is better
 +    #xyzzy is passed in and can be incremented. it will be returned   
 +</code>
 +
 +<code>
 +    xyzzy = incrementXyzzy(xyzzy):
 +
 +    #the calling function MUST assign the returned value   
 +</code>
  
 ===== Read Csv ===== ===== Read Csv =====
Line 62: Line 145:
 file.close() file.close()
 </code> </code>
 +
 +==== Packages ====
 +
 +  * packages live in C:\Users\Donald\AppData\Local\Programs\Python\Python313\Lib\site-packages
 +  * a pip install of exifread appeared to work but did not create this package in the above directory
 +  * found it on Git, downloaded a zip, and copied the package to the site-packages directory
  
python.1730404634.txt.gz · Last modified: 2024/10/31 19:57 by 127.0.0.1