[Tutor] Can you tell me whats wrong with this code?

John Fouhy john at fouhy.net
Thu Aug 31 01:43:56 CEST 2006

On 31/08/06, Amadeo Bellotti <amadeo.bellotti at gmail.com> wrote:
> first of all i have random.randint imported as rand like this:
> from random import randint as rand
> it is giving me an error at the line
>     space = rand(1,82)
> the error its giving me is
>     Traceback (most recent call last):
>       File "sudoku.py", line 1050, in ?
>         space = rand(1,82)
>     TypeError: 'int' object is not callable

It's telling you that "rand" is an int.  Since it didn't start off
like that, I suspect you have assigned to rand somewhere.

Have a look through your code; are there any lines starting with:

    rand =


Also, in my opinion, it's a bad idea to rename standard library
functions like that.  If another python programmer looked at your
code, they would probably be familiar with randint and understand what
it does, but they won't know exactly what "rand" does without looking
through the rest of your code.


More information about the Tutor mailing list