在哪里可以找到一个函数的所有** args的列表? [英] Where to find a list of all **args of a function?

查看:182
本文介绍了在哪里可以找到一个函数的所有** args的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我知道 symbols() positive = True real = True 等作为参数,我想看到这些可能参数的完整列表。
但是,它们没有列在Sympy Core中 doc页面

For example, I know that symbols() take positive=True, real=True, etc. as arguments, and I would like to see a full list of these possible arguments. However, they're not listed in the Sympy Core doc page.

我已经挖掘了源代码本身,但我无法追踪并找到我正在寻找的内容。

And I've dug through the source code itself, but I can't trace and locate what I'm looking for.

我只是在文档中查找错误的地方,还是在这方面缺少文档?

Am I just looking in the wrong place in the documentation, or is the documentation lacking in this area?

推荐答案

symbols() function



正如其他答案所注意到的 - 在符号中使用 ** args 是通过假设关于符号正在创建。您可以通过的假设清单记录在假设页面上,为<一个href =http://docs.sympy.org/dev/modules/assumptions/index.html#supported-predicates =nofollow>支持的谓词。

symbols() function

As other answers have noted - one use of **args in the symbols is to pass in Assumptions about the Symbol being created. The list of assumptions you can pass is documented under the Assumptions page as supported predicates.

然而 ,您还应该注意到,可以传入一些其他特殊的命名参数。

However, you should also note that some other special named arguments can be passed in.

这些都记录在您链接的部分:

These are both documented in the section that you link and are:


  1. cls =< ClassName>


尽管它的名字,symbols()可以创建符号样的对象,如Function或Wild类。为了实现这一点,将cls关键字参数设置为所需的类型:

Despite its name, symbols() can create symbol-like objects like instances of Function or Wild classes. To achieve this, set cls keyword argument to the desired type:

N.B。如果未指定,则使用默认的符号类。

N.B. If not specified, the default Symbol class is used.

seq = < True | False>

文档说:


如果单个符号需要可迭代容器,请将 seq
参数设置为 True 或用逗号终止符号名称

If an iterable container is needed for a single symbol, set the seq argument to True or terminate the symbol name with a comma




代码行走



您注意到,您已经查看了代码,因此我将向您介绍代码中实现的位置。如果您打电话给 symbols() 函数,它对其参数进行各种检查,包括 pop -ing cls seq 来自 ** args 的参数,然后执行更多的检查等,最后通过调用来实例化符号 这里这里这里。这些调用符号(或通过 cls 传入的子类)的构造函数,以及 ** args 这些都被解释为 假设在构造函数中。 - 他们是 sanitized here 即非假设或非 - 适用的命名参数是抛出在这一点上!

Code walk

You note that you've looked through the code - so I'll show you where these are implemented in the code. If you call the symbols() function, it does various checks of its arguments, including pop-ing cls and seq arguments from **args it then performs more checks etc, before finally calling through to instantiate the Symbol here, here or here. These call the constructor of Symbol (or its subclass passed in via cls) with whatever is left in **args which are all interpreted as assumptions in the constructor. - they are sanitized here i.e. non-assumption or non-applicable named arguments are thrown out at this point!

这表明假设+ cls + seq 形成可以在 ** args 中传递的命名参数集到 symbols()

This shows that Assumptions + cls + seq form the set of named arguments that can be passed in **args to symbols()

symbols()可能只是作为代表一个更一般的问题的例子。我希望以上内容能够说服所有可以有效地传递到 symbols()的值。这可能会让您有信心,SymPy中的其他功能也是如此。

It occurs to me that symbols() may have simply served as a representative example of a more general question. I hope the above has convinced you that all the values that can be usefully passed into symbols() are documented. This may give you some confidence that the same is true for other functions within SymPy.

然而,在一般情况下,答案是很难证明您可以将所有可以作为关键字传递的值显示在 任何 库或函数的文档中。事实上,有时只有一个子集被刻意记录,因为它们是图书馆的公共API,而实际的代码可能需要其他参数,但由于某些原因,开发人员不希望将其公开给公众。因为它们的可用性可能会改变,或者它们的功能是未经测试的。

However, in the general case, the answer is that it is rather hard to prove to yourself that all the values that can be passed in as keywordarguments are in the documentation of any library or function. Indeed, sometimes only a subset are documented deliberately as they are the "public API" for the library whereas the actual code may take other arguments, but for some reason the developer doesn't want to expose them to the public - e.g. because their availability may change, or their functionality is untested.

如果您执行传递无效参数,则您正在使用的库的行为可能有所不同某些库或函数将忽略它们,而如果您传递无效的关键字参数,其他库或函数将抛出错误。

If you do pass in invalid arguments, the behaviour of the library you are using may differ. Some libraries or functions will ignore them, while others will throw errors if you pass in invalid keyword arguments.

如果您想了解是否这样(和库是开源的,像SymPy),那么你总是可以深入了解代码(如上面的代码步骤中所示)。如果你这样做 - 你需要遵循执行的路径,寻找 args.pop()的发生。如果SymPy中有其他功能,您关心的是让我在评论中知道 - 但希望这种一般方法可以为您工作。

If you want to find out whether that's the case (and the library is open source, like SymPy), then you can always dive through the code (as I show in the Code Walk above). If you do that - you need to follow the path of execution, looking for occurences of args.pop(). If there are other functions in SymPy that you are concerned about let me know in comments - but hopefully this general method will work for you.

我假定在上述你理解 * args ** args 语法。如果您还不完全清楚这一点, python官方tutoria l处理它。

I'm assuming in the above that you understand the *args and **args syntax. If that's not totally clear for you - this section of the python official tutorial deals with it.

这篇关于在哪里可以找到一个函数的所有** args的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆