Table of Contents

Python language

Python scripts and modules

Language basics

data types, variables, operators

if statements and loops

complex types

functions

handling exceptions

classes

modules

files and directories

from  pathlib import Path
path = Path() # this will reference the current folder
path = Path("foldername") # this will reference a relative folder
path.exists()
path.mkdir() # creates the folder
path.rmdir() # deletes the folder
for file in  path.glob('*') 
  print(file) # lists the contents of the folder
for file in path.glob('*.py')
  print(file)  # lists the python files in  the folder

Pypi and pip

Example manipulating an Excel spreadsheet

import openpyxl as xl
from openpyxl.chart import BarChart, Reference

wb = xl.load_workbook("spreadsheetfilename")
sheet = wb['Worksheetname'] #case sensitive!
cell = sheet['a1'] # this will also give same result: cell = sheet.cell(1,1)
print(cell.value)
for row in range(1,sheet.max_row + 1)
  cell = sheet.cell(row, 3) #get 3rd cell column
# now add a chart:
values = Reference(sheet,min_row=2, max_row=sheet.max_row, min_col=4, max_col=4) #skip 1st row as contains column titles and only use data in column 4
chart = BarChart()
chart.add_data(values)
sheet.add_chart(chart, 'e2') #places chart upper left corner at e2
wb.save('newfilename')

commonly used basic Python libraries