Gettin错误消息' NameError:全局名称' randint'没有定义'

时间:2015-08-18 15:08:06

标签: python python-2.7 random import syntax-error

我使用Python 2.7编写了一个模块memories.py(遗憾的是,由于某些限制,我无法使用最新版本)。它看起来如下。

import random

    def get_a_random_memory(length, upper_sum_range, lower_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 memories.get_a_random_memory(5, 0, 10)
    Traceback (most recent call last):
      File "<input>", line 1, in <module>
      File "xyz\memories.py", line 21, in get_a_random_memory
        # For each bit along the length we add a random value
    NameError: global name 'randint' is not defined

有人可以帮助我吗?

0 个答案:

没有答案