Why won't this decorator work?

John Salerno johnjsal at gmail.com
Sat Jul 2 12:56:39 EDT 2011

I thought I had finally grasped decorators, but the error I'm getting
('str' type is not callable) is confusing me. Here is my code. Also,
the commented sentence is from the Python docs, which says it doesn't
even need to be callable, if that matters. I also commented out a few
things in the move method. They were just to see if it would work, but
those lines raised even more errors!

import random

#space = 0

def move(roll):
#    global space
#   space += roll
    return 'You moved to space {0}.'.format(roll)

def roll_die():
    return random.randint(1, 6)

# The return value of the decorator need not be callable
# roll_die = move(roll_die)

I tried running the command "roll_die()" and I get the error message.


More information about the Python-list mailing list