- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
类的 dir()
可以通过创建一个返回用户定义列表的特殊函数来定制,那么为什么它不保持我指定的顺序?这是一个例子:
>>> class C(object):
... def __dir__(self):
... return ['a', 'c', 'b']
...
>>> c = C()
>>> dir(c)
['a', 'b', 'c']
为什么 dir()
似乎对我的列表进行排序并返回 ['a', 'b', 'c']
而不是 ['a' , 'c', 'b']
?
奇怪的是(对我来说),直接调用成员函数会产生预期的结果:
>>> c.__dir__()
['a', 'c', 'b']
最佳答案
这是根据 dir()
内置的定义。它明确地按字母顺序排列名称列表:
Help on built-in function dir in module __builtin__:dir(...) dir([object]) -> list of strings If called without an argument, return the names in the current scope. Else, return an alphabetized list of names comprising (some of) the attributes of the given object, and of attributes reachable from it. If the object supplies a method named __dir__, it will be used; otherwise the default dir() logic is used and returns: for a module object: the module's attributes. for a class object: its attributes, and recursively the attributes of its bases. for any other object: its attributes, its class's attributes, and recursively the attributes of its class's base classes.
关于python - python 的 dir() 函数的结果顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9659361/
这个问题在这里已经有了答案: What's the difference between html[lang="en"] and html:lang(en) in CSS? (4 个答案) 关闭 6
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题吗? 通过 editing this post 添加细节并澄清问题. 关闭 9 年前。 Improve t
来自 ./configure --help: --with-zlib=DIR Include ZLIB support (requires zlib >= 1.0.9) --with-zlib-
我正在尝试检查我的 pod 规范并收到以下错误。 [!]“Classes”存储库中的“Classes”Pod 遇到意外版本目录“ios”。 我的源文件夹设置如下: 类 - iOS - 操作系统 Pod
在 Python 中有一个名为 dir 的内置函数。这用于获取对象所有属性的列表。 我了解它的作用,但我对为什么将其称为 dir 感到困惑。这个名称与从对象中获取属性有什么关系? 最佳答案 IIRC
我正在使用以下方法遍历文件夹: Dim file As Variant file = Dir(myFolder) While (file <> "" ) mySub file '
在 Python 的交互式 shell 中,执行 dir() 会打印一个名称列表。但是在脚本中 dir() 不直接提供任何输出,我必须使用 print(dir())。 不仅仅是dir(),其他内置函数
我明白它的作用,并且一直在使用它。但有趣的是,我还没有找到说明“DIR”的实际含义 的文档。 “目录”似乎不对。 这不是“console.log() 和 console.dir() 之间有什么区别?”
我正在尝试使用字符向量在我的工作目录中创建一系列目录。没有递归,只是迭代。没有什么花哨。例如,我可以很容易地做到这一点: lapply(state.name, dir.create) 它在我的工作目录
dir(x) 和 dir(x.__class__) 有什么区别?后者返回不同的属性列表,但与前者重叠。 例如,SQLAlchemy 的 sqlalchemy.create_engine() 函数创建一
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题吗? 通过 editing this post 添加细节并澄清问题. 关闭 6 年前。 Improve t
我正在尝试使用 Dir[] 和/或使用 Dir.foreach 对目录进行 glob: files = Dir["#{options[:dir]}/**/*"].reject { |file| Fil
Git 存储库中.gitignore 文件中的/dir 和/dir/ 有区别吗? 以下有何不同? /dir /dir/ /dir/* 最佳答案 是的,这些规则是不同的。 /dir 将匹配文件、目录、链
我正在尝试编译Bootstrap 5.3以及定制的sass文件。。这就是我的东西。奇怪的是,最后一节生成了下面的css。我预计会看到下面的css。它在开头添加了[dir]。为什么要添加[dir]?我怎
我正在尝试编译Bootstrap 5.3以及定制的sass文件。。这就是我的东西。奇怪的是,最后一节生成了下面的css。我预计会看到下面的css。它在开头添加了[dir]。为什么要添加[dir]?我怎
我正在尝试编译Bootstrap 5.3以及定制的sass文件。。这就是我的东西。奇怪的是,最后一节生成了下面的css。我预计会看到下面的css。它在开头添加了[dir]。为什么要添加[dir]?我怎
你可以找到各种文档来指定 XML 文档内容的语言,使用 xml:lang,如下所示: ... HTML 和 XHTML 具有 dir 属性,可让您指定文本在默认情况下应被视为从左到右,还是默认从右到左
当我 echo 时,输出似乎相同编辑它。 我还测试了其他命令,例如 open ,但两者的结果是一样的。 最佳答案 在传统 sh -style 模式匹配,*匹配文件名中的零个或多个字符,因此 * 之间没
我想在不同时间将一个目录复制到另一个目录中。每次,我都希望新名称比以前高一个数字/我希望能够获取该数字并将其存储到变量中。 所以如果我有一个: mymaindir /home/user/dirs/ST
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a softwar
我是一名优秀的程序员,十分优秀!