def main(): with open('data.csv', newline='') as csvfile: reader = csv.reader(csvfile, delimiter=' ', quotechar='|') for row in reader: items = row[0].split(",", 1) parameters = items[1].split(",") action = items[0] if action == 'CREATE': print(action, parameters) array = Array() elif action == 'DEBUG': array.debug_print() elif action == 'ADD': print(action, parameters) array.add(parameters[0]) elif action == 'SET': print(action, parameters) array.set(int(parameters[0]), parameters[1]) elif action == 'GET': print(action, parameters) array.get(int(parameters[0])) elif action == 'DELETE': print(action, parameters) array.delete(int(parameters[0])) elif action == 'INSERT': print(action, parameters) array.insert(int(parameters[0]), parameters[1]) elif action == 'SWAP': print(action, parameters) array.swap(int(parameters[0]), int(parameters[1])) else: print("Blow up!")
def array_runner(command, arg1, arg2): global a if arg1.isdigit(): arg1 = int(arg1) if arg2.isdigit(): arg2 = int(arg2) if command == 'CREATE': a = Array() elif command == 'DEBUG': a.debug_print() elif command == 'ADD': a.add(arg1) elif command == 'SET': a.set(arg1, arg2) elif command == 'GET': a.get(arg1) elif command == 'DELETE': a.delete(arg1) elif command == 'INSERT': a.insert(arg1, arg2) elif command == 'SWAP': a.swap(arg1, arg2) return []
arr = [] with open('data_csv.csv') as csv_file: csv_reader = csv.reader(csv_file, delimiter=',') for row in csv_reader: try: # if(row[0] == 'CREATE'): arr = Array(); continue # args = [x for x in [row[1], row[2]] if x != ''] # getattr(arr, row[0].lower())(*args) if(row[0] == 'CREATE'): arr = Array() continue elif(row[0] == 'DEBUG'): arr.debug_print() continue elif(row[0] == 'ADD'): arr.add(row[1]) continue elif(row[0] == 'SET'): arr.set(row[1], row[2]) continue elif(row[0] == 'GET'): print(arr.get(row[1])) continue elif(row[0] == 'DELETE'): arr.delete(row[1]) continue elif(row[0] == 'INSERT'): arr.insert(row[1], row[2]) continue elif(row[0] == 'SWAP'): arr.swap(row[1], row[2])
import csv from array_api import Array with open('data.csv', newline='') as csvfile: datareader = csv.reader(csvfile, delimiter=',') for i, row in enumerate(datareader): print(f'{i}:{row[0]},{row[1]},{row[2]}') if (row[0] == "CREATE"): array = Array() elif (row[0] == "DEBUG"): Array.debug_print(array) elif (row[0] == "ADD"): Array.add(array, row[1]) elif (row[0] == "SET"): Array.set(array, row[1], row[2]) elif (row[0] == "GET"): Array.get(array, row[1]) elif (row[0] == "INSERT"): Array.insert(array, row[1], row[2]) elif (row[0] == "DELETE"): Array.delete(array, row[1]) elif (row[0] == "SWAP"): Array.swap(array, row[1], row[2])
from array_api import Array, memcpy import csv with open('data.csv') as csvfile: reader = csv.reader(csvfile, delimiter=',') r = 0 for row in reader: command = row[0] if command == 'CREATE': array1 = Array() print('{}: {}'.format(r, ', '.join(str(e) for e in row))) elif command == 'DEBUG': array1.debug_print() print('{}: {}'.format(r, ', '.join(str(e) for e in row))) elif command == 'ADD': array1.add(row[1]) print('{}: {}'.format(r, ', '.join(str(e) for e in row))) elif command == 'GET': array1.get(int(row[1])) print('{}: {}'.format(r, ', '.join(str(e) for e in row))) elif command == 'SET': array1.set(int(row[1]),row[2]) print('{}: {}'.format(r, ', '.join(str(e) for e in row))) elif command == 'INSERT': array1.insert(int(row[1]),row[2]) print('{}: {}'.format(r, ', '.join(str(e) for e in row))) elif command == 'DELETE': array1.delete(int(row[1])) print('{}: {}'.format(r, ', '.join(str(e) for e in row))) elif command == 'SWAP': array1.swap(int(row[1]), int(row[2]))
def main(): print('working') output = open("output.txt", "w") with open('data.csv') as csv_file: arr = Array() csv_reader = csv.reader(csv_file, delimiter=',') line_count = 0 for row in csv_reader: if row[0] == 'CREATE': output.write( str(line_count) + ':' + str(row[0]) + ',' + str(row[1]) + ',' + str(row[2]) + '\n') arr.__init__ if row[0] == 'DEBUG': output.write( str(line_count) + ':' + str(row[0]) + ',' + str(row[1]) + ',' + str(row[2]) + '\n') output.write(arr.debug_print() + '\n') if row[0] == 'ADD': output.write( str(line_count) + ':' + str(row[0]) + ',' + str(row[1]) + ',' + '\n') try: print(row[1]) arr.add(row[1]) except: output.write(str(Exception) + '\n') if row[0] == 'SET': output.write( str(line_count) + ':' + str(row[0]) + ',' + str(row[1]) + ',' + str(row[2]) + '\n') try: arr.set(int(row[1]), row[2]) except: output.write(str(Exception) + '\n') if row[0] == 'GET': output.write( str(line_count) + ':' + str(row[0]) + ',' + str(row[1]) + ',' + '\n') try: arr.get(int(row[1])) except: output.write(str(Exception) + '\n') if row[0] == 'DELETE': output.write( str(line_count) + ':' + str(row[0]) + ',' + str(row[1]) + ',' + '\n') try: arr.delete(int(row[1])) except: output.write(str(Exception) + '\n') if row[0] == 'INSERT': output.write( str(line_count) + ':' + str(row[0]) + ',' + str(row[1]) + ',' + str(row[2]) + '\n') try: arr.insert(int(row[1]), row[2]) except: output.write(str(Exception) + '\n') if row[0] == 'SWAP': output.write( str(line_count) + ':' + str(row[0]) + ',' + str(row[1]) + ',' + str(row[2]) + '\n') try: arr.swap(int(row[1]), int(row[2])) except: output.write(str(Exception) + '\n') line_count += 1 output.close
from array_api import Array objectArray = Array() 'creating an object array' 'here I will do all the work' objectArray.add('11')
for i, cmd in enumerate(reader): try: print(f'{i}:{cmd[0]},{cmd[1]},{cmd[2]}') except: print('Error: Invalid CSV syntax') if cmd[0] == 'CREATE': arr = Array() elif cmd[0] == 'DEBUG': arr.debug_print() elif cmd[0] == 'ADD': arr.add(cmd[1]) elif cmd[0] == 'SET': arr.set(int(cmd[1]), cmd[2]) elif cmd[0] == 'GET': print(arr.get(int(cmd[1]))) if arr.get(int(cmd[1])) else 0 elif cmd[0] == 'DELETE': arr.delete(int(cmd[1])) elif cmd[0] == 'INSERT': arr.insert(int(cmd[1]), cmd[2]) elif cmd[0] == 'SWAP': arr.swap(int(cmd[1]), int(cmd[2]))