''' To install modules like openpyxl or requests you have to open an admin-commandline (cmd.exe with admin privileges, right-click on cmd.exe and run with privilege guard) and go to your python folder There you run the command "python.exe -m pip install openpyxl" to install for example 'openpyxl' ''' # One line comment with # ''' Multi-Line comment with 3 Single ' (above the # key) Perfect ''' # Read in File and split in list lines = open("file.txt","r").read().splitlines() for line in lines: print(line) # Write File with open("out.txt","w") as file: file.write("TEXT HIER") # List files from directory import os directory = "C:\\" liste = os.listdir(directory) for el in liste: print(liste) # Create Directory if it doesn't exist yet (check if file exists) import os mypath = "web_folder" if not (os.path.exists(mypath)): os.mkdir(mypath) # Check for errors try: unbekannte_funktion() except: print("ERROR!") # Check for commandline arguments, if none exit program import sys if len(sys.argv) >= 2: name = sys.argv[1] print("Hi, im "+name) else: print("Usage: python3 filename.py name") sys.exit(0) # Create Excel File import openpyxl wb = openpyxl.Workbook() # Read-In Excel: # wb = openpyxl.load_workbook(filename="filename_here.xlsx") sheet = wb.active sheet["A1"] = "ID" for id in range(2,11): sheet["A"+str(id)] = id wb.save("test.xlsx") # Get Website import requests r = requests.get("https://example.com") print(r) #prints out http status code, 200 == successful print(r.text) #prints HTML of website as String # Globale Variablen # Wenn du eine Funktion hast, welche auf eine Variable ausserhalb zugreifen muss, dann muss man "global" benutzen import os story = "Beginn " def addText(text): global story story = story + text addText("Ende") print(story) # Grafiken Erstellen import matplotlib.pyplot as plt import random xlist = [] ylist = [] llist = [] #labels, describing x-axis ticks for i in range(1,11): xlist.append(i) ylist.append(random.randrange(1,11)) llist.append("Day "+str(i)) plt.figure(figsize=(10.4,4.8)) #sets the size of the image/canvas, 1040x480 pixel axes = plt.gca() axes.set_ylim([-1,11]) #Sets the range that is displayed #Even if there is no 10 or 1, it will display the graph from 1 to 10 on the y-axis(-1 and 11 for a fancier border) plt.plot(xlist, ylist) #draw graph plt.xticks(xlist, llist, rotation='vertical') #set x-axis text plt.ylabel('Y-Axis Description here (left side)') plt.title("Statistic Description here (ontop)") plt.tight_layout() plt.savefig("out.png",bbox_inches="tight") #end