[Tutor] str.replace error
Roger Lea Scherer
rls4jc at gmail.com
Thu Apr 25 13:46:31 EDT 2019
I'm working wtih python 3.7 on Windows 10.
I'm trying to write some code in order to clean up the data in the csv file.
Using spreadsheet language, I want to replace part of a cell ("Basic P1")
with an empty string and write it in the comments cell.
I thought assigning a variable and replacing the string would be a good
idea.
Here is my code:
import csv
with open('somefile') as csvDataFile:
csvReader = csv.reader(csvDataFile)
for row in range(100):
a = "Basic P1"
str.replace(a, "")
print(next(csvReader))
I get an error:
Traceback (most recent call last):
File "somefile", line 7, in <module>
str.replace(a, "")
TypeError: replace() takes at least 2 arguments (1 given)
But I think I have 2 arguments: a being the "old" argument as per the
documentation, "" being the "new" argument as per the documentation.
What am I missing?
--
Roger Lea Scherer
623.255.7719
*Strengths:*
Input, Strategic,
Responsibility,
Learner, Ideation
More information about the Tutor
mailing list