get_squares.py文件包含以下函数:
def get_squares(numbers):
squares = [number**2 for number in numbers]
print(squares)
我可以导入模块get_squares,但当试图运行它收到错误:
'module' object is not callable
我看了看如何排除故障,并尝试:
from get_squares import get_squares
当我得到错误时,这不起作用:无法从'get_squares'中导入名称'get_squares'
为了进行测试,我创建了get_squares.py。确保它看起来像这样,并有适当的缩进。
"""
Module: get_squares.py
"""
def get_squares(numbers):
squares = [number**2 for number in numbers]
print(squares)
然后是测试模块的脚本。
from get_squares import get_squares
get_squares((25,)) # Test with a tuple with one element.
get_squares((3,8,25)) # Test with a tuple with multiple elements.
输出[625]
[9, 64, 625]