Re: [Tutor] str.replace error

2019-04-26 Thread Mats Wichmann
On 4/25/19 10:29 PM, Steven D'Aprano wrote: > On Thu, Apr 25, 2019 at 10:46:31AM -0700, Roger Lea Scherer wrote: > >> with open('somefile') as csvDataFile: >> csvReader = csv.reader(csvDataFile) >> for row in range(100): >> a = "Basic P1" >> str.replace(a, "") >>

Re: [Tutor] str.replace error

2019-04-26 Thread Alan Gauld via Tutor
On 26/04/2019 05:29, Steven D'Aprano wrote: > (deliberately? accidently?) run into one of the slightly advanced > corners of Python: unbound methods. Ooh, good catch. I completely forgot that the string class' name is str... That's why he didn't get a name error... -- Alan G Author of the

Re: [Tutor] str.replace error

2019-04-25 Thread Steven D'Aprano
On Thu, Apr 25, 2019 at 10:46:31AM -0700, Roger Lea Scherer wrote: > with open('somefile') as csvDataFile: > csvReader = csv.reader(csvDataFile) > for row in range(100): > a = "Basic P1" > str.replace(a, "") > print(next(csvReader)) I'm not quite sure what you

Re: [Tutor] str.replace error

2019-04-25 Thread Alan Gauld via Tutor
On 25/04/2019 18:46, Roger Lea Scherer wrote: > Here is my code: > > import csv > > with open('somefile') as csvDataFile: > csvReader = csv.reader(csvDataFile) > for row in range(100): what happens if there are more rows in the file than 100? Or even if there are less!? > a =

[Tutor] str.replace error

2019-04-25 Thread Roger Lea Scherer
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