lingcooo 2021-10-06 22:49 采纳率: 90.9%
浏览 11
已结题

import 调用模块并重命名函数,报错问题。

import语句调用a_1模块中的函数car_massage(),并将函数重新临时命名为c_m

def car_massage(name, long, **other):
cars_massage = {}
cars_massage['name'] = name
cars_massage['long'] = long
for key, value in other.items():
cars_massage[key] = value
return cars_massage

上面是模块a_1

from a_1 import car_massage as c_m

car = a_1.c_m('l', 'q', d='s', s='x')
print(car)

上面是新建.py文件,调用a_1模块,并给函数重命名。
最后打印报错:AttributeError: module 'a_1' has no attribute 'c_m'
  • 写回答

1条回答 默认 最新

  • Pliosauroidea 2021-10-06 22:51
    关注

    你已经引入并重命名了,下面使用直接用c_m即可,不需要加a_1

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 10月14日
  • 已采纳回答 10月6日
  • 创建了问题 10月6日