Python论坛  - 讨论区

标题:[python-chinese] 怎样截取字段

2006年05月01日 星期一 23:56

tocer tocer.deng at gmail.com
Mon May 1 23:56:07 HKT 2006

第 9 行缩进不对
第 10 行改成:
li.search(str).groups()

biosedit at gmail.com 写道:
> |#!/usr/bin/python
>   3 |# This Python file uses the following encoding: utf-8
>   4 |import re
>   5 |pattern='^[^1]'
>   6 |f=open('/var/log/apache2/access.log','r')
>   7 |readlines=f.readlines()
>   8 |for str in readlines:
>   9 |     li =re.compile(pattern)
>  10 |    li.search(pattern).groups()
>  11 |f.close()
>     |
> File "./http.py", line 9
>    li.search(pattern).groups()
>                              ^
> IndentationError: unindent does not match any outer indentation level
>
http://www.woodpecker.org.cn/obp/diveintopython-zh-5.4/zh-cn/dist/html/toc/index.html
>
> groups()该怎么用

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年05月02日 星期二 14:39

biosedit at gmail.com biosedit at gmail.com
Tue May 2 14:39:44 HKT 2006

|#!/usr/bin/python
   3 |# This Python file uses the following encoding: utf-8
   4 |import re
   5 |list=[]
   6 |pattern='^[^1]'
   7 |f=open('/var/log/apache2/access.log','r')
   8 |readlines=f.readlines()
   9 |for str in readlines:
  10 |	 li =re.compile(pattern)
  11 |   print li.search('/var/log/apache2/access.log').groups()
  12 |f.close()
     |
返回的是1000多个()


在 06-5-1,tocer<tocer.deng at gmail.com> 写道:
> 第 9 行缩进不对
> 第 10 行改成:
> li.search(str).groups()
>
> biosedit at gmail.com 写道:
> > |#!/usr/bin/python
> >   3 |# This Python file uses the following encoding: utf-8
> >   4 |import re
> >   5 |pattern='^[^1]'
> >   6 |f=open('/var/log/apache2/access.log','r')
> >   7 |readlines=f.readlines()
> >   8 |for str in readlines:
> >   9 |     li =re.compile(pattern)
> >  10 |    li.search(pattern).groups()
> >  11 |f.close()
> >     |
> > File "./http.py", line 9
> >    li.search(pattern).groups()
> >                              ^
> > IndentationError: unindent does not match any outer indentation level
> >
> http://www.woodpecker.org.cn/obp/diveintopython-zh-5.4/zh-cn/dist/html/toc/index.html
> >
> > groups()该怎么用
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年05月02日 星期二 15:16

tocer tocer.deng at gmail.com
Tue May 2 15:16:19 HKT 2006

你想要什么结果?具体说说。

biosedit at gmail.com 写道:
> |#!/usr/bin/python
>   3 |# This Python file uses the following encoding: utf-8
>   4 |import re
>   5 |list=[]
>   6 |pattern='^[^1]'
>   7 |f=open('/var/log/apache2/access.log','r')
>   8 |readlines=f.readlines()
>   9 |for str in readlines:
>  10 |     li =re.compile(pattern)
>  11 |   print li.search('/var/log/apache2/access.log').groups()
>  12 |f.close()
>     |
> 返回的是1000多个()

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年05月02日 星期二 16:18

biosedit at gmail.com biosedit at gmail.com
Tue May 2 16:18:02 HKT 2006

删除与^1[2,9]匹配的行,打印余下的行

在 06-5-2,tocer<tocer.deng at gmail.com> 写道:
> 你想要什么结果?具体说说。
>
> biosedit at gmail.com 写道:
> > |#!/usr/bin/python
> >   3 |# This Python file uses the following encoding: utf-8
> >   4 |import re
> >   5 |list=[]
> >   6 |pattern='^[^1]'
> >   7 |f=open('/var/log/apache2/access.log','r')
> >   8 |readlines=f.readlines()
> >   9 |for str in readlines:
> >  10 |     li =re.compile(pattern)
> >  11 |   print li.search('/var/log/apache2/access.log').groups()
> >  12 |f.close()
> >     |
> > 返回的是1000多个()
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年05月02日 星期二 16:29

tocer tocer.deng at gmail.com
Tue May 2 16:29:01 HKT 2006

#!/usr/bin/python
# This Python file uses the following encoding: utf-8

import re
pattern='^1[2,9]'
li =re.compile(pattern)
f=open('/var/log/apache2/access.log','r')
for str in f.readlines():
    if not li.match(str): print str
f.close()


biosedit at gmail.com 写道:
> 删除与^1[2,9]匹配的行,打印余下的行
>
> 在 06-5-2,tocer<tocer.deng at gmail.com> 写道:
>> 你想要什么结果?具体说说。

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年05月02日 星期二 18:24

biosedit at gmail.com biosedit at gmail.com
Tue May 2 18:24:10 HKT 2006

非常感谢前辈回帖,我会慢慢看这些函数的

在 06-5-2,tocer<tocer.deng at gmail.com> 写道:
> #!/usr/bin/python
> # This Python file uses the following encoding: utf-8
>
> import re
> pattern='^1[2,9]'
> li =re.compile(pattern)
> f=open('/var/log/apache2/access.log','r')
> for str in f.readlines():
>     if not li.match(str): print str
> f.close()
>
>
> biosedit at gmail.com 写道:
> > 删除与^1[2,9]匹配的行,打印余下的行
> >
> > 在 06-5-2,tocer<tocer.deng at gmail.com> 写道:
> >> 你想要什么结果?具体说说。
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年05月02日 星期二 18:29

tocer tocer.deng at gmail.com
Tue May 2 18:29:57 HKT 2006

不客气。

5.1了,好好休息吧:)

biosedit at gmail.com 写道:
> 非常感谢前辈回帖,我会慢慢看这些函数的
>
> 在 06-5-2,tocer<tocer.deng at gmail.com> 写道:
>> #!/usr/bin/python
>> # This Python file uses the following encoding: utf-8
>>
>> import re
>> pattern='^1[2,9]'
>> li =re.compile(pattern)
>> f=open('/var/log/apache2/access.log','r')
>> for str in f.readlines():
>>     if not li.match(str): print str
>> f.close()
>>
>>
>> biosedit at gmail.com 写道:
>> > 删除与^1[2,9]匹配的行,打印余下的行
>> >
>> > 在 06-5-2,tocer<tocer.deng at gmail.com> 写道:
>> >> 你想要什么结果?具体说说。
>> _______________________________________________
>> python-chinese
>> Post: send python-chinese at lists.python.cn
>> Subscribe: send subscribe to python-chinese-request at lists.python.cn
>> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
>> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号