Re: [python-dBase] Table append problem

63 views
Skip to first unread message

Adrian Klaver

unread,
Jun 24, 2016, 10:16:45 AM6/24/16
to python...@googlegroups.com
On 06/24/2016 07:10 AM, Vinicius Henrique wrote:
> Hey, Guys!
>
> I can't identify the problem in the code below:
> Someone can help-me?
>
>
> try:
> r = csv.reader(f)
> for row in r:
>
> p_id = row[1] #SKU eg: 000185
> qte = row[2] #QTY eg: 10
> p_stock = row[4] #STOCK ID eg: 1
>
> table = dbf.Table('D:/Sensum/comercio/DADOS2/MEST2.DBF')# path
> of your dbf
> table.open()
> table.append((p_stock,str(p_id),qte,0,0,0,0,0,True,0,0,0,0,None,0))
> table.close()
>
> finally:
>
> f.close() #cleanup
>
>
>
> *Erro:*
>
> Traceback (most recent call last):
> File "insert.py", line 29, in <module>
> table.append(datum)
> 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

If I am following the below(please in future paste text not an image),
you are trying to put 0 into PRO_LOC which is a character field.

>
> C:\py>
>
>
> *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
Reply all
Reply to author
Forward
0 new messages