0

I am trying to add potential arguments to a variable dynamically, and send it to the filter function of exchangelib. I can't get it work. This is what's currently working:

sender='abd@google.com'
accountSource.bulk_move(ids=sourceAccountFolder.filter(sender), to_folder=destinationAccountFolder)

This is what I would like to do:

params = { sender: 'asd@google.com', subject:'asdf'}
accountSource.bulk_move(ids=sourceAccountFolder.filter(params), to_folder=destinationAccountFolder)

This doesn't work

The idea is to dynamically add params if needed. For example, I could add subject = 'subjectSample' to params variable.

Thank you

Update:

This did work:

params = { 'sender': 'anemail@abc.com', 'subject__icontains': 'xxx'}
accountSource.bulk_move(ids=sourceAccountFolder.filter(**params).values('item_id', 'changekey'), to_folder=destinationAccountFolder)
Community
  • 1
  • 1
HernanFila
  • 66
  • 5
  • Possible duplicate of [What does \*\* (double star/asterisk) and \* (star/asterisk) do for parameters?](https://stackoverflow.com/questions/36901/what-does-double-star-asterisk-and-star-asterisk-do-for-parameters) – Erik Cederstrand Sep 06 '18 at 07:28
  • I know I can send the filters like this: `accountSource.bulk_move(ids=sourceAccountFolder.filter(sender='adf@sd.com',subject='sdfsdf'), to_folder=destinationAccountFolder)`, but i could not get it work by saving all keywords previous to sending it to filter function: this didn't work: `params = { sender: 'asd@sad.com', subject:'asdf'}` – HernanFila Sep 06 '18 at 13:34
  • 1
    That's what the double asterisk is for: `sourceAccountFolder.filter(**params)`. This is the equivalent of `sourceAccountFolder.filter(sender='asd@google.com', subject='asdf')` – Erik Cederstrand Sep 06 '18 at 18:01

0 Answers0