-2

I have this line on JavaScript, but i want to know what's the equivalent of that in Python.

const { entities, classification } = obj

The complete function is:

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 = []
    });
}
Héliton Martins
  • 1,143
  • 10
  • 25
  • Stack Overflow is **not** a code-writing service, you must at least make an honest attempt to solve your problem before opening a question about it. – Rfroes87 Nov 01 '20 at 21:07
  • 1
    Maybe you didn't understand or I didn't make myself understood. I don't want them to write code for me, I just want to know how I do that line in Python. – Andres Hernandez Nov 01 '20 at 21:34
  • My bad, I didn't pay attention to the *line* part. If you care to edit anything in your question, I can remove the *downvote* casted. – Rfroes87 Nov 02 '20 at 02:58
  • 1
    Sorry man, i can't remove that line, i didn't want to add that line, but the Stack Overflow's policies forces me. Nevermind, i got the answer. – Andres Hernandez Nov 04 '20 at 14:20

1 Answers1

4

Python doesn't use constants, so you have to port only the destructuring, which Python also doesn't have (at least not exactly like ES6).

You can, however, do this:

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

Or, according to this, use the itemgetter.

from operator import itemgetter
entities, classification = itemgetter("entities", "classification")(obj)
Héliton Martins
  • 1,143
  • 10
  • 25