0

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)
3
  • remove , newline='' Commented Nov 8, 2015 at 13:47
  • Indeed, newline is not a valid parameter to the open function. What makes you think it is? Commented Nov 8, 2015 at 13:49
  • 2
    nevermind, I think the problem is actually the python version you are using: you should use python 3 in order to have the newline argument, you probably are using python 2 Commented Nov 8, 2015 at 13:49

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments