标题: [问题求助] 如何把曲目表提取出来 [打印本页]
作者: netdzb 时间: 2020-4-4 08:42 标题: 如何把曲目表提取出来
本帖最后由 netdzb 于 2020-4-4 08:44 编辑
PERFORMER "Various"
TITLE "宝丽金非常老牌精选"
FILE "CDImage.ape" WAVE
TRACK 01 AUDIO
TITLE "太阳一样"
PERFORMER "刘文正"
INDEX 01 00:00:00
TRACK 02 AUDIO
TITLE "堆积情感"
PERFORMER "邝美云"
INDEX 00 03:28:07
INDEX 01 03:30:10
TRACK 03 AUDIO
TITLE "时空寄情"
PERFORMER "黄莺莺"
INDEX 00 08:24:00
INDEX 01 08:27:12
TRACK 04 AUDIO
TITLE "再见我的爱人"
PERFORMER "邓丽君"
INDEX 00 12:33:10
INDEX 01 12:36:32
TRACK 05 AUDIO
TITLE "海角天涯"
PERFORMER "王芷蕾"
INDEX 00 16:03:02
INDEX 01 16:06:07
TRACK 06 AUDIO
TITLE "廻"
PERFORMER "李恕权"
INDEX 00 19:30:30
INDEX 01 19:33:22
TRACK 07 AUDIO
TITLE "故事的真相"
PERFORMER "黄仲昆、杨林"
INDEX 00 24:04:05
INDEX 01 24:06:12
TRACK 08 AUDIO
TITLE "扬帆"
PERFORMER "阳帆"
INDEX 00 28:34:42
INDEX 01 28:37:22
======
def main():
with open('d:/test_trim.txt', 'w', encoding='UTF-8') as fout:
can_write = False
with open('d:/test.txt', 'r', encoding='UTF-8') as fin:
line=fin.readline()
while(line != ''):
if line.find('TRACK') == -1:
line = fin.readline()
continue
if line.find('TITLE') > -1:
print line
fout.write(line)
line = fin.readline()
print('Done.')
运行结果
应该是
TITLE "歌曲名",我关键的一个地方不会写。
就是输出的时候,怎么把TITLE和引号,
多余的tab去掉?
作者: wujunkai 时间: 2020-4-4 10:19
本帖最后由 wujunkai 于 2020-4-4 10:23 编辑
回复 1# netdzb 复制代码
或者复制代码
Ps:为了代码兼容性,建议使用print();
作者: netdzb 时间: 2020-4-4 10:35
我改成这样可以吗?
r'(?<=TITLE.*").+?(?=")'
因为我并不清楚title后面有几个空格,
或者是tab?
作者: wujunkai 时间: 2020-4-4 11:19
回复 3# netdzb
原则上是可以,但python不允许
作者: sxw 时间: 2020-4-17 21:31
使用 raku.org(之前叫 Perl 6):- .comb(/TITLE \s* \" <( \w+ )>\"/)[0].say if /TITLE/ for $=finish.lines
-
- =finish
- PERFORMER "Various"
- TITLE "宝丽金非常老牌精选"
- FILE "CDImage.ape" WAVE
- TRACK 01 AUDIO
- TITLE "太阳一样"
- PERFORMER "刘文正"
- INDEX 01 00:00:00
- TRACK 02 AUDIO
- TITLE "堆积情感"
- PERFORMER "邝美云"
- INDEX 00 03:28:07
- INDEX 01 03:30:10
- TRACK 03 AUDIO
- TITLE "时空寄情"
- PERFORMER "黄莺莺"
- INDEX 00 08:24:00
- INDEX 01 08:27:12
- TRACK 04 AUDIO
- TITLE "再见我的爱人"
- PERFORMER "邓丽君"
- INDEX 00 12:33:10
- INDEX 01 12:36:32
- TRACK 05 AUDIO
- TITLE "海角天涯"
- PERFORMER "王芷蕾"
- INDEX 00 16:03:02
- INDEX 01 16:06:07
- TRACK 06 AUDIO
- TITLE "廻"
- PERFORMER "李恕权"
- INDEX 00 19:30:30
- INDEX 01 19:33:22
- TRACK 07 AUDIO
- TITLE "故事的真相"
- PERFORMER "黄仲昆、杨林"
- INDEX 00 24:04:05
- INDEX 01 24:06:12
- TRACK 08 AUDIO
- TITLE "扬帆"
- PERFORMER "阳帆"
- INDEX 00 28:34:42
- INDEX 01 28:37:22
复制代码
输出:- 宝丽金非常老牌精选
- 太阳一样
- 堆积情感
- 时空寄情
- 再见我的爱人
- 海角天涯
- 廻
- 故事的真相
- 扬帆
复制代码
作者: netdzb 时间: 2020-4-17 21:36
回复 5# sxw
这个用perl 5怎么写,手上没有perl6
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |