### 抽象季节/节目/剧集数据的最佳方式

print tvdbinstance[1][23]['episodename'] # get the name of episode 23 of season 1

Tvdb()类中抽象这些数据的“最佳”方法是什么？

#### 5 个答案:

import new
myexc=new.classobj("ExcName",(Exception,),{})
i=myexc("This is the exc msg!")
raise i

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
__main__.ExcName: This is the exc msg!

self.__class__.__name__

P.S。 - 你也可以提出字符串，但这已被弃用。

raise(self.__class__.__name__+"Exception")

episodes = []
episodes.append({'season':1, 'episode': 2, 'name':'Something'})
episodes.append({'season':1, 'episode': 2, 'name':'Something', 'actors':['Billy Bob', 'Sean Penn']})

season_1 = [e for e in episodes if e['season'] == 1]
billy_bob = [e for e in episodes if 'actors' in e and 'Billy Bob' in e['actors']]

for episode in billy_bob:
print "Billy bob was in Season %s Episode %s" % (episode['season'], episode['episode'])

Bartosz /澄清“这工作没问题，但没有简单的方法来检查是否存在x [3] [24]”

x['some show'][3][24]将返回第3季第24集“some show”。如果没有第3季，我希望伪字典提高tvdb_seasonnotfound，如果“some show”不存在，则提高tvdb_shownotfound

>>>x={}
>>>x[1]={}
>>>x[1][2]={}
>>>x
{1: {2: {}}}
>>> 2 in x[1]
True
>>> 3 in x[1]
False