简体   繁体   中英

use boto3 command as a string

We can use boto3 package to get the data from mTurk account (or do anything else in AWS). For example:

client = boto3.client('mturk')
balance = client.get_account_balance()

Is there a way to use boto3 command as a string? Something like:

balance = client.get_command('get_account_balance')

get_command is totally just for illustrative purposes here of course.

使用getattr内置函数:

getattr(client, 'get_account_balance')()

You could use the built-in getattr :

def get_command(client, command):
    return getattr(client, command)()

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