python调用函数输入列表_如果在python中调用函数列表中的任何函数,则自动触发函数...

如果在python中调用了函数列表中的任何一个函数,是否有一种自动触发函数的方法?

就像say函数a附加到一个函数列表[b,c,d,e]上,如果调用了[b,c,d,e]中的任何一个(例如say b()),那么在它之前自动调用a()?

我想在调用B之前使用函数A设置一些值,以便B可以使用它。

例如:

# function b is some inbuilt, library function

attach(a, b) #attach function b to function a

b()

# If function b is called first function a gets called, it changes up some

# global variables for the use of function b, then function b gets executed

我有一些全局变量和一些类方法,全局变量是一些诸如分类器(如逻辑回归或XGBClassifier)、分类器类型(如“线性”或“树”)之类的东西,每当我在各自的管道上调用fit和predict方法(如pipeline、linear或pipeline、tree)时,都需要更改它们。fit/predict。这是因为我编写了如下代码:

CLASSIFIER = LogisticRegression

CLASSIFIER_TYPE = 'linear'

pipeline_linear = make_pipeline(preprocessing_pipe, CLASSIFIER())

pipeline_linear.fit(X, y)

CLASSIFIER = XGBClassifier

CLASSIFIER_TYPE = 'tree'

pipeline_tree = make_pipeline(preprocessing_pipe, CLASSIFIER())

pipeline_tree.fit(X, y)

linear_preds = pipeline_linear.predict(X) # This statement throws an error

# because CLASSIFIER and CLASSIFIER_TYPE are not changed

# preprocessing_pipe uses CLASSIFIER_TYPE internally to take care of

# handling both types of classifiers differently.

因此,基于我正在使用的管道,需要相应地修改全局变量,以便适合和预测管道(管道\线性和管道\树)的工作方法。

任何其他处理这些情况的好方法都将非常有用!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值