title: Search in DBF and update record
body: <p>Code:</p>
  
  <pre><code>#!/usr/bin/python
  db = dbf.Dbf("MEST2.DBF")
  #LINE TO UPDATE:
  rec = db[0]
  #PROEST IS A field of my dbf. I'm assigning 1 to this field line 0
  rec["PROEST"] = 1
  rec.store()
  del rec
  db.close()
  </code></pre>
  
  <p>IMAGE OF DBF TABLE: <a href="http://i.stack.imgur.com/1UHE1.jpg" rel="nofollow">http://i.stack.imgur.com/1UHE1.jpg</a></p>
  
  <p>My problem is I can not change the records by rows, cause the position of the products (PROCOD) may vary.</p>
  
  <p>Any suggestions to get the PROCOD and change the value of PROEST?</p>
  
  <p><strong>UPDATED:</strong></p>
  
  <pre><code>#!/usr/bin/python
  
  import dbf
  db = dbf.Table('MEST2.DBF')
  with db:
      procod_idx = db.create_index(lambda rec: (rec.codigo, rec.procod))
      match = procod_idx.search(match='000001')
  
      # should only be one product with that code
      record = match[0]   
      with record:
          record.proest = 23
  </code></pre>
  
  <p>But the question now is, how i edit the value based on the CODIGO field (Stock code). I have multiples stocks ID: (1, 2, 5, 11). The code update just the first result, i need update a specific record based in the CODIGO FIELD. </p>
  
  <p>In SQL would be: "UPDATE PROEST SET 32 where CODIGO=11"... or CODIGO=2</p>
  
  <p><strong>SOLVED</strong> by Ethan Furman</p>
  
  <pre><code>#!/usr/bin/python
  
  import dbf
  db = dbf.Table('MEST2.DBF')
  with db:
      procod_idx = db.create_index(lambda rec: (rec.codigo, rec.procod))
      match = procod_idx.search(match=(11, '000001'))
      record = match[0]
      with record:
          record.proest = 25
          record.dt_atualiz = '14/07/15 16:52'
  </code></pre>