简体   繁体   English

使用boto3命令作为字符串

[英]use boto3 command as a string

We can use boto3 package to get the data from mTurk account (or do anything else in AWS). 我们可以使用boto3包从mTurk帐户获取数据(或在AWS中执行其他任何操作)。 For example: 例如:

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

Is there a way to use boto3 command as a string? 有没有办法将boto3命令用作字符串? Something like: 就像是:

balance = client.get_command('get_account_balance')

get_command is totally just for illustrative purposes here of course. get_command完全只是出于说明目的。

使用getattr内置函数:

getattr(client, 'get_account_balance')()

You could use the built-in getattr : 您可以使用内置的getattr

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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