简体   繁体   中英

How to pass keyword argument as a key to other function in python?

Code:

def edit_properties(self, device, ssc_command="hexa", value="test")
    result = self.edit_devices.edit_device_property(device, ssc_command=value)

I want to pass "ssc_command" as a key to self.edit_devices.edit_device_property(device, ssc_command=value) and value as a value.

Dictionary/kwargs expansion. First, you make a dict with ssc_command as the key and value as the value, and then you use ** to expand it into a set of keyword arguments:

result = self.edit_device.edit_device_property(device, **{ssc_command:value})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM