Skip to content

Instantly share code, notes, and snippets.

@richardbwest
richardbwest / csvread.py
Last active May 22, 2018 10:50
Python CSV Reader Simple Example
import csv
f = open('scores.csv','r')
reader = csv.reader(f) #Start the reader engine
scorelist = [row for row in reader] #Get all the rows from the file read them into a 2d list
#Just to prove that it has worked, let's print out the list in a pretty manner.
#Using list unzipping like this makes your program really easy to read.
for fname,lname,score in scorelist:
print("First name:", fname, "Last name:",lname,"Score:",score)
@richardbwest
richardbwest / scores csv
Created May 22, 2018 10:17
Example of a simple csv file of first names, last names and scores....
bob,jones,20
fred,wilson,30
sarah,smith,100
harry,harrington,5000
bill,billington,300
@richardbwest
richardbwest / scores.csv
Last active May 22, 2018 10:16
Example of a simple CSV File
bob jones 20
fred wilson 30
sarah smith 100
harry harrington 5000
bill billington 300
@richardbwest
richardbwest / pythonfileread.py
Created May 16, 2018 13:10
Reading the contents of a file into a Python program
#Open a file and print out all the contents.
f = open("myfile.txt","r")
for line in f:
print("line)
#Read one light from the file and save it to a variable.
f = open("highscore.txt","r")
score = f.readline()
import mcpi.minecraft as minecraft
import mcpi.block as block
import time,math
mc = minecraft.Minecraft.create()
mc.postToChat("Rainbow World")
pos = mc.player.getTilePos()
import mcpi.minecraft as minecraft
import mcpi.block as block
import random, time
mc = minecraft.Minecraft.create()
mc.postToChat("Minecraft Volcano!")
mc.setBlocks(-100,0,-100,100,50,100,block.AIR)
@richardbwest
richardbwest / minecraftcircle.py
Created January 24, 2018 16:29
Draw a circle in minecraft using SIN and COS ready for drawing a working clock
import mcpi.minecraft as minecraft
import mcpi.block as block
import time,math
mc=minecraft.Minecraft.create()
#mc.player.setTilePos(1,1,1)
mc.setBlocks(0,0,0,100,100,100,block.AIR)
import time, os
os.system('clear')
print("*** Welcome to the month app ***")
month = input("What month is it?").lower()
# .lower() converts the input to lowercase e.g. January >>>> january
if month == "january":
print("Brr!!! It's cold in january")
elif month in ["july","august"]:
@richardbwest
richardbwest / ev3pythonwritingrobotprototype.py
Created May 18, 2017 14:07
A quick bit of code to test out a prototype design for a writing robot during school project week.
from ev3dev.ev3 import *
import time
a = LargeMotor('outA')
b = LargeMotor('outB')
c = MediumMotor('outC')
ANGLEMULTI = 15
def turnRight(x):
from microbit import *
#Let's create a baby pink color using analogue settings!
pin0.write_analog(1020)
pin1.write_analog(620)
pin1.write_analog(1020)