Note that there are some explanatory texts on larger screens.

plurals
  1. POError while editing many CSV files
    primarykey
    data
    text
    <p>I asked this question a few days ago because I needed help with editing some CSV files: <a href="https://stackoverflow.com/questions/18257999/fix-numbering-on-csv-files-that-have-deleted-lines/18258274?noredirect=1#comment26921500_18258274">Fix numbering on CSV files that have deleted lines</a>. The people of Stack Overflow helped me out a great deal however I keep getting an error saying <code>AttributeError: 'int' object has no attribute 'strip'.</code> The problem is that all the information in my CSV files are not integers. Being the python newbie that I am, a few days of trying to fix it only made things worse. Here is what I have from my previous question that gives me the error: </p> <pre><code>import csv import glob import os import re numbered = re.compile(r'N\d+').match for fn in fns: # open for counting reader = csv.reader(open(fn,"rb")) count = sum(1 for row in reader if row and not any(r.strip() == 'DIF' for r in row) and numbered(row[0])) # reopen for filtering reader = csv.reader(open(fn,"rb")) with open (os.path.join('out', fn), 'wb') as f: counter = 0 w = csv.writer(f) for row in reader: if row and 'Count' in row[0].strip(): row = ['Count', count] if row and not any(r.strip() == 'DIF' for r in row): #remove DIF if numbered(row[0]): counter += 1 row[0] = 'N%d' % counter w.writerow(row) </code></pre> <p>The code is essentially supposed to run through a bunch of CSV files and delete all the lines that have 'DIF' in them and fix the numbering due to deleted lines. Does anyone have any suggestions?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload