Skip to content

how does the writer object work? #96

Description

@Niblick1020

I don't understand how the writer object works

how does it write to the files?

def write_files_to_csv(file_counts, output_file):
    """
    Writes filename and modification counts to CSV. Identifies the file with the highest modifications.
    - dictfiles: Dictionary {filename: modification count}.
    - file: Base name for the output CSV file.
    """
    fileOutput = 'data/file_' + file + '.csv'
    rows = ["Filename", "Touches"]
    fileCSV = open(fileOutput, 'w')
    writer = csv.writer(fileCSV)
    writer.writerow(rows)

    bigcount = None
    bigfilename = None
    for filename, count in dictfiles.items():
        rows = [filename, count]
        writer.writerow(rows)
        if bigcount is None or count > bigcount:
            bigcount = count
            bigfilename = filename
    fileCSV.close()
    print('The file ' + bigfilename + ' has been touched ' + str(bigcount) + ' times.')

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions