0

I have a file x.py and another file y.py

I have a class x in x.py and it has a function defined as:

@property
def x(self):
    return self._x

@x.setter
def x(self, x):
    self.update_x(x)

def xy(self, l):
    self._x = 100

Now I want to use this value in the other file y.py

Where I have:

from models.x import X # where X is the name of the class in  x.py

def functionX(self):
    y = # set this value as the value of x in function x from x.py

How can I do this?

xyres
  • 20,487
  • 3
  • 56
  • 85
anonn023432
  • 2,940
  • 6
  • 31
  • 63
  • Well, you'd need to create an instance of `X` before you can access its non-static methods... Can I also suggest using less confusing names? A class named `X` (or is it `x`? You used it both ways.) in a file named `x` that has a function named `x` that returns `_x` is not exactly easy to comprehend at first glance. – senshin Dec 13 '15 at 20:56
  • This doesn't make sense. The class X doesn't have a value for x; it's a property, which has a value for a particular *instance* of X. – Daniel Roseman Dec 13 '15 at 20:56

1 Answers1

3

The class doesn't have a property x. What it does have is a property method x, and methods are only callable on instances (mostly. you can check out class methods and static methods, but they're not what you want here).

So in y.py you need an instance of the class X, which you can get by doing something like foo = X(). You can then refer to foo.x.

Community
  • 1
  • 1
6c1
  • 392
  • 2
  • 14