Write a code saved as a CSV file
with open(outputFile, 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
for item in sortsim:
writer.writerow([item[0], item[1], item[2]])
Something’s wrong
Traceback (most recent call last):
File "/data/ml/shan-als.py", line 54, in <module>
with open(outputFile, 'w', newline='') as csvfile:
TypeError: 'newline' is an invalid keyword argument for this function
Guess is the reason for the version, plus the version of judgment.
Py2 can use ‘WB’, PY3 can use newline = ‘.
import sys
if sys.version >= '3':
with open(outputFile, 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
for item in sortsim:
writer.writerow([item[0], item[1], item[2]])
else:
with open(outputFile, 'wb') as csvfile:
writer = csv.writer(csvfile)
for item in sortsim:
writer.writerow([item[0], item[1], item[2]])
Read More:
- TypeError: drop() got an unexpected keyword argument ‘columns’
- python got an unexpected keyword argument
- TypeError(‘Keyword argument not understood:‘, ‘***‘) in keras.models load_model
- Python error prompt: typeerror: ‘builtin’_ function_ or_ method‘ object is not subscriptable
- Python about typeerror: required argument ‘mat’ (POS 2) not found error resolution
- Python oserror: [errno 22] invalid argument: solution
- Syntax error: typeerror: this.getoptions is not a function an error is reported when the. SCSS file is imported globally
- Typeerror: write() argument must be STR, not bytes and the method of writing binary file in Python 3
- Typeerror: write() argument must be STR, not bytes and the method of writing binary file in Python 3
- Solve the oserror: [errno 22] invalid argument: ‘u202ad’ in Python
- [Qt] error: call to non-static member function without an object argument
- OS error reported by Python: [errno 22] invalid argument
- TypeError: descriptor ‘__init__‘ of ‘super‘ object needs an argument
- After introducing sass into Vue project, start to report error typeerror [err]_ INVALID_ ARG_ Type]: the “path” argument must be of type string
- An import error is reported in the python. The solution to setting. Pylintrc is invalid
- Error reported in Python reading file oserror: [errno 22] invalid argument: ‘u202ac: \ \ users \ \ yyqhk \ \ desktop \ \ 1. CSV’
- “Typeerror: invalid dimensions for image data” in Matplotlib drawing imshow() function
- AngularJS–[ng:areq] Argument ‘xxCtrl’ is not a function, got undefined! Error (Fixed)
- TypeError: connection.connect is not a function
- JS error – typeerror: XXX is not a function