[Tutor] Instances
Kent Johnson
kent37 at tds.net
Sat Aug 6 16:46:18 CEST 2005
Greg Kellogg wrote:
> Lets say i do:
>
>
>>>>i = f.get_movie('0092411')
>
>
> No I know the i holds an instance:
>
>
>>>>i
>
> <imdb.Movie.Movie instance at 0x2d7a08>
>
> 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 "<stdin>", 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 = [<imdb.Person.Person instance at 0x00A52288>, <imdb.Person.Person instance at 0x00A522D8>, <imdb.Person.Person instance at 0x00A52300>, <im
db.Person.Person instance at 0x00A52328>, <imdb.Person.Person instance at 0x00A52350>, <imdb.Person.Person instance at 0x00A52378>]
producer = [<imdb.Person.Person instance at 0x00A49A58>, <imdb.Person.Person instance at 0x00A49BC0>, <imdb.Person.Person instance at 0x00A49F80>, <im
db.Person.Person instance at 0x00A49CD8>, <imdb.Person.Person instance at 0x00A49F58>, <imdb.Person.Person instance at 0x00A49DC8>, <imdb.Person.Perso
n instance at 0x00A49F30>]
film length (metres) = ['3145 m']
locations = ['Hopkins, Minnesota, USA (Reunion Location)']
runtimes = ['112']
... LOTS more info about the movie!
Kent
More information about the Tutor
mailing list