0

I have a class called Stream that has multiple functions in it. A function called live is called inside another function in the same class Stream but doing so prints the name live is not defined error.

class Stream(Thread):

   def __init__(self):
      # declare some stuff

   def live(x, y):
      # do something

   def run(self):
      # do something
      var = live(a, b)
      # do something

When running this file, I get the NameError error.

  • `live` is an attribute of `Stream`, not a variable in any scope that `Stream.run` can see. `class` statements do not create a new scope. – chepner Sep 14 '21 at 00:56
  • so how would i use live in this situation? I actually need whatever live returns for **run** – Hakim Kadhi Sep 14 '21 at 00:59
  • 1
    The same way you would any other class attribute: `vat = Stream.live(a, b)`. Note that since it neither expects nor receives `self` as an argument, it should probably declared as a static method. (Or defined outside the class altogether, in which case you *can* use `live` as an ordinary global variable.) – chepner Sep 14 '21 at 11:06

0 Answers0