I am very new to python and very much appreciate any help I can get!
I have created a class and I am hoping to combine two lists from a previous instance of the class with the same lists in the current instance of the class.
This is my current code:
def merge(self, another_flu_tweets):
self.another_flu_tweets = another_flu_tweets
self.tweets = self.tweets + self.another_flu_tweets.tweets
self.labels = self.labels + self.another_flu_tweets.labels
another_flu_tweets = flu_tweets()
current_flu_tweets = flu_tweets()
Pass the name of the instance without the quotations, as using quotations makes it a string which will complicate your code:
Once you've passed the name of the other instance to a method in your current class, you'll simply do:
def merge(self, another_flu_tweets): self.tweets = self.tweets + another_flu_tweets.tweets # or self.tweets += another_flu_tweets.tweets self.labels = self.labels + another_flu_tweets.labels
import statements are used for imports; not sure of what you were expecting that to do.
self reference on the other hand is a name (conventionally used) to refer to the current instance of the class within a method. So you would not need to set up an instance attribute that references the other instance i.e.
self.another_flu_tweets is not needed.