5

I'm trying to run a short sorting program I wrote in Python, but I'd like to call the program in a Swift macOS application. The program is designed to take a large csv file and sort it for some hard-coded criteria. I'd like to be able to do this all without using the command line and have a very simple mac OS application UI.

This is a snapshot of the program:

def add_data(qualifiers_master,data):

    # Set the right parameters
    base_counter = 2
    index_counter = 7
    iterations = len(qualifiers_master)

    # Create a masterList for the data to be contained
    master_list = []

    # Grab dictionary
    for qualifier in qualifiers_master:
        for row_num in range(4,len(data)):

            # Counter for iterations of parameters in the report
            if iterations > 0:

                #
                # Create the clean data in strings
                #
                # This looks bad but its just filtering out the punctuation
                base_count_number = ''.join([i for i in data[row_num][base_counter] if i.isdigit() == True])
                try:
                    base_count = int(base_count_number)
                except ValueError:
                    pass
                market_index_number = ''.join([i for i in data[row_num][index_counter] if i.isdigit() == True])
                try:
                    market_index = int(market_index_number)
                except ValueError:
                    pass
                # Cleaning ZipCode
                zip_code = str(data[row_num][0])

            # Filter for lower than 120 BaseCount

            try:
                if int(market_index) >= 120:

                    # Begin creating a dictionary to add to the master_list container
                    working_dict={}

                    working_dict['name'] = qualifier
                    working_dict['baseCount'] = base_count
                    working_dict['marketPotentialIndex'] = market_index
                    working_dict['zipCode'] = zip_code

                    master_list.append(working_dict)

                    working_dict={}
            except ValueError:
                pass

        # Maintaining the indexes for the data
        base_counter += 6
        index_counter += 6
        iterations -= 1

    return master_list



def main():

    import pandas as pd

    file_name = input('What is the name of the file?\n') 
    print("Thanks! I'm gonna sort it now for you...")`
Grisha Levit
  • 8,194
  • 2
  • 38
  • 53
  • better use some Python GUI - tkinter, wxPython, PyQt. – furas Jan 27 '17 at 03:27
  • You can launch the python interpreter with [`Process`](https://developer.apple.com/reference/foundation/process), and have it run any python code you want. – Alexander Jan 27 '17 at 04:01
  • I would investigate the C API for calling Python. This should be usable from Swift. See http://stackoverflow.com/questions/1056051/how-do-you-call-python-code-from-c-code – Gary Makin Jan 27 '17 at 04:22
  • http://stackoverflow.com/questions/41864930/use-multiple-launch-paths-to-run-terminal-command-swfit – muescha Jan 27 '17 at 05:31
  • http://stackoverflow.com/questions/41881406/how-to-delete-an-element-that-contains-a-letter-in-array-using-swift – muescha Jan 27 '17 at 05:31

0 Answers0