- 主题:python的字符串有长度限制吗
今天我想听张国荣的共同度过的国语版,虾米一搜居然没版权。于是我找到一个专辑,发现里面带水印的。
TITLE "Leslie Cheung 张国荣 LPCD45"
PERFORMER "张国荣"
REM DATE "2008"
REM DISCID E3103E10
FILE "Leslie Cheung 张国荣 LPCD45.flac" WAVE
TRACK 01 AUDIO
TITLE "奔向未来日子"
PERFORMER "张国荣"
REM COMMENT "[www.pt80.net]"
INDEX 01 00:00:00
TRACK 02 AUDIO
TITLE "由零开始"
PERFORMER "张国荣"
REM COMMENT "[www.pt80.net]"
INDEX 00 04:29:50
INDEX 01 04:34:50
TRACK 03 AUDIO
TITLE "这是爱"
PERFORMER "张国荣"
REM COMMENT "[www.pt80.net]"
INDEX 00 08:41:70
INDEX 01 08:46:70
TRACK 04 AUDIO
TITLE "似水流年"
PERFORMER "张国荣"
REM COMMENT "[www.pt80.net]"
INDEX 00 12:28:42
INDEX 01 12:33:42
TRACK 05 AUDIO
TITLE "情难自控"
PERFORMER "张国荣"
REM COMMENT "[www.pt80.net]"
INDEX 00 16:50:17
INDEX 01 16:55:17
TRACK 06 AUDIO
TITLE "你在何地"
PERFORMER "张国荣"
REM COMMENT "[www.pt80.net]"
INDEX 00 21:09:35
INDEX 01 21:14:35
TRACK 07 AUDIO
TITLE "烈火灯蛾"
PERFORMER "张国荣"
REM COMMENT "[www.pt80.net]"
INDEX 00 26:16:41
INDEX 01 26:21:41
TRACK 08 AUDIO
TITLE "浓情"
PERFORMER "张国荣"
REM COMMENT "[www.pt80.net]"
INDEX 00 30:37:65
INDEX 01 30:42:65
TRACK 09 AUDIO
TITLE "想你"
PERFORMER "张国荣"
REM COMMENT "[www.pt80.net]"
INDEX 00 34:16:59
INDEX 01 34:21:59
TRACK 10 AUDIO
TITLE "雪中情"
PERFORMER "张国荣"
REM COMMENT "[www.pt80.net]"
INDEX 00 39:16:50
INDEX 01 39:21:50
TRACK 11 AUDIO
TITLE "风再起时"
PERFORMER "张国荣"
REM COMMENT "[www.pt80.net]"
INDEX 00 43:22:08
INDEX 01 43:27:08
TRACK 12 AUDIO
TITLE "沉默是金"
PERFORMER "张国荣"
REM COMMENT "[www.pt80.net]"
INDEX 00 47:55:56
INDEX 01 48:00:56
TRACK 13 AUDIO
TITLE "共同渡过"
PERFORMER "张国荣"
REM COMMENT "[www.pt80.net]"
INDEX 00 52:07:62
INDEX 01 52:12:62
TRACK 14 AUDIO
TITLE "寂寞夜晚"
PERFORMER "张国荣"
REM COMMENT "[www.pt80.net]"
INDEX 00 56:35:65
INDEX 01 56:40:65
TRACK 15 AUDIO
TITLE "无需要太多"
PERFORMER "张国荣"
REM COMMENT "[www.pt80.net]"
INDEX 00 61:05:07
INDEX 01 61:10:07
TRACK 16 AUDIO
TITLE "倩女幽魂"
PERFORMER "张国荣"
REM COMMENT "[www.pt80.net]"
INDEX 00 65:36:17
INDEX 01 65:41:16
--
FROM 101.93.15.*
是否可以用在线的python把水印的那行删除?
【 在 javame 的大作中提到: 】
: 今天我想听张国荣的共同度过的国语版,虾米一搜居然没版权。于是我找到一个专辑,发现里面带水印的。
: TITLE "Leslie Cheung 张国荣 LPCD45"
: PERFORMER "张国荣"
: ...................
--
FROM 101.93.15.*
最基本的文本编辑查找替换啊,为什么要用Python编程来做?
【 在 javame (javame) 的大作中提到: 】
: 今天我想听张国荣的共同度过的国语版,虾米一搜居然没版权。于是我找到一个专辑,发现里面带水印的。
: TITLE "Leslie Cheung 张国荣 LPCD45"
: PERFORMER "张国荣"
: ...................
--
FROM 58.23.246.*
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import re
str = '''TITLE "Leslie Cheung 张国荣 LPCD45"
PERFORMER "张国荣"
REM DATE "2008"
REM DISCID E3103E10
FILE "Leslie Cheung 张国荣 LPCD45.flac" WAVE
TRACK 01 AUDIO
TITLE "奔向未来日子"
PERFORMER "张国荣"
REM COMMENT "[www.pt80.net]"
INDEX 01 00:00:00
TRACK 02 AUDIO
TITLE "由零开始"
PERFORMER "张国荣"
REM COMMENT "[www.pt80.net]"
INDEX 00 04:29:50
INDEX 01 04:34:50
TRACK 03 AUDIO
TITLE "这是爱"
PERFORMER "张国荣"
REM COMMENT "[www.pt80.net]"
INDEX 00 08:41:70
INDEX 01 08:46:70
TRACK 04 AUDIO
TITLE "似水流年"
PERFORMER "张国荣"
REM COMMENT "[www.pt80.net]"
INDEX 00 12:28:42
INDEX 01 12:33:42
TRACK 05 AUDIO
TITLE "情难自控"
PERFORMER "张国荣"
REM COMMENT "[www.pt80.net]"
INDEX 00 16:50:17
INDEX 01 16:55:17
TRACK 06 AUDIO
TITLE "你在何地"
PERFORMER "张国荣"
REM COMMENT "[www.pt80.net]"
INDEX 00 21:09:35
INDEX 01 21:14:35
TRACK 07 AUDIO
TITLE "烈火灯蛾"
PERFORMER "张国荣"
REM COMMENT "[www.pt80.net]"
INDEX 00 26:16:41
INDEX 01 26:21:41
TRACK 08 AUDIO
TITLE "浓情"
PERFORMER "张国荣"
REM COMMENT "[www.pt80.net]"
INDEX 00 30:37:65
INDEX 01 30:42:65
TRACK 09 AUDIO
TITLE "想你"
PERFORMER "张国荣"
REM COMMENT "[www.pt80.net]"
INDEX 00 34:16:59
INDEX 01 34:21:59
TRACK 10 AUDIO
TITLE "雪中情"
PERFORMER "张国荣"
REM COMMENT "[www.pt80.net]"
INDEX 00 39:16:50
INDEX 01 39:21:50
TRACK 11 AUDIO
TITLE "风再起时"
PERFORMER "张国荣"
REM COMMENT "[www.pt80.net]"
INDEX 00 43:22:08
INDEX 01 43:27:08
TRACK 12 AUDIO
TITLE "沉默是金"
PERFORMER "张国荣"
REM COMMENT "[www.pt80.net]"
INDEX 00 47:55:56
INDEX 01 48:00:56
TRACK 13 AUDIO
TITLE "共同渡过"
PERFORMER "张国荣"
REM COMMENT "[www.pt80.net]"
INDEX 00 52:07:62
INDEX 01 52:12:62
TRACK 14 AUDIO
TITLE "寂寞夜晚"
PERFORMER "张国荣"
REM COMMENT "[www.pt80.net]"
INDEX 00 56:35:65
INDEX 01 56:40:65
TRACK 15 AUDIO
TITLE "无需要太多"
PERFORMER "张国荣"
REM COMMENT "[www.pt80.net]"
INDEX 00 61:05:07
INDEX 01 61:10:07
TRACK 16 AUDIO
TITLE "倩女幽魂"
PERFORMER "张国荣"
REM COMMENT "[www.pt80.net]"
INDEX 00 65:36:17
INDEX 01 65:41:16'''
print re.sub(r'REM COMMENT "[www.pt80.net]"','',str);
我弄了一下,但是运行后并没有替换掉,不知道错在哪里?
【 在 callmebbser 的大作中提到: 】
: 最基本的文本编辑查找替换啊,为什么要用Python编程来做?
:
--
修改:javame FROM 101.93.15.*
FROM 101.93.15.*
我猜问题可能出在这里,python 2.7默认安装的字符集是ascii编码,当切换到utf8编码时会导致匹配失败。
但我不知道怎么修改。因为在线的python是2.7版本,所以
我只能用2.7的方法。
【 在 javame 的大作中提到: 】
: #!/usr/bin/python
: # -*- coding: UTF-8 -*-
:
: ...................
--
修改:javame FROM 101.93.15.*
FROM 101.93.15.*
你这正则式没入门
`[]`在正则式里面有特殊含义,需要转义符
btw:使用sed一行就能搞定的事情,何必用python呢
【 在 javame 的大作中提到: 】
: #!/usr/bin/python
: # -*- coding: UTF-8 -*-
:
: ...................
--
FROM 111.250.80.*
windows的gnu的sed存在bug,那个人gnu维护代码的人也跑了。
【 在 Neuralize 的大作中提到: 】
: 你这正则式没入门
: `[]`在正则式里面有特殊含义,需要转义符
: btw:使用sed一行就能搞定的事情,何必用python呢
: ...................
--
FROM 101.93.14.*
呃,那用grep也行啊,我试了下:
grep -v '"\[www.pt80.net\]"' source > dest
是可以的
【 在 javame 的大作中提到: 】
: windows的gnu的sed存在bug,那个人gnu维护代码的人也跑了。
--
FROM 180.158.189.*
sed也没毛病啊,至少针对你的问题足够了:
sed '/www.pt80.net/d' source > dst
【 在 javame 的大作中提到: 】
: windows的gnu的sed存在bug,那个人gnu维护代码的人也跑了。
--
FROM 180.158.189.*