Re: [Tutor] Instances
Greg Kellogg wrote: > Lets say i do: > > i = f.get_movie('0092411') > > > No I know the i holds an instance: > > i > > > > How can I find out the value of all the data this instance has? I can > do a dir(i) ... > I know there is more info in there than this, is there a way to see > everything that 'i" without hunting and pecking? You appear to be using imdbpy. The file docs/README.package gives some tips on how to use Movie objects. A Movie behaves like a dictionary; the data is stored as key/value pairs. To see all the data in a movie you could use for key in movie.keys(): print key, '=', movie[key] (Normally I would use for key, value in movie.items(): but there is a bug in movie.items() and this doesn't work. Also Movie has a summary() method that returns a string describing the movie, so you could use print movie.summary() Here is an example based on info from README.packages: >>> from imdb import IMDb >>> i = IMDb() >>> movie_list = i.search_movie('beautiful girls') >>> first_match = movie_list[0] >>> print first_match.summary() Movie = Title: Beautiful Girls (1996) >>> i.update(first_match) >>> print first_match.summary() Movie = Title: Beautiful Girls (1996) Genres: Drama, Comedy, Romance. Director: Ted Demme. Writer: Scott Rosenberg. Cast: Matt Dillon (Tommy 'Birdman' Rowland), Noah Emmerich (Michael 'Mo' Morris), Annabeth Gish (Tracy Stover), Lauren Holly (Darian Smalls), Timothy Hutton (Willie Conway). Runtime: 112. Country: USA. Language: English. Rating: 7.2 Votes: 7754 Plot: Beautiful Girls is about a group of small-town friends joining up for their first high school reunion. They find themselves evaluating their liv es and their relationships. It's about growing up and facing reality. >>> i.update(first_match, 'all') >>> print first_match.summary() >>> for key, value in first_match.items(): ... print key, '=', value ... Traceback (most recent call last): File "", line 1, in ? File "imdb\Movie.py", line 226, in items return [(k, self.__movie_data[k]) for k in self.keys()] KeyError: 'canonical title' >>> for k in first_match.keys(): ... print k, '=', first_match[k] ... rating = 7.2 composer = [, , , , , ] producer = [, , , , , , ] film length (metres) = ['3145 m'] locations = ['Hopkins, Minnesota, USA (Reunion Location)'] runtimes = ['112'] ... LOTS more info about the movie! Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Instances
Lets say i do: >>> i = f.get_movie('0092411') No I know the i holds an instance: >>> i How can I find out the value of all the data this instance has? I can do a dir(i) ['_Movie__modFunct', '_Movie__movie_data', '_Movie__namesRefs', '_Movie__titlesRefs', '__cmp__', '__contains__', '__deepcopy__', '__delitem__', '__doc__', '__getitem__', '__init__', '__module__', '__nonzero__', '__setitem__', '__str__', 'accessSystem', 'add_to_current_info', 'append_item', 'clear', 'copy', 'currentRole', 'current_info', 'default_info', 'get', 'get_current_info', 'get_namesRefs', 'get_titlesRefs', 'has_current_info', 'has_key', 'isSameTitle', 'items', 'keys', 'keys_alias', 'movieID', 'myID', 'myTitle', 'notes', 'reset', 'set_current_info', 'set_data', 'set_item', 'set_mod_funct', 'set_title', 'summary', 'update_namesRefs', 'update_titlesRefs', 'values'] I know there is more info in there than this, is there a way to see everything that 'i" without hunting and pecking? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor