2024-04-24 03:21:51 发布
网友
我目前正在用python索引我的音乐收藏。理想情况下,我希望我的输出文件格式为
"Artist; Album; Tracks - length - bitrate - md5 Artist2; Album2; Tracks - length - bitrate - md5"
但我似乎不知道如何做到这一点。有什么建议吗?在
如果您的输入数据是一个元组列表,每个元组有6个字符串(artist, album, tracks, length, bitrate, md5):
(artist, album, tracks, length, bitrate, md5)
for artist, album, tracks, length, bitrate, md5 in input_data: print "%s;" % artist print "%s;" % album print " %s - %s - %s - %s" % (tracks, length, bitrate, md5)
如果输入数据的格式不同,本质上也很简单,但是除非你告诉我们输入数据的格式是什么,否则我们就很难猜测。在
>>> import textwrap >>> class Album(object): ... def __init__(self, title, artist, tracks, length, bitrate, md5): ... self.title=title ... self.artist=artist ... self.tracks=tracks ... self.length=length ... self.bitrate=bitrate ... self.md5=md5 ... def __str__(self): ... return textwrap.dedent(""" ... %(artist)s; ... %(title)s; ... %(tracks)s - %(length)s - %(bitrate)s - %(md5)s"""%(vars(self))) ... >>> a=Album("album title","artist name",10,52.1,"320kb/s","4d53b0cb432ec371ca93ea30b62521d9") >>> print a artist name; album title; 10 - 52.1 - 320kb/s - 4d53b0cb432ec371ca93ea30b62521d9
如果您的输入数据是一个元组列表,每个元组有6个字符串
(artist, album, tracks, length, bitrate, md5)
:如果输入数据的格式不同,本质上也很简单,但是除非你告诉我们输入数据的格式是什么,否则我们就很难猜测。在
相关问题 更多 >
编程相关推荐