简体   繁体   English

在 Python 库上启动参数的最佳方法是什么?

[英]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.

相关问题 在Python中使用自定义排序参数对列表进行排序的最佳方法是什么? - What is the best way to sort list with custom sorting parameters in Python? 将方法(带参数)传递给 python 中的另一个方法的最佳方法是什么 - What is the best way to pass a method (with parameters) to another method in python 在python中将多个参数传递给init类的最佳方法是什么? - What is the best way to pass multiple parameters to class init in python? 使用 Python 鼠兔库合并 RabbitMQ 队列的最佳方法是什么? - What is the best way to merge RabbitMQ queues using Python pika library? 在另一个 python 项目中使用 python 库的自定义分支的最佳方法是什么? - What is the best way to use a custom fork of a python library in another python project? 简洁评估 Python 中默认参数的最佳方法? - Best way to succinctly evaluate default parameters in Python? 在 OOP Python ZE5BA8B4C539C287BAAAEZ34 - What is the best way to use one function with same parameters in multiple classes in OOP Python tkinter 在Python库中动态加载模块的最佳方法 - Best way to dynamically load modules in a Python library 在 Firebase 项目中使用 python 库的最佳方法 - Best way to use python library in Firebase project Python中最好的调度程序/回调库是什么? - What's the best dispatcher/callback library in Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM