it does not work. I want to split data as in code in lines attribute.
class movie_analyzer:def __init__(self,s):for c in punctuation:import removiefile = open(s, encoding = "latin-1")movielist = []movies = moviefile.readlines()def lines(movies):for movie in movies:if len(movie.strip().split("::")) == 4:a = movie.strip().split("::")movielist.append(a)return(movielist)movie = movie_analyzer("movies-modified.dat")movie.lines
It returns that:
You can use @property
decorator to be able to access the result of the method as a property. See this very simple example of how this decorator might be used:
import randomclass Randomizer:def __init__(self, lower, upper):self.lower = lowerself.upper = upper@propertydef rand_num(self):return random.randint(self.lower, self.upper)
Then, you can access it like so:
>>> randomizer = Randomizer(0, 10)
>>> randomizer.rand_num
5
>>> randomizer.rand_num
7
>>> randomizer.rand_num
3
Obviously, this is a useless example; however, you can take this logic and apply it to your situation.
Also, one more thing: you are not passing self
to lines
. You pass movies
, which is unneeded because you can just access it using self.movies
. However, if you want to access those variables using self
you have to set (in your __init__
method):
self.movielist = []
self.movies = moviefile.readlines()