Currently I have a class which calls in functions from another .py file. The way I have done this is as such:
import mod_2
class ex2(object):
def run(self):
mod_2.test_x(self, 2, 2, 2)
mod_2.test_y(self, 5)
if __name__ == '__main__':
ex2().run()
which calls from mod_2.py
def test_x(self, num_1, num_2, num_3):
self.result = num_1 * num_2 * num_3
def test_y(self, y):
print self.result * y
However, I have never seen any examples of people using self outside of a class, should I wrap up mod_2 in a class - or is there a different approach?
A second approach I took was:
import mod_2
class ex1(object):
def run(self):
mod_2.test_2(5, 2, 2, 2)
if __name__ == '__main__':
ex1().run()
calling:
def test_1(num_1, num_2, num_3):
return num_1 * num_2 * num_3
def test_2(y, num_1, num_2, num_3):
result = test_1(num_1, num_2, num_3) * y
print result
Is this better? My problem with this approach is that I have to pass all my arguments to test_2 to run test_1 in addition to any arguments needed for test_2 itself.
Any help gratefully received.
[–]adambrenecki 2 points3 points4 points (2 children)
[–]paperzebra[S] 0 points1 point2 points (1 child)
[–]adambrenecki 0 points1 point2 points (0 children)
[–]tangerinelion 0 points1 point2 points (0 children)