Python调用模块时一直显示没有模块名,但创建的模块和调用的文件已经放在了同一个目录里面
# -*- coding: utf-8 -*-
"""
Created on Mon Mar 6 19:18:13 2023
@author: HUAWEI
"""
def make_pizza(size,*toppings):
"""概述要制作的披萨"""
print(f"\nmaking a {size}-inch pizza with the following toppings")
for topping in toppings:
print(f"-{topping}")
# -*- coding: utf-8 -*-
"""
Created on Mon Mar 6 19:16:48 2023
@author: HUAWEI
"""
import making_pizza
making_pizza.make_pizza(16,'pepperoni')
making_pizza.make_pizza(12,'mushrooms','green peppers','green peppers',
'extra cheese')
最后一个文件里,把当前文件所在的路径加入到os.path
# -*- coding: utf-8 -*-
"""
Created on Mon Mar 6 19:16:48 2023
@author: HUAWEI
"""
import os
import sys
sys.path.append(os.path.dirname(__file__))
import making_pizza
making_pizza.make_pizza(16,'pepperoni')
making_pizza.make_pizza(12,'mushrooms','green peppers','green peppers',
'extra cheese')
有帮助的话,请点采纳该答案~