[英]What is the best way to initiate parameters on a Python library?
I have a homegrown python library.我有一个自己开发的 python 库。 As it is a library, it should be initialized with parameters every time it is used, based on different projects using it.由于它是一个库,因此每次使用时都应该根据使用它的不同项目使用参数对其进行初始化。 For example, here is the sample pseudo code:例如,这里是示例伪代码:
import myownlibrary
myownlibrary.init('path_to_config_file_containing_details_to_process_data')
Any idea how this can be achieved?知道如何实现吗? A sample reference code will be very helpful.示例参考代码将非常有帮助。
Thanks谢谢
I added it to the __init__.py
as below我将它添加到__init__.py
如下
global configpath
def setpath(self, pathpassedin):
self.configpath = pathpassedin
print("Value passed in: ", pathpassedin)
I thought self
was required, but having self
also requires that the method be called as below:我认为self
是必需的,但拥有self
还需要按如下方式调用该方法:
import myownlibrary as mylib
myownlibrary.setpath(mylib, 'path_to_config_file')
Not sure if this is the way to set this up.不确定这是否是设置此方法的方法。 Would appreciate feedback希望得到反馈
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.