2004年08月28日 星期六 00:11
class的定义不是在one = A("one")以前就结束了吗?在class中我没有定义one,two变量,但是他却能够把创建的实例one,two打印出来。我学习python才2天,对python的程序结构还不则么了解,能不能就这个程序,解释一下执行过程呢?
----- Original Message -----
From: "limodou" <chatme at 263.net>
To: <python-chinese at lists.python.cn>
Sent: Friday, August 27, 2004 11:25 PM
Subject: Re: [python-chinese]python参数和self的迷惑
> lizzz49,您好!
>
> 仍然是在执行equals时才执行的呀,那里看出是定义时生效的,多加些print看看就知道了。
>
> ======= 2004-08-27 22:49:09 您在来信中写道:=======
>
> >class A(object):
> > def __init__(self,a):
> > self.a =a
> > def __str__(self):
> > return "this is " + self.a
> > def equals(self,b):
> > print one
> > print two
> > return one.a == b.a
> >one = A("one")
> >two = A("two")
> >if one.equals(two):
> > print "equals\n"
> >
> >>>>
> >this is one
> >this is two
> >>>>
> >这里的one ,two为A的实例
> >为什么在定义的时候就能使用了呢?_______________________________________________
> >python-chinese list
> >python-chinese at lists.python.cn
> >http://python.cn/mailman/listinfo/python-chinese
> >
>
> = = = = = = = = = = = = = = = = = = = =
>
>
> 致
> 礼!
>
>
> limodou
> chatme at 263.net
> 2004-08-27
>
>
--------------------------------------------------------------------------------
> _______________________________________________
> python-chinese list
> python-chinese at lists.python.cn
> http://python.cn/mailman/listinfo/python-chinese
>
2004年08月28日 星期六 03:38
dreamingk(天成),您好! 这几天大家讨论如何使用程序登陆论坛我很感兴趣,我前些日子就用Python来处理论坛里的文档。 但我没有用ClientCookie,因为我不知道有这个东西,最近刚知道。 我一直都是用Socket直接连Http的80,然后提交协议。其实很简单,你只要把IE游览这个论坛的TCP报文捕获下来,然后用Socket连就可以了。 而处理HTTP我用的是一个Div Into Python里的BaseHTMLProcessor. 这样就可以基本解决大多数的HTML处理. 但是像 ftp://music.popv.net:bbs.popv.net@218.104.78.34/游戏/莎木一章横须贺_Shenmue/Shenmue_OST2/船员の复响.mp3>网通公众网镜像 可能就有一点问题了(虽然我没测试,你可以去试试) 但我想用正则表达式处理就可以了, 例如: .*?)>.*? OK ,解决了. ======= 2004-08-27 12:56:00 您在来信中写道:======= >Xie Yanbo,您好! > > 已经按照上述方法搞定了,可以正确登陆论坛。原来的原因是我没有用ClientCookie.urlopen()来打开网页,而是用的urllib.urlopen()也不能获得正确的网页。 > 但是现在也有点问题。网页上的href都是这样的 > ftp://music.popv.net:bbs.popv.net@218.104.78.34/游戏/莎木一章横须贺_Shenmue/Shenmue_OST2/船员の复响.mp3>网通公众网镜像 > 但是我用sgml的parser解析获得的href都只有前半段 ftp://music.popv.net:bbs.popv.net@218.104.78.34/ ,这个是解析器的问题吗? > >======= 2004-08-27 11:49:26 您在来信中写道:======= > >>On 2004-08-25 11:00:1093402811 +0800, dreamingk(天成) wrote: >>> dreamingk(天成),您好! >>> >>> ClientCookie.CookieJar确实没有save 的方法 >>> MSIECookieJar 才有这个方法 >> >>研究了一下新版本的 ClientCookie,还有 Python2.4 的 cookielib, >>更新了一下那个登录 linuxforum 的代码,大家有兴趣可以看: >> >> http://xie.freezope.org/blog/2004/08/python.html >> >>_______________________________________________ >>python-chinese list >>python-chinese at lists.python.cn >>http://python.cn/mailman/listinfo/python-chinese >> > >= = = = = = = = = = = = = = = = = = = = > > > 致 >礼! > > > dreamingk(天成) > dreamingker at 163.com > 2004-08-27 > >_______________________________________________ >python-chinese list >python-chinese at lists.python.cn >http://python.cn/mailman/listinfo/python-chinese > = = = = = = = = = = = = = = = = = = = = 致 礼! Anew Anewboy at citiz.net 2004-08-28
2004年08月28日 星期六 09:46
lizzz49,您好!
python是动态语言,在对class定义时,类的方法代码并不会执行;执行的只是定义语句(def),也就是说只是把方法名和相应代码绑定起来,而不管代码是什么东西.
只有在方法被调用时,相应的代码才执行.
======= 2004-08-28 00:11:21 您在来信中写道:=======
>class的定义不是在one = A("one")以前就结束了吗?在class中我没有定义one,two变量,但是他却能够把创建的实例one,two打印出来。我学习python才2天,对python的程序结构还不则么了解,能不能就这个程序,解释一下执行过程呢?
>----- Original Message -----
>From: "limodou" <chatme at 263.net>
>To: <python-chinese at lists.python.cn>
>Sent: Friday, August 27, 2004 11:25 PM
>Subject: Re: [python-chinese]python参数和self的迷惑
>
>
>> lizzz49,您好!
>>
>> 仍然是在执行equals时才执行的呀,那里看出是定义时生效的,多加些print看看就知道了。
>>
>> ======= 2004-08-27 22:49:09 您在来信中写道:=======
>>
>> >class A(object):
>> > def __init__(self,a):
>> > self.a =a
>> > def __str__(self):
>> > return "this is " + self.a
>> > def equals(self,b):
>> > print one
>> > print two
>> > return one.a == b.a
>> >one = A("one")
>> >two = A("two")
>> >if one.equals(two):
>> > print "equals\n"
>> >
>> >>>>
>> >this is one
>> >this is two
>> >>>>
>> >这里的one ,two为A的实例
>> >为什么在定义的时候就能使用了呢?_______________________________________________
>> >python-chinese list
>> >python-chinese at lists.python.cn
>> >http://python.cn/mailman/listinfo/python-chinese
>> >
>>
>> = = = = = = = = = = = = = = = = = = = =
>>
>>
>> 致
>> 礼!
>>
>>
>> limodou
>> chatme at 263.net
>> 2004-08-27
>>
>>
>
>
>--------------------------------------------------------------------------------
>
>
>> _______________________________________________
>> python-chinese list
>> python-chinese at lists.python.cn
>> http://python.cn/mailman/listinfo/python-chinese
>> _______________________________________________
>python-chinese list
>python-chinese at lists.python.cn
>http://python.cn/mailman/listinfo/python-chinese
>
= = = = = = = = = = = = = = = = = = = =
致
礼!
0.706
0.706 at 163.com
2004-08-28
2004年08月28日 星期六 10:15
Anew,您好!
sgml的parser不能正确处理中文,所以当遇到中文的时候就自动截断了。
当然因为我的应用很简单,所以用正则表达式解决就可以。你的方法当然也是不错的。谢谢!
======= 2004-08-28 03:38:26 您在来信中写道:=======
>dreamingk(天成),您好!
>
> 这几天大家讨论如何使用程序登陆论坛我很感兴趣,我前些日子就用Python来处理论坛里的文档。
> 但我没有用ClientCookie,因为我不知道有这个东西,最近刚知道。
> 我一直都是用Socket直接连Http的80,然后提交协议。其实很简单,你只要把IE游览这个论坛的TCP报文捕获下来,然后用Socket连就可以了。
> 而处理HTTP我用的是一个Div Into Python里的BaseHTMLProcessor. 这样就可以基本解决大多数的HTML处理.
> 但是像 ftp://music.popv.net:bbs.popv.net@218.104.78.34/游戏/莎木一章横须贺_Shenmue/Shenmue_OST2/船员の复响.mp3>网通公众网镜像 可能就有一点问题了(虽然我没测试,你可以去试试)
> 但我想用正则表达式处理就可以了, 例如: .*?)>.*?
> OK ,解决了.
>
>======= 2004-08-27 12:56:00 您在来信中写道:=======
>
>>Xie Yanbo,您好!
>>
>> 已经按照上述方法搞定了,可以正确登陆论坛。原来的原因是我没有用ClientCookie.urlopen()来打开网页,而是用的urllib.urlopen()也不能获得正确的网页。
>> 但是现在也有点问题。网页上的href都是这样的
>> ftp://music.popv.net:bbs.popv.net@218.104.78.34/游戏/莎木一章横须贺_Shenmue/Shenmue_OST2/船员の复响.mp3>网通公众网镜像
>> 但是我用sgml的parser解析获得的href都只有前半段 ftp://music.popv.net:bbs.popv.net@218.104.78.34/ ,这个是解析器的问题吗?
>>
>>======= 2004-08-27 11:49:26 您在来信中写道:=======
>>
>>>On 2004-08-25 11:00:1093402811 +0800, dreamingk(天成) wrote:
>>>> dreamingk(天成),您好!
>>>>
>>>> ClientCookie.CookieJar确实没有save 的方法
>>>> MSIECookieJar 才有这个方法
>>>
>>>研究了一下新版本的 ClientCookie,还有 Python2.4 的 cookielib,
>>>更新了一下那个登录 linuxforum 的代码,大家有兴趣可以看:
>>>
>>> http://xie.freezope.org/blog/2004/08/python.html
>>>
>>>_______________________________________________
>>>python-chinese list
>>>python-chinese at lists.python.cn
>>>http://python.cn/mailman/listinfo/python-chinese
>>>
>>
>>= = = = = = = = = = = = = = = = = = = =
>>
>>
>> 致
>>礼!
>>
>>
>> dreamingk(天成)
>> dreamingker at 163.com
>> 2004-08-27
>>
>>_______________________________________________
>>python-chinese list
>>python-chinese at lists.python.cn
>>http://python.cn/mailman/listinfo/python-chinese
>>
>
>= = = = = = = = = = = = = = = = = = = =
>
>
> 致
>礼!
>
>
> Anew
> Anewboy at citiz.net
> 2004-08-28
>
>_______________________________________________
>python-chinese list
>python-chinese at lists.python.cn
>http://python.cn/mailman/listinfo/python-chinese
>
= = = = = = = = = = = = = = = = = = = =
致
礼!
dreamingk(天成)
dreamingker at 163.com
2004-08-28
Zeuux © 2025
京ICP备05028076号