Python: 使用对象调用包的函数

Python: Call function of package using object

我正在为 python 使用 ccxt 模块。 我可以初始化它进行交换。例如 bittrex:

exchange = ccxt.bittrex({
    'enableRateLimit': True
})
return exchange

但以下不起作用:

ex = 'bittrex'
print(ex)
exchange = ccxt.ex({
    'enableRateLimit': True
})
return exchange

错误:AttributeError: module 'ccxt' has no attribute 'ex' 我怎样才能使这项工作?

import ccxt
ex = 'bittrex'
ex_obj = getattr(ccxt, ex)
exchange = ex_obj({
    'enableRateLimit': True
})
return exchange

ex 必须是以下支持的交换列表之一

print(ccxt.exchanges) ['_1broker', '_1btcxe', 'acx', 'allcoin', 'anxpro', 'anybits', 'bcex', 'bibox', 'bigone', 'binance', 'bit2c', 'bitbank', 'bitbay', 'bitfinex', 'bitfinex2', 'bitflyer', 'bitforex', 'bithumb', 'bitkk', 'bitlish', 'bitmarket', 'bitmex', 'bitsane', 'bitso', 'bitstamp', 'bitstamp1', 'bittrex', 'bitz', 'bl3p', 'bleutrade', 'braziliex', 'btcalpha', 'btcbox', 'btcchina', 'btcexchange', 'btcmarkets', 'btctradeim', 'btctradeua', 'btcturk', 'btcx', 'bxinth', 'ccex', 'cex', 'chbtc', 'chilebit', 'cobinhood', 'coinbase', 'coinbaseprime', 'coinbasepro', 'coincheck', 'coinegg', 'coinex', 'coinexchange', 'coinfalcon', 'coinfloor', 'coingi', 'coinmarketcap', 'coinmate', 'coinnest', 'coinone', 'coinsecure', 'coinspot', 'cointiger', 'coolcoin', 'crypton', 'cryptopia', 'deribit', 'dsx', 'ethfinex', 'exmo', 'exx', 'fcoin', 'flowbtc', 'foxbit', 'fybse', 'fybsg', 'gatecoin', 'gateio', 'gdax', 'gemini', 'getbtc', 'hadax', 'hitbtc', 'hitbtc2', 'huobi', 'huobicny', 'huobipro', 'ice3x', 'independentreserve', 'indodax', 'itbit', 'jubi', 'kraken', 'kucoin', 'kuna', 'lakebtc', 'lbank', 'liqui', 'livecoin', 'luno', 'lykke', 'mercado', 'mixcoins', 'negociecoins', 'nova', 'okcoincny', 'okcoinusd', 'okex', 'paymium', 'poloniex', 'qryptos', 'quadrigacx', 'quoinex', 'rightbtc', 'southxchange', 'surbitcoin', 'theocean', 'therock', 'tidebit', 'tidex', 'uex', 'urdubit', 'vaultoro', 'vbtc', 'virwox', 'wex', 'xbtce', 'yobit', 'yunbi', 'zaif', 'zb']