user5539322
user5539322

Reputation:

Getting TyperError when trying to print as CSV in Python?

I attached the python script above.

I am trying to print out the information I need in to a csv. Whenever I attempt this, I get a TypeError: 'newline' is an invalid keyword argument for this function'. I am very new to python so I'm not sure how to address this (or if there are other issues in the script).

#print(teams)
with open('players.csv', 'w', newline='') as csvfile:
    writer = csv.writer(csvfile, delimiter=',',
                        quotechar='|', quoting=csv.QUOTE_MINIMAL)
    for row in teams:
        writer.writerow(row)

Upvotes: 0

Views: 33

Answers (2)

Mark Tolonen
Mark Tolonen

Reputation: 177675

In Python 2, use 'wb' instead of newline='' to achieve the same effect. Python 3 uses the latter.

Upvotes: 1

William
William

Reputation: 2935

You are using Python 2, and the open function has no newline argument.

You should use Python 3 in order to use that argument. See the new open documentation.

Upvotes: 2

Related Questions