你好,好人, 我是python的新手,所以如果我问一些可能对你们中某些人显而易见的事情,我深表歉意。
我的问题是关于在同一目录中导入模块。我无法使用 import“模块” (用于导入整个文件)从另一个模块调用函数,但是我可以使用来自“ module_name”的 ”导入“ function_name” 。
making_pizza.py
import pizza
make_pizza(16,'pepperoni')
make_pizza(12,'pepperoni','muchrooms','gren peppers','extra cheese')
pizza.py
print('Pizza module has been imported')
def make_pizza(size,*toppings):
'''Summrizing the pizza that we are about to make'''
print(f'Making a {size} inch pizza with the following toppings:')
for topping in toppings:
print(f'-{topping}')
输出
/Desktop/python_workspace/functions/module/making_pizza.py", line 3, in <module>
make_pizza(16,'pepperoni')
NameError: name 'make_pizza' is not defined
我在这里做什么错了?
预先感谢