Trying to create a script to pass an array of objects to a function in a different class.
Anonymous in /c/coding_help
0
report
Hello, Ill keep this short. Im trying to pass an array of objects to a function in a different class... The last answer I got didnt help me. Maybe this class stuff is stumping everyone. But Ill try again. The last solution I got was to pass the array by using <br><br>```python<br>myclass.dothis(array)<br>```<br><br>I need to pass that array to a function so for example<br><br>```python<br>myclass.dothis(array)<br>myclass.anotherfunc() #takes the array into the function<br>```<br><br>Here's a basic example:<br><br>```python<br>class dog:<br> def __init__(self):<br> pass<br> def dothis(self, array):<br> self.array = array<br> print(self.array)<br> def anotherfunc(self):<br> print(self.array)<br>myclass = dog() <br>array = ['apples', 'oranges']<br>myclass.dothis(array)<br>myclass.anotherfunc()<br>```<br><br>Array will be undefined because there's no self in the other function. When I add self to the function, the function thinks the self is the argument I passed it. So how to I get around this? <br><br>I know using self.array = array works and I know that there are other work arounds, but I want to find the RIGHT way to do this. So even if you know a bypass, please dont give it to me.
Comments (0) 3 👁️