【发布时间】:2015-11-11 17:17:59
【问题描述】:
我创建了一个 Python 2.7 模块。它的名字是记忆,保存在memory.py中。代码是:
import random
def get_a_random_memory(length, lower_sum_range, upper_sum_range):
# Start with a blank memory
memory = list()
# For each bit along the length we add a random value
for i in range(0, length):
memory.append((2 * random.randint(0, 1) - 1))
return memory
当我尝试运行时,出现以下错误。
>>> import memories
>>> print get_a_random_memory(10, 1, 10)
Traceback (most recent call last):
File "<input>", line 1, in <module>
NameError: name 'get_a_random_memory' is not defined
我检查了 print os.getcwd()。 memory.py 在我当前的工作目录中。
有什么帮助吗?
【问题讨论】:
-
你试过
print memories.get_a_random_memory(10, 1, 10)吗? -
@MorganThrapp,那个是带有内置函数的,但这个是关于我的自定义函数的。你建议我删除那个吗?
-
完全一样的问题。谁编写模块并不重要。
-
@MorganThrapp,添加记忆。解决了这个问题。谢谢。
标签: python python-2.7 module namespaces syntax-error