本文整理汇总了Python中movie.Movie.read_movies方法的典型用法代码示例。如果您正苦于以下问题:Python Movie.read_movies方法的具体用法?Python Movie.read_movies怎么用?Python Movie.read_movies使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类movie.Movie
的用法示例。
在下文中一共展示了Movie.read_movies方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from movie import Movie [as 别名]
# 或者: from movie.Movie import read_movies [as 别名]
import csv
from movie import Movie
from user import User
movies = Movie.read_movies('u.item')
users = User.read_users('u.user')
class Rating:
def __init__(self, user_id, movie_id, score):
self.user_id = user_id
self.movie_id = movie_id
self.score = score
def add_rating(rating):
movie = movies[movie_id]
movie.add_rating(rating)
user = users[user_id]
user.add_rating(rating)
with open('u.data', 'r') as movies_file:
reader = csv.DictReader(movies_file, fieldnames=['user_id', 'movie_id', 'score'], delimiter='\t')
for row in reader:
user_id = row['user_id']
movie_id = row['movie_id']
score = row['score']
rating = Rating(user_id, movie_id, score)
add_rating(rating)