Вы находитесь на странице: 1из 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 (A,a,b):
temp = A[a]
A[a] = A[b]
A[b] = temp

Вам также может понравиться