所以我才刚刚开始使用 Python,目前正在努力通过 http://diveintopython3.ep.io/ .代码示例很好,但其中绝大多数都是四行的小片段,我想多看一点大图。
据我所知——如果我错了请纠正我——每个“.py”文件变成一个“模块”,目录中的一组模块变成一个“包”(至少,它确实如此)如果我在该目录中创建一个 __init__.py
文件)。如果我没有 __init__.py
文件怎么办?
那么每个“模块”文件是什么样的呢?我通常只在文件中定义一个类吗?除了类定义和一些 import
命令之外,该文件中还有其他内容吗?
最佳答案
What is it if I don't have a
__init__.py
file?
这只是一个文件夹。
Do I generally define only one class in the file?
这取决于。不一定。
Does anything else go in that file besides the class definition and maybe a handful of import commands?
你可以放任何你想放的东西。任何至少是有效的 python。
关于python - Python 中的文件/模块结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4683955/