<tfoot id='H4uTK'></tfoot>

      <small id='H4uTK'></small><noframes id='H4uTK'>

      • <bdo id='H4uTK'></bdo><ul id='H4uTK'></ul>
        <i id='H4uTK'><tr id='H4uTK'><dt id='H4uTK'><q id='H4uTK'><span id='H4uTK'><b id='H4uTK'><form id='H4uTK'><ins id='H4uTK'></ins><ul id='H4uTK'></ul><sub id='H4uTK'></sub></form><legend id='H4uTK'></legend><bdo id='H4uTK'><pre id='H4uTK'><center id='H4uTK'></center></pre></bdo></b><th id='H4uTK'></th></span></q></dt></tr></i><div id='H4uTK'><tfoot id='H4uTK'></tfoot><dl id='H4uTK'><fieldset id='H4uTK'></fieldset></dl></div>
      1. <legend id='H4uTK'><style id='H4uTK'><dir id='H4uTK'><q id='H4uTK'></q></dir></style></legend>
      2. setattr 与 kwargs,pythonic 与否?

        setattr with kwargs, pythonic or not?(setattr 与 kwargs,pythonic 与否?)

          <tfoot id='uYbJ4'></tfoot>
        • <legend id='uYbJ4'><style id='uYbJ4'><dir id='uYbJ4'><q id='uYbJ4'></q></dir></style></legend>

            <small id='uYbJ4'></small><noframes id='uYbJ4'>

              <tbody id='uYbJ4'></tbody>

              1. <i id='uYbJ4'><tr id='uYbJ4'><dt id='uYbJ4'><q id='uYbJ4'><span id='uYbJ4'><b id='uYbJ4'><form id='uYbJ4'><ins id='uYbJ4'></ins><ul id='uYbJ4'></ul><sub id='uYbJ4'></sub></form><legend id='uYbJ4'></legend><bdo id='uYbJ4'><pre id='uYbJ4'><center id='uYbJ4'></center></pre></bdo></b><th id='uYbJ4'></th></span></q></dt></tr></i><div id='uYbJ4'><tfoot id='uYbJ4'></tfoot><dl id='uYbJ4'><fieldset id='uYbJ4'></fieldset></dl></div>
                • <bdo id='uYbJ4'></bdo><ul id='uYbJ4'></ul>
                  本文介绍了setattr 与 kwargs,pythonic 与否?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在一些具有许多参数(最多 20 个)的 SQLAlchemy ORM 类中使用像这样的 __init__().

                  I'm using __init__() like this in some SQLAlchemy ORM classes that have many parameters (upto 20).

                  def __init__(self, **kwargs):
                      for k, v in kwargs.iteritems():
                          setattr(self, k, v)
                  

                  这样设置属性是pythonic"吗?

                  Is it "pythonic" to set attributes like this?

                  推荐答案

                  是的.另一种方法是.

                  def __init__(self, **kwargs):
                      self.__dict__.update( kwargs )
                  

                  这篇关于setattr 与 kwargs,pythonic 与否?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Initialize Multiple Numpy Arrays (Multiple Assignment) - Like MATLAB deal()(初始化多个 Numpy 数组(多重赋值) - 像 MATLAB deal())
                  How to extend Python class init(如何扩展 Python 类初始化)
                  What#39;s the difference between dict() and {}?(dict() 和 {} 有什么区别?)
                  What is a wrapper_descriptor, and why is Foo.__init__() one in this case?(什么是 wrapper_descriptor,为什么 Foo.__init__() 在这种情况下是其中之一?)
                  Initialize list with same bool value(使用相同的布尔值初始化列表)
                  Python - Initializing Multiple Lists/Line(Python - 初始化多个列表/行)
                    • <bdo id='dN5Nm'></bdo><ul id='dN5Nm'></ul>

                      <small id='dN5Nm'></small><noframes id='dN5Nm'>

                      <tfoot id='dN5Nm'></tfoot>
                      • <legend id='dN5Nm'><style id='dN5Nm'><dir id='dN5Nm'><q id='dN5Nm'></q></dir></style></legend>

                          • <i id='dN5Nm'><tr id='dN5Nm'><dt id='dN5Nm'><q id='dN5Nm'><span id='dN5Nm'><b id='dN5Nm'><form id='dN5Nm'><ins id='dN5Nm'></ins><ul id='dN5Nm'></ul><sub id='dN5Nm'></sub></form><legend id='dN5Nm'></legend><bdo id='dN5Nm'><pre id='dN5Nm'><center id='dN5Nm'></center></pre></bdo></b><th id='dN5Nm'></th></span></q></dt></tr></i><div id='dN5Nm'><tfoot id='dN5Nm'></tfoot><dl id='dN5Nm'><fieldset id='dN5Nm'></fieldset></dl></div>
                              <tbody id='dN5Nm'></tbody>