Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New header row added to CSV each time the script is run #3

Open
DanOBrien opened this issue Aug 21, 2019 · 0 comments
Open

New header row added to CSV each time the script is run #3

DanOBrien opened this issue Aug 21, 2019 · 0 comments

Comments

@DanOBrien
Copy link

DanOBrien commented Aug 21, 2019

We only need to write the headers once, so if we modify the "write" block to see if this is the first time we're writing the CSV, we don't keep seeing headers added to the file when we've gone back to add new books:

if len(new_additions) > 0:
    with open(filename, 'a') as csvfile:
        writer = csv.DictWriter(csvfile, fieldnames=fields)
        if current_ID == 1:
            writer.writeheader()
        for item in new_additions:
            writer.writerow(item)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant