python setattr 函数

python setattr 函数setattr object name value Thisisthecou Thearguments astringandan Thestringmay Thefun

setattr
(
object,
name,
value
)

This is the counterpart of getattr(). The arguments are an object, astring and an arbitrary value. The string may name an existing attribute or anew attribute. The function assigns the value to the attribute, provided theobject allows it. For example, setattr(x, 'foobar', 123) is equivalent tox.foobar = 123.

查阅 python lib reference manual 得到:

yocto bitbake python 脚本中有一段代码用到了这个函数:

class BBConfiguration(object): """ Manages build options and configurations for one run """ def __init__(self, options): for key, val in options.__dict__.items(): setattr(self, key, val) self.pkgs_to_build = [] 

def main(): parser = optparse.OptionParser( version = "BitBake Build Tool Core version %s, %%prog version %s" % (bb.__version__, __version__), usage = """%prog [options] [package ...] Executes the specified task (default is 'build') for a given set of BitBake files. It expects that BBFILES is defined, which is a space separated list of files to be executed. BBFILES does support wildcards. Default BBFILES are the .bb files in the current directory.""") parser.add_option("-b", "--buildfile", help = "execute the task against this .bb file, rather than a package from BBFILES. Does not handle any dependencies.", action = "store", dest = "buildfile", default = None) parser.add_option("-k", "--continue", help = "continue as much as possible after an error. While the target that failed, and those that depend on it, cannot be remade, the other dependencies of these targets can be processed all the same.", action = "store_false", dest = "abort", default = True) parser.add_option("-a", "--tryaltconfigs", help = "continue with builds by trying to use alternative providers where possible.", action = "store_true", dest = "tryaltconfigs", default = False) parser.add_option("-f", "--force", help = "force run of specified cmd, regardless of stamp status", action = "store_true", dest = "force", default = False) parser.add_option("-c", "--cmd", help = "Specify task to execute. Note that this only executes the specified task for the providee and the packages it depends on, i.e. 'compile' does not implicitly call stage for the dependencies (IOW: use only if you know what you are doing). Depending on the base.bbclass a listtasks tasks is defined and will show available tasks", action = "store", dest = "cmd") parser.add_option("-C", "--clear-stamp", help = "Invalidate the stamp for the specified cmd such as 'compile' and run the default task for the specified target(s)", action = "store", dest = "invalidate_stamp") parser.add_option("-r", "--read", help = "read the specified file before bitbake.conf", action = "append", dest = "prefile", default = []) parser.add_option("-R", "--postread", help = "read the specified file after bitbake.conf", action = "append", dest = "postfile", default = []) parser.add_option("-v", "--verbose", help = "output more chit-chat to the terminal", action = "store_true", dest = "verbose", default = False) parser.add_option("-D", "--debug", help = "Increase the debug level. You can specify this more than once.", action = "count", dest="debug", default = 0) parser.add_option("-n", "--dry-run", help = "don't execute, just go through the motions", action = "store_true", dest = "dry_run", default = False) parser.add_option("-S", "--dump-signatures", help = "don't execute, just dump out the signature construction information", action = "store_true", dest = "dump_signatures", default = False) parser.add_option("-p", "--parse-only", help = "quit after parsing the BB files (developers only)", action = "store_true", dest = "parse_only", default = False) parser.add_option("-s", "--show-versions", help = "show current and preferred versions of all recipes", action = "store_true", dest = "show_versions", default = False) parser.add_option("-e", "--environment", help = "show the global or per-package environment (this is what used to be bbread)", action = "store_true", dest = "show_environment", default = False) parser.add_option("-g", "--graphviz", help = "emit the dependency trees of the specified packages in the dot syntax, and the pn-buildlist to show the build list", action = "store_true", dest = "dot_graph", default = False) parser.add_option("-I", "--ignore-deps", help = """Assume these dependencies don't exist and are already provided (equivalent to ASSUME_PROVIDED). Useful to make dependency graphs more appealing""", action = "append", dest = "extra_assume_provided", default = []) parser.add_option("-l", "--log-domains", help = """Show debug logging for the specified logging domains""", action = "append", dest = "debug_domains", default = []) parser.add_option("-P", "--profile", help = "profile the command and print a report", action = "store_true", dest = "profile", default = False) parser.add_option("-u", "--ui", help = "userinterface to use", action = "store", dest = "ui") parser.add_option("-t", "--servertype", help = "Choose which server to use, none, process or xmlrpc", action = "store", dest = "servertype") parser.add_option("", "--revisions-changed", help = "Set the exit code depending on whether upstream floating revisions have changed or not", action = "store_true", dest = "revisions_changed", default = False) parser.add_option("", "--server-only", help = "Run bitbake without UI, the frontend can connect with bitbake server itself", action = "store_true", dest = "server_only", default = False) parser.add_option("-B", "--bind", help = "The name/address for the bitbake server to bind to", action = "store", dest = "bind", default = False) parser.add_option("", "--no-setscene", help = "Do not run any setscene tasks, forces builds", action = "store_true", dest = "nosetscene", default = False) options, args = parser.parse_args(sys.argv) configuration = BBConfiguration(options) configuration.pkgs_to_build.extend(args[1:])

其中:




版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/217618.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月18日 上午9:10
下一篇 2026年3月18日 上午9:10


相关推荐

  • 比较好用的Java模拟器,515最好的java模拟器

    比较好用的Java模拟器,515最好的java模拟器之前的那些 java 模拟器根本算不上真正适用的 一来操作麻烦 二来不支持现成的 java 程序 还必须手机上网下载 之前的那些 java 模拟器根本算不上真正适用的 一来操作麻烦 二来不支持现成的 java 程序 还必须手机上网下载 这个 dmidp2 才算得上真正的可以用的 java 模拟器 它最大的优点就是可以建立在卡上 而 java 程序也可以是实现成的 相信很多人都囤积了大量的从网上下载来的 java 游戏吧 这些

    2025年8月8日
    7
  • 一文吃透 Agent Skills:从概念到落地,打造靠谱智能体工程体系

    一文吃透 Agent Skills:从概念到落地,打造靠谱智能体工程体系

    2026年3月16日
    1
  • Winform开发常用控件之Checkbox和CheckedListBox

    Winform开发常用控件之Checkbox和CheckedListBoxWinform的开发基本都是基于控件事件的,也就是事件驱动型的。多选框的放置和值的获取有很多种,这里介绍几个简单常用的方法1、直接放置Checkbox,并获取Checkbox的值上图做法也非常简单,就

    2022年7月2日
    33
  • 相关性分析方法怎么选择_多个因素相关性分析

    相关性分析方法怎么选择_多个因素相关性分析有时候我们根据需要要研究数据集中某些属性和指定属性的相关性,显然我们可以使用一般的统计学方法解决这个问题,下面简单介绍两种相关性分析方法,不细说具体的方法的过程和原理,只是简单的做个介绍,由于理解可能

    2022年8月5日
    11
  • vmware15最新激活码2021_在线激活

    (vmware15最新激活码2021)本文适用于JetBrains家族所有ide,包括IntelliJidea,phpstorm,webstorm,pycharm,datagrip等。IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.html…

    2022年3月22日
    81
  • java实现短信群发功能

    java实现短信群发功能首先去 http www smschinese cn 上下载 jar 包以及注册用户 然后调用 api 接口 取得秘钥 1 ASP 调用例子 lt 常用函数 输入 url 目标网页地址 返回值 getHTTPPage 是目标网页的 html 代码 functiongetH url dimHttpsetHt server c

    2026年3月18日
    2

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号