def main():
    with open(FILE_INPUT) as input_file:
        # with open(FILE_OUTPUT, 'w') as output_file:
        # sys.stdout = output_file
        csv_reader = csv.reader(input_file, delimiter=',')
        line = 0

        for row in csv_reader:
            command = row[0]
            param_one = row[1]
            param_two = row[2]

            # print line number and command
            print('{}:{},{},{}'.format(line, command, param_one, param_two))

            # call appropriate method based on command
            if command == 'CREATE':
                arr = Array()
            else:
                exec_command(command, arr, param_one, param_two)

            line += 1
示例#2
0
from array_api import Array
import csv

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])
示例#3
0
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]))
示例#4
0
文件: main.py 项目: tomirisr/Arrays
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])
示例#5
0
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
示例#6
0
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 []
示例#7
0
from array_api import Array

objectArray = Array()
'creating an object array'

'here I will do all the work'

objectArray.add('11')
示例#8
0
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!")
示例#9
0
arr = None

with open(DATA_FILE, 'r') as csv_file:

    reader = csv.reader(csv_file)

    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]))