[Tutor] bad name in module

Jim Mooney cybervigilante at gmail.com
Fri May 10 07:45:17 CEST 2013


I have a simple program, below, to create a specified list of random
integers, which works fine.
I saved it to Lib as makeRandomList.py, then imported it to a
sorter.py program, like so. The import doesn't fail:

import makeRandomList

newRandomList = createRandomList()

  But I then get the following error:

File "c:\Python33\Progs\sorter.py", line 3, in <module>
builtins.NameError: name 'createRandomList' is not defined

  What am I doing wrong in creating the library module below, which
works fine as a standalone?

====================================  program saved to Lib directory
as makeRandomList.py
import random
random.seed()

def createRandomList():
    while True:
        listLength = input("How big a list do ya want, Corky? ")
        try:
            listLength = int(listLength)
            break
        except:
            print("That's not an integer, Corky - try again: ")

    while True:
        maxNumberSize = input("How big should the biggest number in
the list be? ")
        try:
            maxNumberSize = int(maxNumberSize)
            break
        except:
            print("That's not an integer, Corky - try again: ")

    randomList = []

    for c in range(0,listLength):
        randNum = random.randint(0,maxNumberSize)
        randomList.append(randNum)

    return randomList


-- 
Jim Mooney

“For anything that matters, the timing is never quite right, the
resources are always a little short, and the people who affect the
outcome are always ambivalent.”


More information about the Tutor mailing list