You are on page 1of 2

Writing to File

NB!!! import csv


def writeToFile (varA, varB...):
inFile = open ("name.csv", "w")
inFile.write (...)
inFile.close ()
return

Reading from File (csv)


def readFromFile (col):
A = []
inFile = open("name.csv", "r")
inCSVFile = csv.reader(inFile)
for value in inCSVFile:
a = float (value [col])
A.append (a)
inFile.close ()
return A

Reading from File (normal)


def readFromFile (col):
A = []
inFile = open("name.csv", "r")
for line in inFile:
data = line.split (",")
A.append (float(data[col]))
inFile.close ()
return A

Sorting Arrays
def sort (A):
size = len (A)
for i in range (0, size-1):
for j in range(i+1, size):
if A[j]> A[i]:
swop (A,i,j)
return A

Swop
def swop
temp
A[a]
A[b]

(A,a,b):
= A[a]
= A[b]
= temp

You might also like