有没有一个不错的“Python 约定和最佳实践”?总结在哪里?
我对 python 相当陌生,我通常将编码作为达到目的的手段,而不是成为“编码员”。我喜欢Python通过库所包含的所有力量,并且我喜欢Python中固有但看不见的力量。 (例如,面向对象,但仍然相对脚本编写者友好的用于创建类的结构等)
但我不断遇到无法找到完整文档的情况,并且只有在发现我意外创建的问题之后才找到指向相应文档的指针。到目前为止,我只找到了对以下适当文档的引用:
不过,除非我错过了什么,这些都没有捕获有关“正确的”Python 文件命名约定的问题。在制作了几个 python 脚本之后,我发现我不应该在文件名中使用句点 (.),因为这会给导入它们带来挑战。遇到这个问题后,我确实可以找到与这一点相关的链接:
但是,我真的很想开始积极主动地解决问题,而不是通过适当的机制倒退。 Python 有几个方面使其非常独特(例如所需的空格和前面提到的文件名中不允许的句点)。我还太新,无法说这些是好是坏。但我可以说,事后不断发现所有这些事情是一种痛苦。
除了我引用的两个相对简短的文件之外,是否有任何类型的“百科全书”可以捕获所有这些特质以上?
谢谢大家!
麦克风
I am fairly new to python, and I generally code as a means to an end, as opposed to being a "coder". I like all the power that python contains through libraries, and I enjoy the inherent but invisible strength in python. (E.g., object-oriented, but still relatively scripter-friendly structure for making classes, etc.)
But I keep running into cases where I cannot find complete documentation, and I find pointers to the appropriate documentation only after discovering the problem I have accidentally created. So far, I have only found references to the following appropriate documentation:
Unless I missed something, however, neither of these captured issues regarding "proper" python file naming conventions. After making several python scripts, I discovered that I am not supposed to use periods ( . ) in the file name, since it will make it a challenge to import them. After running into this problem, I could indeed find links talking to this point:
However, I'd really like to start tackling issues pro-actively, instead of having to step backwards through the proper mechanisms. Python has SEVERAL aspects which make it quite unique (such as required whitespace & the aforementioned disallowed periods in filenames). I am too new to say whether these are good things or bad things. But I can say that it is a pain to keep discovering all these things after the fact.
Is there any sort of "encyclopedia" which may capture all these idiosyncrasies, beyond the 2 relatively brief documents I've cited above?
Thanks, all!
Mike
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道有任何明确的来源涵盖了所有内容,但除了您已经发布的链接之外,您绝对应该查看这些链接以获取一些最佳实践:
这些涵盖样式,还突出显示了一些可以通过使用某些约定和模式来避免的问题。
I don't know of any definitive source that covers everything but in addition to the links you already posted you should definitely check these links out for some best practices:
These cover style and also highlight some gotchas that can be avoided by using certain conventions and patterns.
我真的喜欢像Pythonista一样编码:惯用语David Goodger 的 Python 文章。
I really like Code Like a Pythonista: Idiomatic Python article by David Goodger.