在Python中布置导入路径,简单直接? [英] Lay out import pathing in Python, straight and simple?
问题描述
如果一组Python开发人员希望将他们的共享代码放在某个层次结构中,那么结构是什么,以及相关的导入语法是什么?
java风格的引用也适用于Python吗?即,目录是否对应点?
什么是内部使用专用的Python代码库的标准设置,以及从该库区域导入的语法是什么,比如3级深度?
我读过学习Python,看到PYTHONPATH,现在已经花了几个星期的代码,喜欢它,但我只是在重要的情况下密切关注琐事。如果过于笼统,请寄回给我。
如果一组Python开发人员想要将他们的共享代码放在某个层次结构中,结构是什么,相关的导入语法是什么?
你把它放在一起在您自己的文件夹下的C:\ python26 \Lib \site-packages \目录中。
在该文件夹中,您应该包含一个__init__.py文件将在导入时运行,这可以是空的。
java风格的引用是否也适用于Python?即,目录是否对应点?
是的,只要目录包含__init__.py文件。
什么是内部使用的Python代码库的标准设置,以及从该库区域导入的语法是什么,比如3级深度?
MyCompany / MyProject / - > import MyCompany.MyProject
If a group of Python developers wants to put their shared code somewhere, in a hierarchical structure, what's the structure, and what's the related "import" syntax?
Does java-style reference work in Python also? I.e., do directories correspond to dots?
What is standard setup for an internal-use-only library of Python code, and what's the syntax for imports from that library area, say 3 levels deep?
I've read Learning Python, saw PYTHONPATH, been fiddling with code for a few weeks now, love it, but I'm just dense on "import" beyond trivial cases. If too general send me back to the books.
If a group of Python developers wants to put their shared code somewhere, in a hierarchical structure, what's the structure, and what's the related "import" syntax?
You put it in your C:\python26\Lib\site-packages\ directory under your own folder.
Inside that folder you should include an __init__.py file which will be run upon import, this can be empty.
Does java-style reference work in Python also? I.e., do directories correspond to dots?
Yes as long as the directories contain __init__.py files.
What is standard setup for an internal-use-only library of Python code, and what's the syntax for imports from that library area, say 3 levels deep?
MyCompany/MyProject/ -> import MyCompany.MyProject
这篇关于在Python中布置导入路径,简单直接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!