所以我正在编写一个修改电视节目标题的python脚本。这比任何事情都更适合练习。我正在尝试使用@property 装饰器,但我误以为当您执行“var.property”时,我认为 var 会传递给属性...所以我正在尝试获取 splitName()能够使用基类中的 hasDots 属性,但我不确定如何将名称 Var 传递给属性。我知道我可以用一种方法来做到这一点,但我正在尝试学习如何使用属性。一旦我可以让基类正常工作, splitName() 方法将成为主要方法。
对此的任何帮助将不胜感激。我对python也很陌生,所以如果我正在做任何“非pythonic”的事情,请告诉我。
exceptibleExts = ['.avi','.mkv','mp4']
class Base(object):
def __init__(self, source):
self.source = source
self.isTvShow()
# this method will return the file name
def fileName(self):
for name in self.source:
name, ext = os.path.splitext(name)
yield name, ext
@property
def isTvShow(self):
names = self.fileName()
for name in names:
if str(name[1]) in exceptibleExts and str(name[1]).startswith('.') == False:
return True
else:
return False
@property
def hasDots(self):
names = self.fileName()
for name in names:
if '.' in str(name[0]):
return True
else:
return False
@property
def hasDashes(self):
names = self.fileName()
for name in names:
if '-' in str(name[0]):
return True
else:
return False
@property
def startswithNumber(self):
names = self.fileName()
for name in names:
if str(name[0].lstrip()[0].isdigit()):
return True
else:
return False
@property
def hasUnderscore(self):
names = self.fileName()
for name in names:
if '_' in str(name[0]):
return True
else:
return False
class names(Base):
def __init__(self, source):
self.source = source
#pass
self.splitName()
#this method returns true if the show title is in the file name... if not it will return false
def hasShowTitle(self):
pass
def splitName(self):
#names = self.fileNames
showInfo = {}
for name in self.fileName():
print name.hasDots