本文整理汇总了Python中actor.Actor.save方法的典型用法代码示例。如果您正苦于以下问题:Python Actor.save方法的具体用法?Python Actor.save怎么用?Python Actor.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类actor.Actor
的用法示例。
在下文中一共展示了Actor.save方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestActorClass
# 需要导入模块: from actor import Actor [as 别名]
# 或者: from actor.Actor import save [as 别名]
class TestActorClass(unittest.TestCase):
def setUp(self):
self.a = Actor("Best.Actor.Ever.")
def test_get_actor_name(self):
self.assertEqual("Best.Actor.Ever.", self.a.get_name())
@unittest.skip("No point in adding extra actors to db. It works, trust me")
def test_save_actor_into_database(self):
self.assertTrue(self.a.save())
示例2: MovieCatalogProgram
# 需要导入模块: from actor import Actor [as 别名]
# 或者: from actor.Actor import save [as 别名]
class MovieCatalogProgram():
def __init__(self):
self.actors = []
self.movies = OrderedDict()
self.db_path = sqlite3.connect("movie_catalog.db")
self.cursor = self.db_path.cursor()
self._load_initial_state()
def add_movie(self):
self.movie_title = input('title >')
self.movie_year = input('year >')
while True:
self.movie_rating = int(input('rating >'))
if self.movie_rating <= 10 and self.movie_rating > 0:
break
else:
print("Rating can only be a number between 1 and 10.")
self.m = Movie(self.movie_title,
self.movie_year,
self.movie_rating)
if(self.m.get_title() not in self.movies.keys()
and self.m.get_year() not in self.movies.values()):
self.movies[self.movie_title] = self.movie_year
self.m.save()
print('{} ({}) {}'.format(self.movie_title,
self.movie_year,
'was added to your catalog!'))
else:
print('Movie already exists!')
def add_actor(self, *arguments):
arguments = list(arguments)
if len(arguments) == 1:
self.name = input('name >')
self.a = Actor(self.name)
self.actors.append(self.name)
arguments.append(len(self.actors))
self.a.save()
else:
if len(self.actors) >= int(arguments[1]):
self.a = Actor(self.actors[int(arguments[1]) - 1])
else:
print("There is no actor with this id! Add new actor!")
self.name = input('name >')
self.a = Actor(self.name)
self.actors.append(self.name)
self.a.save()
self.cursor.execute("""CREATE TABLE IF NOT EXISTS relations
(movie_id, actor_id)""")
query = ("INSERT INTO relations(movie_id, actor_id) VALUES (?, ?)")
data = [int(arguments[0]), int(arguments[1])]
self.cursor.execute(query, data)
self.db_path.commit()
def list_movies(self):
i = 1
for movie in self.movies:
print('[{}] {} ({})'.format(str(i), movie, self.movies[movie]))
i += 1
def list_actors(self):
i = 1
for actor in self.actors:
print('[{}] {}'.format(str(i), actor))
i += 1
def actor_info(self, id):
self.__id = id
movies_ids = []
movies_actor_is_in = []
lines = []
query = ("SELECT Name FROM actors WHERE id = ?")
data = [self.__id]
actor = self.cursor.execute(query, data)
for line in actor:
actor_name = line[0]
query = ("SELECT movie_id FROM relations WHERE actor_id = ?")
for line in self.cursor.execute(query, data):
movies_ids.append(line[0])
for i in range(len(movies_ids)):
query = ("SELECT * FROM movies WHERE id = ?")
data = [movies_ids[i]]
movies_actor_is_in.append(self.cursor.execute(query, data))
for movie_actor_is_in in movies_actor_is_in:
for line in movies_actor_is_in:
for data in line:
lines.append(data)
break
print('{} stars in:'.format(actor_name))
for line in lines:
print('[{}] {} ({})'.format(line[0], line[1], line[2]))
def movie_info(self, id):
self.__id = id
query = ("SELECT * FROM movies WHERE id = ?")
data = [self.__id]
movie = self.cursor.execute(query, data)
actors_ids = []
cast = []
#.........这里部分代码省略.........