python – 位置参数跟随关键字参数
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了python – 位置参数跟随关键字参数,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1901字,纯文字阅读大概需要3分钟。
内容图文
参见英文答案 > Why can’t non-default arguments follow default arguments? 4个
我在python中调用这样的函数.
order_id = kite.order_place(self, exchange, tradingsymbol,
transaction_type, quantity, price, product, order_type, validity,
disclosed_quantity=None, trigger_price=None, squareoff_value,
stoploss_value, trailing_stoploss, variety, tag='')
这是函数文档中的代码..
def order_place(self, exchange, tradingsymbol, transaction_type,
quantity, price=None, product=None, order_type=None, validity=None,
disclosed_quantity=None, trigger_price=None, squareoff_value=None,
stoploss_value=None, trailing_stoploss=None, variety='regular', tag='')
它给出了这样的错误..
如何解决此错误?
谢谢 !
解决方法:
grammar of the language指定位置参数出现在调用中的关键字或星号参数之前:
argument_list ::= positional_arguments ["," starred_and_keywords]
["," keywords_arguments]
| starred_and_keywords ["," keywords_arguments]
| keywords_arguments
具体来说,关键字参数如下所示:tag =’insider trading!’
虽然位置参数看起来像这样:…,交换,…??.问题在于您似乎已复制/粘贴参数列表,并保留了一些默认值,这使它们看起来像关键字参数而不是位置参数.这很好,除了你然后回到使用位置参数,这是一个语法错误.
此外,当参数具有默认值(例如price = None)时,这意味着您不必提供它.如果您不提供它,它将使用默认值.
要解决此错误,请将以后的位置参数转换为关键字参数,或者,如果它们具有默认值而您不需要使用它们,则根本不要指定它们:
order_id = kite.order_place(self, exchange, tradingsymbol,
transaction_type, quantity)
# Fully positional:
order_id = kite.order_place(self, exchange, tradingsymbol, transaction_type, quantity, price, product, order_type, validity, disclosed_quantity, trigger_price, squareoff_value, stoploss_value, trailing_stoploss, variety, tag)
# Some positional, some keyword (all keywords at end):
order_id = kite.order_place(self, exchange, tradingsymbol,
transaction_type, quantity, tag='insider trading!')
内容总结
以上是互联网集市为您收集整理的python – 位置参数跟随关键字参数全部内容,希望文章能够帮你解决python – 位置参数跟随关键字参数所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。