title: Passing a listed range of an attribute to its own object (Python)
body: <p>I'm trying to create a class of objects which print "BOO!" a certain number of times, based on the current (particular) object's scariness level. I've created the attribute scariness, but I want to create a function which takes a range from 0 to that scariness level, then takes that range as a list, then prints "BOO!" for every element in that list. I've tried it two ways, here is my code:</p>
  
  <p>Version 1:</p>
  
  <pre><code>class Ghost:  
      def __init__(self, name, scariness, scarylist):  
          self.name = name  
          self.scariness = scariness  
          self.scarylist = list(range[scariness])  
      def scare_human(self):  
          for i in scarylist:  
              print('BOO!')
  
  steve = Ghost("Steve", 1000, scarylist)
  </code></pre>
  
  <p>When I execute the cell beginning with <code>scarylist = list[range(1000)]</code> in my IDE (Jupyter Notebook if it matters) I get the error, "'Type' object is not subscriptable." I'm guessing there are a couple things wrong with this version.</p>
  
  <p>Version 2:  </p>
  
  <pre><code>class Ghost:  
      scarylist = list(range[scariness])  
      def scare_human(self):  
          for i in scarylist:  
              print('BOO!')  
  
  steve = Ghost()  
  steve.name = "Steve"  
  steve.scariness = 1000  
  steve.hungriness = 10
  </code></pre>
  
  <p>The trouble with this version is that I have to define the attributes of the class <em>before</em> I want to call them as variables of a function of the class. I can't do this if I use this kind of definition of the class.</p>