Table Append Problem - unable to coerce

64 views
Skip to first unread message

Vinicius Henrique

unread,
Jun 24, 2016, 10:20:43 AM6/24/16
to Python dBase
Hey, Guys!

I can't identify the problem in the code below:
Someone can help-me?
 
f = open('estoque.csv', 'r')
try:
    r = csv.reader(f)
    for row in r:
        p_id = row[1]
        qte = row[2]
        p_stock = row[4]
        
    table = dbf.Table('D:/Sensum/comercio/DADOS2/MEST2.DBF')# path of your dbf
    table.open()
    records=table.query('select *')
    add=1
    #updating
    if len(records)>11110:
            for record in records:
                    if record.procod!="" and record.codigo!=None and (int(record.procod) == int(p_id) and int(record.codigo) == int(p_stock)):
                            add=0
                            with record :
                                    record.proest = qte
                            break
    if add==1:
            #inserting
            print ("Not found, Inserting...")
            table.append((p_stock,str(p_id),qte,0,0,0,0,0,True,0,0,0,0,None,0))
            table.close()

    print ("[OK]")
        
finally:
    f.close() #cleanup


Erro:
Not found, Inserting...
Traceback (most recent call last):
  File "insert.py", line 46, in <module>
    table.append((p_stock,str(p_id),qte,0,0,0,0,0,True,0,0,0,0,None,0))
  File "C:\Python27\lib\site-packages\dbf\ver_2.py", line 5172, in append
    newrecord[index] = item
  File "C:\Python27\lib\site-packages\dbf\ver_2.py", line 2586, in __setitem__
    self.__setattr__(self._meta.fields[name], value)
  File "C:\Python27\lib\site-packages\dbf\ver_2.py", line 2569, in __setattr__
    self._update_field_value(index, name, value)
  File "C:\Python27\lib\site-packages\dbf\ver_2.py", line 2758, in _update_field
_value
    bytes = array('c', update(value, fielddef, self._meta.memo, self._meta.input
_decoder, self._meta.encoder))
  File "C:\Python27\lib\site-packages\dbf\ver_2.py", line 3504, in update_charac
ter
    raise ValueError("unable to coerce %r(%r) to string" % (type(string), string
))
ValueError: unable to coerce <type 'int'>(0) to string


Tabela DBF:
 



CSV:
 
1,000185,10,4925167d-4642-4728-a2b5-12351179f729,1

Vinicius Henrique

unread,
Jun 24, 2016, 10:21:44 AM6/24/16
to Python dBase
*UPDATE*

Table DBF:

CODIGO,N,3,0 PROCOD,C,6 PROEST,N,14,4 PRORES,N,14,4 PRO_MINIMO,N,10,4 PRO_MAXIMO,N,10,4 PRO_IDEAL,N,10,4 PRO_LOC,C,15 INC_KANBAN,L PROCOM,N,14,4 CUSTO_MAX,N,14,4 CUSTO_FISC,N,14,4 CRC,N,6,0 DT_ATUALIZ ACRESCIMO,N,12,4

Adrian Klaver

unread,
Jun 24, 2016, 10:44:15 AM6/24/16
to python...@googlegroups.com
On 06/24/2016 07:21 AM, Vinicius Henrique wrote:
> *UPDATE*
>
> Table DBF:
>
> CODIGO,N,3,0 PROCOD,C,6 PROEST,N,14,4 PRORES,N,14,4
> PRO_MINIMO,N,10,4 PRO_MAXIMO,N,10,4 PRO_IDEAL,N,10,4 PRO_LOC,C,15
> INC_KANBAN,L PROCOM,N,14,4 CUSTO_MAX,N,14,4 CUSTO_FISC,N,14,4
> CRC,N,6,0 DT_ATUALIZ ACRESCIMO,N,12,4
>
>
Given your input row:

p_stock,str(p_id),qte,0,0,0,0,0,True,0,0,0,0,None,0

See the match up or not when it comes to PRO_LOC

p_stock str(p_id) qte 0 0 0 0 0 True
CODIGO,N,3,0 PROCOD,C,6 PROEST,N,14,4 PRORES,N,14,4 PRO_MINIMO,N,10,4 PRO_MAXIMO,N,10,4 PRO_IDEAL,N,10,4 PRO_LOC,C,15 INC_KANBAN,L
0 0 0 0 None 0
> *Erro:*
> *Tabela DBF:*
>
>
> <https://lh3.googleusercontent.com/-iNlm8ug_SA4/V208wQQeJ8I/AAAAAAAAJbQ/Pf7tyO-q4244TIdtZW0vdi7N-NxcH0BjgCLcB/s1600/fields_dbf.jpg>
>
>
>
> *CSV:*
>
>
> 1,000185,10,4925167d-4642-4728-a2b5-12351179f729,1
>
>
> <https://lh3.googleusercontent.com/-wLVmzQYE160/V209Ij0aYBI/AAAAAAAAJbY/MtDhmxuHyRsPdl3GnMbpySfKuMseKdkGQCLcB/s1600/csv.jpg>
>
> --
>
> ---
> You received this message because you are subscribed to the Google
> Groups "Python dBase" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to python-dbase...@googlegroups.com
> <mailto:python-dbase...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.


--
Adrian Klaver
adrian...@aklaver.com

Vinicius Henrique

unread,
Jun 24, 2016, 10:52:50 AM6/24/16
to Python dBase
Thanks, Aklaver!

It really was in this field the problem.


Em sexta-feira, 24 de junho de 2016 11:20:43 UTC-3, Vinicius Henrique escreveu:
Reply all
Reply to author
Forward
0 new messages