0

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
========================================================================
3
  • Could you post your code? Commented Dec 5, 2016 at 8:28
  • 1
    It looks like open() doesn't have such keyword: docs.python.org/2/library/functions.html#open But this can be told for sure only after you'll post your code. Commented Dec 5, 2016 at 8:36
  • And for that matter: csv is in the standard library. Commented Dec 7, 2016 at 20:53

1 Answer 1

2

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).

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

1 Comment

@dhke thanks for the tip! I will add it to the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.