第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 Python 中以編程方式調(diào)用函數(shù)也以編程方式指定模塊?

如何在 Python 中以編程方式調(diào)用函數(shù)也以編程方式指定模塊?

有只小跳蛙 2021-09-14 20:57:04
我不能用這個import foomethod_to_call = getattr(foo, 'bar')result = method_to_call()因為模塊名稱是硬編碼的,我不能使用它module = __import__('foo')func = getattr(module, 'bar')func()因為模塊是嵌套的。我試過這個customer = 'jci'module = __import__('customer.{customer_name}.gt'.format(customer_name=customer_name)) # AttributeError: module 'customer' has no attribute 'get_gt'#module = __import__('customer.{customer_name}'.format(customer_name=customer_name), fromlist=['gt']) # AttributeError: module 'customer.jci' has no attribute 'get_gt'#module = __import__('customer.{customer_name}.gt'.format(customer_name=customer_name), fromlist=[]) # AttributeError: module 'customer' has no attribute 'get_gt'func = getattr(module, 'get_gt')gt = func()    但因錯誤而失敗,在注釋中與每個變體一起指定。get_gt()是目錄內(nèi)gt.py文件內(nèi)的函數(shù)customer/jci。每個目錄__init__.py里面都是空的。以下硬編碼代碼有效:import customer.jci.gt as ggt = g.get_gt()如何克服?
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 209 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號