English 中文(简体)
如何在吉特与其他人分享文字时处理第三方进口的问题?
原标题:How to deal with third party Python imports when sharing a script with other people on Git?

我制作了一个“灰色”模块(https://github.com/Yannbane/Tick.py)和一个“灰色方案”(https://github.com/Yannbane/Flatland.py)。 该方案进口了该模块,没有该模块,就无法运作。 我本打算让人们在他们能够管理该方案之前下载这两份文件,但我对此感到关切。

In the program, I ve added these lines:

sys.path.append("/home/bane/Tick.py")
import tick

/home/bane/Tick.py> is the path to my local repo of the model that need to be included, but this will clear be different to other people! 我如何能够更好地解决这种状况?

最佳回答

您不妨尝试将自己的模块提交给Python Inclusive Index,这样人们就可以轻易地将这一模块(pip rite)安装到自己的道路上,而你只能进口该模块而无需添加到平线上。

否则,我就建议简单地告诉人们,他们也要下载该单元,并把它放在该方案的子项下。 如果你真的认为这一努力太大,你可以把该单元的副本放在该方案的存放处(当然,这意味着确保你保持这两个版本的更新,这是痛苦的bit脚石,尽管我想象可能只是使用一种link子。

值得指出的是,你重新签名是一种令人难以置信的误导,资本化往往很重要,因此,你可能要打上<代码>.py,以便与模块相匹配,并用假歌命名公约。

问题回答

@Lattyware所建议的是可行的选择。 然而,它并不罕见地将核心受扶养人与主要方案挂钩(例如,Django和PyDev这样做)。 尤其是如果主要法与图书馆的具体版本相比被打碎,这项工作就会被罚款。

为了避免Lattyware在编码维护方面提到的问题,你应当研究如下网址:submodules ,其中准确允许这种布局,保持编码式。

根据你的名录结构,这两个档案似乎都在同一目录中。 这可能是两个单元: Pack。 在这种情形下,你应当简单地在名录上添加一个叫做_init__py的空档,然后您的进口可以通过以下方式发挥作用:

imp或t bane.tick

from bane imp或t tick

Oh, and yes... you should use lower case f或 module names (it s w或th to take a in-depth look at PEP8 if you are going to code in python! :)

HTH!





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签