python 样式 ** 问题
我正在使用 Python 2.7 开发我的第一个项目。我们有 Java 背景,我们的第一反应是以 Java 风格的方式编写 Python 代码。但现在我们正在努力尽可能地适应。到目前为止,我们正在使用pylint来调整我们的代码。
现在我不断遇到 pylint 的情况。每次我使用诸如 **data
之类的东西将值传递给方法时,我都会收到有关使用 *
或 的 pylint 警告**。现在我的问题是:使用
**
编写 python 代码是否是一种不好的样式?是否有某种标准替代品可以使用它?
问候, 博格丹
I'm working on my first project using Python 2.7. We're coming from a Java background and our first instinct was to write python code in a Java-esque way. But now we're trying to adapt as much as possible. So far we are using pylint to adapt our code.
Now I keep running into a situation with pylint. Every time I use something like **data
to pass values to a method I'm getting a pylint warning about using *
or **
. Now my question is: Is using **
a bad styling for writing python code? Is there some kind of standard replacement for using this ?
Regards,
Bogdan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
**
可能会引入一些更棘手的错误,因为它会接受任何内容。通常您希望代码在调用错误时会中断。下面是一个示例:您不应该仅仅因为懒得键入参数名称而使用
**
。但这并不总是可能的,因此也有合法的用途。**
can introduce some more tricky bug because it will accept anything. Usually you want code that breaks when called wrong. Here is a example:You shouldn't use
**
just because you are too lazy to type out the argument names. That is not always possible though, so there are legitimate uses too.使用静态分析来验证
**
生成的参数是否全部有效几乎是不可能的,但如果这是唯一合适的机制,他们一定会使用它。It's almost impossible to use static analysis to verify that the arguments generated by
**
are all valid, but if it is the only appropriate mechanism them by all means do use it.**
非常适合其设计目的:将参数转发给其他函数。您肯定可以做一些坏事,从而降低代码的可读性,但这本身并不被认为是不好的做法。**
excellent for what it is designed for: to forward arguments to other functions. You can definitely do bad things that will decrease the readability of your code with it, but it's not considered bad practice per se.