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?

2
  • 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. Commented Dec 13, 2015 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. Commented Dec 13, 2015 at 20:56

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.