Plutonic Rainbows

Using Functions to do Maths

Mathematics isn't really something I'm good at but luckily, Python makes it easy when using functions. I'm also using .format to correctly show decimal places - as well as # -*- coding: utf-8 -*- so that Python can print currency symbols..

# -*- coding: utf-8 -*-
def add(a, b, c):
    print "\nADDING %d + %d + %d" % (a, b, c)
    return a + b + c

price = add(12, 12, 12);print "The price is £{0:.2f}\n".format (price)

def multiply(a, b):
    print "MULTIPLYING %d * %d" % (a, b)
    return a * b

multiply_price = multiply(10, 10);print "The price is £{0:.2f}\n".format (multiply_price)

def subtracting(a, b):
    print "SUBTRACTING %d - %d" % (a, b)
    return a - b

subtract_price = subtracting(100, 50);print "The price is £{0:.2f}\n".format (subtract_price)

def division(a, b):
    print "DIVIDING %d / %d" % (a, b)
    return a / b

division_price = division(90, 2);print "The price is £{0:.2f}\n".format (division_price)

Rewinding

This will not sink in. Have to keep looking at it over and over again. I'm just not clever enough, I think. The only way to make it stick is to look at the previous variables etc.

from sys import argv

script, input_file = argv

def print_all(f):
    print f.read()

def rewind(f):
    f.seek(0)

def print_a_line(line_count, f):
    print line_count, f.readline()

current_file = open(input_file)

print "First let's print the whole file:\n"

print_all(current_file)

print "\nNow let's rewind. Just like a tape."

rewind(current_file)

print "Let's print three lines:\n"

current_line = 1
print_a_line(current_line, current_file)

current_line = current_line + 1
print_a_line(current_line, current_file)

current_line = current_line + 1
print_a_line(current_line, current_file)

print "\n"

Defining a Function

Ended the week with revision. Have to build this into learning if I want to remember what I've studied.

Defining a function:

def print_three(arg1, arg2, arg3):
    print "Name: %r, Surname: %r, Country: %r" % (arg1, arg2, arg3)

print_three("Elle", "Macpherson", "Australia")

Copying Files

Learning how to copy files with Python. The script also checks the file size in bytes.

from sys import argv
from os.path import exists

script, from_file, to_file = argv

print "Let's copy from %s to %s." % (from_file, to_file)

in_file = open(from_file)
indata = in_file.read()

print "The size is %s bytes in length." % len(indata);
print "Does the target file exist? %r" % exists (to_file)

raw_input()

out_file = open(to_file, 'w')
out_file.write(indata)

in_file.close()
out_file.close()

print "All done."

Kuniyuki Takahashi - Early Tape Works 1986 - 1993 Volume 1

Bleep:

The Amsterdam crew delve deep into the archives of Japanese deep house sensation Kuniyuki to bring us six entrancing early compositions. MFM027 collects some of the choice early recordings from a man known for his expert sound design and earthy, percussive leaning dance tracks. The songs that Tako & Jamie Tiller have opted for show a rough and slightly amateur sounding approach to the stylistic traits that would go on to define a career. Blurring the lines between kosmiche, ambient, dub and electro this record is top quality as you’ve no doubt come to expect from the label.

Vinyl & Digital from Bleep