Table of Contents

Python

create window usb install

sudo apt update
sudo apt install git p7zip-full python3-pip python3-wxgtk4.0

sudo pip3 install WoeUSB-ng --break-system-packages

Run woeusb from the application menu

error: externally-managed-environment

pip install <package-name> --break-system-packages

Testing for odd

num = 7
if num % 2 != 0:
    print(f"{num} is odd.")

Lists

Importing code

Range

# print 0 - 4
for i in range(5):
    print(i)

Passing Variables

    def incrementXyzzy():
       xyzzy = xyzzy + 1
    #does not work because xyzzy is a local created on the fly   
    def incrementXyzzy(xyzzy):
       xyzzy = xyzzy + 1
    #xyzzy is passed in and can be incremented. it will be returned   
    def incrementXyzzy(xyzzy):
       xyzzy = xyzzy + 1
    return xyzzy   #explict return is better
    #xyzzy is passed in and can be incremented. it will be returned   
    xyzzy = incrementXyzzy(xyzzy):

    #the calling function MUST assign the returned value   

Read Csv

Lists

Pip

error: externally-managed-environment

This environment is externally managed To install Python packages system-wide, try apt install python3-xyz, where xyz is the package you are trying to install.

If you wish to install a non-Debian-packaged Python package, create a virtual environment using python3 -m venv path/to/venv.

Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make sure you have python3-full installed.

For more information visit http://rptl.io/venv

Files

file_path = 'randomfile.txt'
file_text = open(file_path, "r")
a = True
while a:
    file_line = file_text.readline()
    if not file_line:
        print("End Of File")
        a = False
file_text.close()
file = open("randomfile.txt", "r")

while (f := file.read()):
    process(f)

file.close()

Packages