Python中文
首页
教程
问答
标签
搜索
登录
注册
Python dataset update TypeError:update()最多接受2个位置参数(给定3个)
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>当试图用来自一个dict(其中uuident=uuident)的数据更新数据库时,我收到了这个错误</p> <h3>错误:</h3> <pre><code>TypeError: update() takes at most 2 positional arguments (3 given) </code></pre> <p>错误只发生在此更新中。如果插入,则完全没有错误。你知道吗</p> <p>我是初学者,你能帮帮我吗?你知道吗</p> <h3>细节</h3> <pre><code>Traceback (most recent call last): File "/home/ubuntu/workspace/ex50/bin/teste.py", line 59, in <module> main() File "/home/ubuntu/workspace/ex50/bin/teste.py", line 35, in main prec.precifica("7f559bb1-b6c6-44b7-ba4e-1e4592dcd009") File "/home/ubuntu/workspace/ex50/bin/precificator.py", line 81, in precifica produto_precificado.update(product,['uuident']) File "/usr/lib/python2.7/_abcoll.py", line 534, in update "arguments ({} given)".format(len(args))) TypeError: update() takes at most 2 positional arguments (3 given) </code></pre> <h2>你知道吗测试.py你知道吗</h2> <pre><code>from alcateia.alcateia import * from bling.bling import * from tray.tray import * import alcateia.alcateia import tray.tray import tray.trayservice from precificator import Precificator import logging def main(): logging.basicConfig(filename='myapp.log', level=logging.INFO, format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p') logging.info('Programa inicializado...') prec = Precificator() prec.precifica("7f559bb1-b6c6-44b7-ba4e-1e4592dcd009") logging.info('Processo finalizado!') logging.info('--------------------') if __name__ == '__main__': main() </code></pre> <h3>你知道吗精密度.py</h3> <pre><code># coding: utf-8 import sys import uuid from sgcon import Produto from db import produtosalca, alca_uuid, cem, precificado import logging logger = logging.getLogger(__name__) class Precificator(object): """ modulo precificador """ def __init__(self): pass def precifica(self,uuident): print 'uuident value is %s' % uuident print 'uuident type is %s' % type(uuident) product = {} ## cria dict product product['uuident'] = uuident produto_cem = cem.find_one(uuident=uuident) ## gets produto_cem from database cem valorcem = produto_cem['valorcem'] margem = 0.04 ## definimos margem em 10% product['margem']=margem ## atribuimos margem valorMargem = valorcem * margem ## valor + margem product['valormargem']=valorMargem despadm = 15.00 ## desp adm 15 reais product['despadm'] = despadm outrasdesp = 5.00 ## outras desp 5 reais product['outrasdesp'] = outrasdesp somatudo = valorMargem + despadm + outrasdesp comissaovenda = 0.00 ##comissao mktplace 16% product['comissaovenda'] = comissaovenda comissaorecebiveis = 0.05 ##comissao / desp financeiras 0% product['comissaorecebiveis']=comissaorecebiveis cemcommargem = valorcem*(1+(margem)) ## cem com margem = cem*(1+margem) aliqICMS = produto_cem['aliqICMS'] product['aliqICMS'] = aliqICMS aliqPIS = produto_cem['aliqPIS'] aliqCofins = produto_cem['aliqCofins'] aliqTotalImposto = aliqICMS + aliqCofins + aliqPIS ## aliquota total (em %) dos impostos base = cemcommargem + despadm + outrasdesp ## Soma as despesas em reais ao valorcem e obtem a base para o calculo outrasAliq = comissaovenda + comissaorecebiveis ## outras aliquotas não tributárias indice = 1-(aliqTotalImposto + outrasAliq) ## índice para cálculo precovenda = base / indice ## aplica o índice product['precovenda']=precovenda ## atribui ao dict product ## ALL MATH DONE AND DICT PRODUCT IS READY TO GO TO DATABASE TABLE PRECIFICA produto_precificado = precificado.find_one(uuident=uuident) ## CHECKS IF ROW WITH THIS UUIDENT EXISTS IN TABLE PRECIFICA """ CHECKS AND ACT """ if produto_precificado: ## IF PRODUCT EXISTS IN DATABASE TABLE ## UPDATE print 'produto exists in db' print product print type(product) """ THIS DO NOT WORK """ produto_precificado.update(product,['uuident']) ## THIS DO NOT WORK!!!! ##produto_precificado.update(dict(precovenda=precovenda),['id']) else: ## IF product do not exists ## INSERT print 'produto nao existe no bd' """ THIS WORKS!!!! """ precificado.insert(product) ### THIS WORKS! </code></pre> <h2>更新</h2> <p><code>produto_precificado</code>类型是<code><class 'collections.OrderedDict'></code></p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>内置dict update方法接受other keywords=值并用该值更新dict,或另一个dictionary并用第二个dict的<strong>all</strong>键更新dict</p> <p>你可能想做的是:</p> <pre><code>produto_precificado[product['uuident']] = product </code></pre> <p>根据uuident(或任何键)对产品进行散列。你知道吗</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
无法使用Django/mongoengine连接到MongoDB(身份验证失败)
1 回答
无法使用Django\u mssql\u后端迁移到外部hos
3 回答
无法使用Django&Python3.4连接到MySql
6 回答
无法使用Django+nginx上载媒体文件
6 回答
无法使用Django1.6导入名称模式
6 回答
无法使用Django1.7和mongodb登录管理站点
5 回答
无法使用Djangoadmin创建项目,进程使用了错误的路径,因为我事先安装了错误的Python
7 回答
无法使用Djangockedi验证CBV中的字段
6 回答
无法使用Djangocketditor上载图像(错误400)
7 回答
无法使用Djangocron进行函数调用
10 回答
无法使用Djangofiler djang上载文件
2 回答
无法使用Djangokronos
8 回答
无法使用Djangomssql provid
5 回答
无法使用Djangomssql连接到带有Django 1.11的MS SQL Server 2016
9 回答
无法使用Djangomssq迁移Django数据库
2 回答
无法使用Djangonox创建用户
7 回答
无法使用Djangopyodb从Django查询SQL Server
1 回答
无法使用Djangopython3ldap连接到ldap
8 回答
无法使用Djangoredis连接到redis
2 回答
无法使用Django中的FK创建新表
10 回答