Reputation: 63
I keep getting an "invalid keyword" error when i try to read from a csv file in python. Any ideas for a work around for this?
C:\Python27\python.exe C:/Users/User_Name/PycharmProjects/untitled/car.py
Traceback (most recent call last): File
"C:/Users/User_Name/PycharmProjects/untitled/car.py", line 122, in <module> d = handle_refugee_data.DataTable(csvformat="generic", data_directory="car2014", start_date="2013-12-01") File
"C:\Users\User_Name\PycharmProjects\untitled\handle_refugee_data.py", line 78, in __init__ with open("%s/%s" % (data_directory, data_layout), newline='') as csvfile:
TypeError: 'newline' is an invalid keyword argument for this function
Process finished with exit code 1
========================================================================
Upvotes: 0
Views: 111
Reputation: 17003
newline
is a valid keyword argument to open()
in Python 3, but not in Python 2, which appears to be what you are using.
One solution, if possible, would be to execute the script with Python 3 instead. Alternatively, as pointed out by @dhke in the comments, you could use io.open()
instead, which does accept a newline
keyword argument.
Of course, you could probably use the csv
module instead, depending on your use case (which is not clear from the original question).
Upvotes: 2