2005年11月14日 星期一 17:08
主要是用来提取IP地址的。对Python的函数还不熟,所以请教了。 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20051114/aaf5f2bb/attachment.htm
2005年11月14日 星期一 17:35
use package 're' 在 2005年11月14日 星期一 17:08,超卓 写道: > 主要是用来提取IP地址的。对Python的函数还不熟,所以请教了。
2005年11月14日 星期一 17:38
大哥你的邮件标题。。。。你用什么客户端? 在 05-11-14,amingsc<amingsc at 163.com> 写道: > use package 're' > > 在 2005年11月14日 星期一 17:08,超卓 写道: > > 主要是用来提取IP地址的。对Python的函数还不熟,所以请教了。 > > _______________________________________________ > Python中文技术讨论邮件列表 > 发言: 发邮件到 python-chinese at lists.python.cn > 订阅: 发送 subscribe 到 python-chinese-request at lists.python.cn > 退订: 发送 unsubscribe 到 python-chinese-request at lists.python.cn > 详细说明: http://python.cn/mailman/listinfo/python-chinese > > -- Blog:http://www.donews.net/changzheng Blog:http://qingfeng.ushared.com/blog/ MagnoliaCMS:http://www.magnolia.com.cn/
2005年11月14日 星期一 18:52
在 05-11-14,超卓<chaoszhuo at gmail.com> 写道: > 主要是用来提取IP地址的。对Python的函数还不熟,所以请教了。 我刚看玩byte of python的数据结构那一部分,自己写个小程序看看能不能解决 主要是解决ip地址的也许可以处理了 #!/usr/bin/python #Filename:ip.py #Use to split ip #author:zhaoguang ipAddress="192.168.0.1" def ipSplit(ipAddress): ipScrap=0 finalIp=[''] ipLen=len(ipAddress) print 'ipLen is',ipLen i=0 for i in range(0,int(ipLen)): if ipAddress[i]=='.': ipScrap=ipScrap+1 finalIp.append('') #ipLen=ipLen-1 else: finalIp[ipScrap]=finalIp[ipScrap]+ipAddress[i] #ipLen=ipLen-1 else: print '\nipSplit() done.\n' i=0 for i in range(0,4): print 'Section %d of Ip is %s' % (i,finalIp[i]) ipSplit(ipAddress) -- /********************************************************** * Love in Gentoo-Linux C and Python * Look at my blog * http://poorc.wordpress.com **********************************************************/
2005年11月14日 星期一 19:21
在 05-11-14,赵光<prolibertine at gmail.com> 写道: > 在 05-11-14,超卓<chaoszhuo at gmail.com> 写道: > > 主要是用来提取IP地址的。对Python的函数还不熟,所以请教了。 > 我刚看玩byte of python的数据结构那一部分,自己写个小程序看看能不能解决 > 主要是解决ip地址的也许可以处理了 > > #!/usr/bin/python > #Filename:ip.py > #Use to split ip > #author:zhaoguang > > ipAddress="192.168.0.1" > def ipSplit(ipAddress): > ipScrap=0 > finalIp=[''] > ipLen=len(ipAddress) > print 'ipLen is',ipLen > i=0 > for i in range(0,int(ipLen)): > if ipAddress[i]=='.': > ipScrap=ipScrap+1 > finalIp.append('') > #ipLen=ipLen-1 > else: > finalIp[ipScrap]=finalIp[ipScrap]+ipAddress[i] > #ipLen=ipLen-1 > else: > print '\nipSplit() done.\n' > i=0 > for i in range(0,4): > print 'Section %d of Ip is %s' % (i,finalIp[i]) > > ipSplit(ipAddress) 正则表达式是一种方式,另一种简单的方式可以直接使用 a = '192.168.0.1' v = map(int, a.split('.')) -- I like python! My Blog: http://www.donews.net/limodou NewEdit Maillist: http://groups.google.com/group/NewEdit
2005年11月14日 星期一 19:25
在 05-11-14,limodou<limodou at gmail.com> 写道: > > 正则表达式是一种方式,另一种简单的方式可以直接使用 > > a = '192.168.0.1' > v = map(int, a.split('.')) 不好意思,搞的太麻烦,误导群众 -- /********************************************************** * Love in Gentoo-Linux C and Python * Look at my blog * http://poorc.wordpress.com **********************************************************/
2005年11月14日 星期一 19:35
在 05-11-14,赵光<prolibertine at gmail.com> 写道: > 在 05-11-14,limodou<limodou at gmail.com> 写道: > > > > 正则表达式是一种方式,另一种简单的方式可以直接使用 > > > > a = '192.168.0.1' > > v = map(int, a.split('.')) > > 不好意思,搞的太麻烦,误导群众 > 这没什么,刚开始对python的东西不熟,自力更生是好的。随着熟悉会有越来越好的方法。多交流就会提高得很快。 -- I like python! My Blog: http://www.donews.net/limodou NewEdit Maillist: http://groups.google.com/group/NewEdit
2005年11月14日 星期一 20:12
ipAddress="192.168.0.1"
finalIp=ipAddress.split('.')
print finalIp
在 2005年11月14日 星期一 18:52,赵光 写道:
> 在 05-11-14,超卓<chaoszhuo at gmail.com> 写道:
>
> > 主要是用来提取IP地址的。对Python的函数还不熟,所以请教了。
>
> 我刚看玩byte of python的数据结构那一部分,自己写个小程序看看能不能解决
> 主要是解决ip地址的也许可以处理了
>
> #!/usr/bin/python
> #Filename:ip.py
> #Use to split ip
> #author:zhaoguang
>
> ipAddress="192.168.0.1"
> def ipSplit(ipAddress):
> ipScrap=0
> finalIp=['']
> ipLen=len(ipAddress)
> print 'ipLen is',ipLen
> i=0
> for i in range(0,int(ipLen)):
> if ipAddress[i]=='.':
> ipScrap=ipScrap+1
> finalIp.append('')
> #ipLen=ipLen-1
> else:
> finalIp[ipScrap]=finalIp[ipScrap]+ipAddress[i]
> #ipLen=ipLen-1
> else:
> print '\nipSplit() done.\n'
> i=0
> for i in range(0,4):
> print 'Section %d of Ip is %s' % (i,finalIp[i])
>
> ipSplit(ipAddress)
>
> --
> /**********************************************************
> * Love in Gentoo-Linux C and Python
> * Look at my blog
> * http://poorc.wordpress.com
> **********************************************************/
2005年11月14日 星期一 20:34
清风 wrote: > 在 05-11-14,amingsc<amingsc at 163.com> 写道: >>use package 're' > > 大哥你的邮件标题。。。。你用什么客户端? [top post fixed] amingsc用的是KDE的KMail,标题编码是gbk,而gmail目前还不支持gbk编码。 -- Qiangning Hong, Registered Linux User #396996 My Blog: http://www.hn.org/hongqn RSS: http://feeds.feedburner.com/hongqn
2005年11月14日 星期一 21:17
太感动了,大家这么支持
对于limodou的回复,有个问题
如果Ip地址是这样的格式"x.x.x.x/y"呢?
我试过,在split()里,应该是不支持[]的表达方式。因此不能使用split('[./]',s)这样的方式。这样的话有什么好办法呢?
在05-11-14,Qiangning Hong <hongqn at gmail.com> 写道:
>
> 清风 wrote:
> > 在 05-11-14,amingsc<amingsc at 163.com> 写道:
> >>use package 're'
> >
> > 大哥你的邮件标题。。。。你用什么客户端?
>
> [top post fixed]
>
> amingsc用的是KDE的KMail,标题编码是gbk,而gmail目前还不支持gbk编码。
>
> --
> Qiangning Hong, Registered Linux User #396996
> My Blog: http://www.hn.org/hongqn
> RSS: http://feeds.feedburner.com/hongqn
>
> _______________________________________________
> Python中文技术讨论邮件列表
> 发言: 发邮件到 python-chinese at lists.python.cn
> 订阅: 发送 subscribe 到 python-chinese-request at lists.python.cn
> 退订: 发送 unsubscribe 到 python-chinese-request at lists.python.cn
> 详细说明: http://python.cn/mailman/listinfo/python-chinese
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20051114/81d167cd/attachment.html
2005年11月14日 星期一 21:22
在 05-11-14,超卓<chaoszhuo at gmail.com> 写道: > 太感动了,大家这么支持 > > 对于limodou的回复,有个问题 > > 如果Ip地址是这样的格式"x.x.x.x/y"呢? > 我试过,在split()里,应该是不支持[]的表达方式。因此不能使用split('[./]',s)这样的方式。这样的话有什么好办法呢? > > 先使用split('/') 把格式"x.x.x.x/y"分成x.x.x.x和y,然后在对x.x.x.x分就可以了吧 两次使用 -- /********************************************************** * Love in Gentoo-Linux C and Python * Look at my blog * http://poorc.wordpress.com **********************************************************/
2005年11月14日 星期一 21:29
这个办法我用了,可以达到效果,不过好像有点土,没有Perl里面的灵活。是不是只能这样了? 在05-11-14,赵光 <prolibertine at gmail.com> 写道: > > 在 05-11-14,超卓<chaoszhuo at gmail.com> 写道: > > 太感动了,大家这么支持 > > > > 对于limodou的回复,有个问题 > > > > 如果Ip地址是这样的格式"x.x.x.x/y"呢? > > 我试过,在split()里,应该是不支持[]的表达方式。因此不能使用split('[./]',s)这样的方式。这样的话有什么好办法呢? > > > > > 先使用split('/') > 把格式"x.x.x.x/y"分成x.x.x.x和y,然后在对x.x.x.x分就可以了吧 > 两次使用 > > -- > /********************************************************** > * Love in Gentoo-Linux C and Python > * Look at my blog > * http://poorc.wordpress.com > **********************************************************/ > > _______________________________________________ > Python中文技术讨论邮件列表 > 发言: 发邮件到 python-chinese at lists.python.cn > 订阅: 发送 subscribe 到 python-chinese-request at lists.python.cn > 退订: 发送 unsubscribe 到 python-chinese-request at lists.python.cn > 详细说明: http://python.cn/mailman/listinfo/python-chinese > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20051114/cb09fb37/attachment.htm
2005年11月14日 星期一 21:31
在 05-11-14,赵光<prolibertine at gmail.com> 写道: > 在 05-11-14,超卓<chaoszhuo at gmail.com> 写道: > > 太感动了,大家这么支持 > > > > 对于limodou的回复,有个问题 > > > > 如果Ip地址是这样的格式"x.x.x.x/y"呢? > > 我试过,在split()里,应该是不支持[]的表达方式。因此不能使用split('[./]',s)这样的方式。这样的话有什么好办法呢? > > > > > 先使用split('/') > 把格式"x.x.x.x/y"分成x.x.x.x和y,然后在对x.x.x.x分就可以了吧 > 两次使用 > 对于复杂的那可以使用正则表达式。简单的就如上面,先去掉/后面的东西,再使用 split处理,如果不知道可能有什么,那么可以: >>> import re >>> b = re.search('(\w{1,3}).(\w{1,3}).(\w{1,3}).(\w{1,3})', 'http://192.168.0.1/test') >>> b.groups() ('192', '168', '0', '1') -- I like python! My Blog: http://www.donews.net/limodou NewEdit Maillist: http://groups.google.com/group/NewEdit
2005年11月14日 星期一 21:51
这样的结果应该是:
>>>b = re.search('(\w{1,3}).(\w{1,3}).(\w{1,3}).(\w{1,3})/(\w{1,2})',
'http://192.168.0.1/test')
>>>b.group()
'192.168.0.1 <http://192.168.0.1>'
所以如果需要连掩码也要的话就变成了:
>>>b = re.search('(\w{1,3}).(\w{1,3}).(\w{1,3}).(\w{1,3})/(\w{1,2})',
'http://192.168.0.1/13')
>>>b.group()
'192.168.0.1/13 <http://192.168.0.1/13>'
这样,掩码还是没有被拆出来。
在05-11-14,limodou <limodou at gmail.com> 写道:
>
> 在 05-11-14,赵光<prolibertine at gmail.com> 写道:
> > 在 05-11-14,超卓<chaoszhuo at gmail.com> 写道:
> > > 太感动了,大家这么支持
> > >
> > > 对于limodou的回复,有个问题
> > >
> > > 如果Ip地址是这样的格式"x.x.x.x/y"呢?
> > > 我试过,在split()里,应该是不支持[]的表达方式。因此不能使用split('[./]',s)这样的方式。这样的话有什么好办法呢?
> > >
> > >
> > 先使用split('/')
> > 把格式"x.x.x.x/y"分成x.x.x.x和y,然后在对x.x.x.x分就可以了吧
> > 两次使用
> >
>
> 对于复杂的那可以使用正则表达式。简单的就如上面,先去掉/后面的东西,再使用 split处理,如果不知道可能有什么,那么可以:
>
> >>> import re
> >>> b = re.search('(\w{1,3}).(\w{1,3}).(\w{1,3}).(\w{1,3})',
> 'http://192.168.0.1/test')
> >>> b.groups()
> ('192', '168', '0', '1')
>
> --
> I like python!
> My Blog: http://www.donews.net/limodou
> NewEdit Maillist: http://groups.google.com/group/NewEdit
>
> _______________________________________________
> Python中文技术讨论邮件列表
> 发言: 发邮件到 python-chinese at lists.python.cn
> 订阅: 发送 subscribe 到 python-chinese-request at lists.python.cn
> 退订: 发送 unsubscribe 到 python-chinese-request at lists.python.cn
> 详细说明: http://python.cn/mailman/listinfo/python-chinese
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20051114/761dcfdd/attachment.html
2005年11月14日 星期一 21:52
我特别不理解的是什么在这里正则表达式 [] 不被支持!是我理解有问题么? 在05-11-14,超卓 <chaoszhuo at gmail.com> 写道: > > 这样的结果应该是: > >>>b = re.search('(\w{1,3}).(\w{1,3}).(\w{1,3}).(\w{1,3})/(\w{1,2})', > 'http://192.168.0.1/test') > >>>b.group() > '192.168.0.1 <http://192.168.0.1/>' > 所以如果需要连掩码也要的话就变成了: > >>>b = re.search('(\w{1,3}).(\w{1,3}).(\w{1,3}).(\w{1,3})/(\w{1,2})', > 'http://192.168.0.1/13') > >>>b.group() > '192.168.0.1/13 <http://192.168.0.1/13>' > 这样,掩码还是没有被拆出来。 > 在05-11-14,limodou <limodou at gmail.com> 写道: > > > > 在 05-11-14,赵光<prolibertine at gmail.com> 写道: > > > 在 05-11-14,超卓< chaoszhuo at gmail.com> 写道: > > > > 太感动了,大家这么支持 > > > > > > > > 对于limodou的回复,有个问题 > > > > > > > > 如果Ip地址是这样的格式"x.x.x.x/y"呢? > > > > 我试过,在split()里,应该是不支持[]的表达方式。因此不能使用split('[./]',s)这样的方式。这样的话有什么好办法呢? > > > > > > > > > > > 先使用split('/') > > > 把格式"x.x.x.x/y"分成x.x.x.x和y,然后在对x.x.x.x分就可以了吧 > > > 两次使用 > > > > > > > 对于复杂的那可以使用正则表达式。简单的就如上面,先去掉/后面的东西,再使用 split处理,如果不知道可能有什么,那么可以: > > > > >>> import re > > >>> b = re.search('(\w{1,3}).(\w{1,3}).(\w{1,3}).(\w{1,3})', > > 'http://192.168.0.1/test') > > >>> b.groups() > > ('192', '168', '0', '1') > > > > -- > > I like python! > > My Blog: http://www.donews.net/limodou > > NewEdit Maillist: http://groups.google.com/group/NewEdit > > > > _______________________________________________ > > Python中文技术讨论邮件列表 > > 发言: 发邮件到 python-chinese at lists.python.cn > > 订阅: 发送 subscribe 到 python-chinese-request at lists.python.cn > > 退订: 发送 unsubscribe 到 python-chinese-request at lists.python.cn > > 详细说明: http://python.cn/mailman/listinfo/python-chinese > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20051114/470eed2c/attachment-0001.htm
2005年11月14日 星期一 21:58
在 05-11-14,超卓<chaoszhuo at gmail.com> 写道: > 这样的结果应该是: > >>>b = > re.search('(\w{1,3}).(\w{1,3}).(\w{1,3}).(\w{1,3})/(\w{1,2})', > 'http://192.168.0.1/test') > >>>b.group() > '192.168.0.1 ' > > 所以如果需要连掩码也要的话就变成了: > >>>b = > re.search('(\w{1,3}).(\w{1,3}).(\w{1,3}).(\w{1,3})/(\w{1,2})', > 'http://192.168.0.1/13') > >>>b.group() > '192.168.0.1/13 ' > 这样,掩码还是没有被拆出来。 > > 在05-11-14,limodou <limodou at gmail.com> 写道: > > > > 在 05-11-14,赵光<prolibertine at gmail.com> 写道: > > > 在 05-11-14,超卓< chaoszhuo at gmail.com> 写道: > > > > 太感动了,大家这么支持 > > > > > > > > 对于limodou的回复,有个问题 > > > > > > > > 如果Ip地址是这样的格式"x.x.x.x/y"呢? > > > > > 我试过,在split()里,应该是不支持[]的表达方式。因此不能使用split('[./]',s)这样的方式。这样的话有什么好办法呢? > > > > > > > > > > > 先使用split('/') > > > 把格式"x.x.x.x/y"分成x.x.x.x和y,然后在对x.x.x.x分就可以了吧 > > > 两次使用 > > > > > > > 对于复杂的那可以使用正则表达式。简单的就如上面,先去掉/后面的东西,再使用 > split处理,如果不知道可能有什么,那么可以: > > > > >>> import re > > >>> b = > re.search('(\w{1,3}).(\w{1,3}).(\w{1,3}).(\w{1,3})', > > 'http://192.168.0.1/test') > > >>> b.groups() > > ('192', '168', '0', '1') > > 你好象没看清我的例子呀,结果我都列出来了。你少了一个s呀,应该是groups()。group表示整个匹配串,而groups是指()包起来的。 -- I like python! My Blog: http://www.donews.net/limodou NewEdit Maillist: http://groups.google.com/group/NewEdit
2005年11月14日 星期一 22:28
哦,对不起。再试试 在05-11-14,limodou <limodou at gmail.com> 写道: > > 在 05-11-14,超卓<chaoszhuo at gmail.com> 写道: > > 这样的结果应该是: > > >>>b = > > re.search('(\w{1,3}).(\w{1,3}).(\w{1,3}).(\w{1,3})/(\w{1,2})', > > 'http://192.168.0.1/test') > > >>>b.group() > > '192.168.0.1 <http://192.168.0.1> ' > > > > 所以如果需要连掩码也要的话就变成了: > > >>>b = > > re.search('(\w{1,3}).(\w{1,3}).(\w{1,3}).(\w{1,3})/(\w{1,2})', > > 'http://192.168.0.1/13') > > >>>b.group() > > '192.168.0.1/13 <http://192.168.0.1/13> ' > > 这样,掩码还是没有被拆出来。 > > > > 在05-11-14,limodou <limodou at gmail.com> 写道: > > > > > > 在 05-11-14,赵光<prolibertine at gmail.com> 写道: > > > > 在 05-11-14,超卓< chaoszhuo at gmail.com> 写道: > > > > > 太感动了,大家这么支持 > > > > > > > > > > 对于limodou的回复,有个问题 > > > > > > > > > > 如果Ip地址是这样的格式"x.x.x.x/y"呢? > > > > > > > 我试过,在split()里,应该是不支持[]的表达方式。因此不能使用split('[./]',s)这样的方式。这样的话有什么好办法呢? > > > > > > > > > > > > > > 先使用split('/') > > > > 把格式"x.x.x.x/y"分成x.x.x.x和y,然后在对x.x.x.x分就可以了吧 > > > > 两次使用 > > > > > > > > > > 对于复杂的那可以使用正则表达式。简单的就如上面,先去掉/后面的东西,再使用 > > split处理,如果不知道可能有什么,那么可以: > > > > > > >>> import re > > > >>> b = > > re.search('(\w{1,3}).(\w{1,3}).(\w{1,3}).(\w{1,3})', > > > 'http://192.168.0.1/test') > > > >>> b.groups() > > > ('192', '168', '0', '1') > > > > > 你好象没看清我的例子呀,结果我都列出来了。你少了一个s呀,应该是groups()。group表示整个匹配串,而groups是指()包起来的。 > > -- > I like python! > My Blog: http://www.donews.net/limodou > NewEdit Maillist: http://groups.google.com/group/NewEdit > > _______________________________________________ > Python中文技术讨论邮件列表 > 发言: 发邮件到 python-chinese at lists.python.cn > 订阅: 发送 subscribe 到 python-chinese-request at lists.python.cn > 退订: 发送 unsubscribe 到 python-chinese-request at lists.python.cn > 详细说明: http://python.cn/mailman/listinfo/python-chinese > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20051114/63ffa655/attachment.html
2005年11月15日 星期二 10:30
我刚改了一下编码gb18030,不知道行不行,再试试 在 2005年11月14日 星期一 20:34,Qiangning Hong 写道: > 清风 wrote: > > 在 05-11-14,amingsc<amingsc at 163.com> 写道: > > > >>use package 're' > > > > 大哥你的邮件标题。。。。你用什么客户端? > > [top post fixed] > > amingsc用的是KDE的KMail,标题编码是gbk,而gmail目前还不支持gbk编码。
2005年11月15日 星期二 10:43
在 05-11-15,amingsc<amingsc at 163.com> 写道: > 我刚改了一下编码gb18030,不知道行不行,再试试 > 标题还是不行。 -- I like python! My Blog: http://www.donews.net/limodou NewEdit Maillist: http://groups.google.com/group/NewEdit
2005年11月15日 星期二 12:34
朋友们呀,求你们了,别再回复标题是乱码的邮件了,见了就删掉算了…… 向毛主席保证:这是我最后一次回复乱码标题邮件! -- CopyLeft (^_^) Scorpio Auding -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20051115/10280c95/attachment.htm
2005年11月15日 星期二 12:43
Scorpio Auding wrote: > 朋友们呀,求你们了,别再回复标题是乱码的邮件了,见了就删掉算了…… > > 向毛主席保证:这是我最后一次回复乱码标题邮件! 前面解释过了,amingsc的标题并没有乱码,是gmail不认识gbk和gb18030编码。用 我的Thunderbird看,这个线索中,你的信是第一个出现标题乱码的(因为强行用 UTF-8解释gbk)。 同学们,去blame gmail吧 ;) 不过考虑到这个列表中gmail web用户占了绝大部分,也请使用其他客户端的同志 们注意一下,将编码设置为UTF-8或者GB2312。 -- Qiangning Hong, Registered Linux User #396996 My Blog: http://www.hn.org/hongqn RSS: http://feeds.feedburner.com/hongqn
Zeuux © 2025
京ICP备05028076号