如何在Python3上执行此javascript代码?

2024-10-05 02:01:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我在JavaScript上有这行代码,但我想知道在Python中这行代码的等价物是什么

const { entities, classification } = obj

完整的功能是:

function extractActionEntities (lang, expressionsFilePath, obj) {
    return new Promise(async (resolve, reject) => {
        log.title('NER')
        log.info('Searching for entities...')

        // Need to instanciate on the fly to flush entities
        this.nerManager = new NerManager()

        const { entities, classification } = obj
        // Remove end-punctuation and add an end-whitespace
        const query = `${string.removeEndPunctuation(obj.query)} `
        const expressionsObj = JSON.parse(fs.readFileSync(expressionsFilePath, 'utf8'))
        const { module, action } = classification
        const promises = []
    });
}

Tags: to代码功能logobjnewfunctionjavascript
1条回答
网友
1楼 · 发布于 2024-10-05 02:01:19

Python不使用常量,因此您必须只移植分解结构,而Python也没有(至少不像ES6那样)

但是,您可以执行以下操作:

entities, classification = [obj[k] for k in ("entities", "classification")]

或者,根据this,使用itemgetter

from operator import itemgetter
entities, classification = itemgetter("entities", "classification")(obj)

相关问题 更多 >

    热门问题