2006年02月13日 星期一 21:26
请问如何控制模块中定义的class或者function对其它的模块不可见呢? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060213/acc263a4/attachment.htm
2006年02月13日 星期一 21:46
Python的对象模型很简单,基于命名约定,没有真正的访问限定,如果一定需要,考虑用C/C++扩展。 在06-2-13,ajax chelsea <ajaxchelsea at gmail.com> 写道: > > 请问如何控制模块中定义的class或者function对其它的模块不可见呢? > _______________________________________________ > 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 > > -- 欢迎访问: http://blog.csdn.net/ccat 刘鑫 March.Liu -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060213/449fcc16/attachment.html
2006年02月13日 星期一 21:51
python中没有对public private及protect专门定义,但是有相应的处理办法 在类中以又下划线的变量被看作是私有的例:__tt 全局变量,局部变量,类变量,实例变量都有相应的定义方法,查看一下相关资料会明白的具体的我也讲不太清楚以免误导了你 ajax chelsea <ajaxchelsea at gmail.com> 写道: 请问如何控制模块中定义的class或者function对其它的模块不可见呢? _______________________________________________ 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 --------------------------------- 雅虎1G免费邮箱百分百防垃圾信 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060213/3db43953/attachment.htm
2006年02月13日 星期一 21:58
在前面加__就可以。 On 2/13/06, 刘鑫 <march.liu at gmail.com> wrote: > Python的对象模型很简单,基于命名约定,没有真正的访问限定,如果一定需要,考虑用C/C++扩展。 > > 在06-2-13,ajax chelsea <ajaxchelsea at gmail.com> 写道: > > 请问如何控制模块中定义的class或者function对其它的模块不可见呢? > > _______________________________________________ > > 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 > > > > > > > > -- > 欢迎访问: > http://blog.csdn.net/ccat > > 刘鑫 > March.Liu > > _______________________________________________ > 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 > > -- http://www.flyaflya.com
2006年02月13日 星期一 22:33
不管用啊 ----chess.py def __faint(): print 'faint' ----caller.py import chess chess.__faint() 还是正常运行啊 在06-2-13,flya flya <flyaflya at gmail.com> 写道: > > 在前面加__就可以。 > > On 2/13/06, 刘鑫 <march.liu at gmail.com> wrote: > > Python的对象模型很简单,基于命名约定,没有真正的访问限定,如果一定需要,考虑用C/C++扩展。 > > > > 在06-2-13,ajax chelsea <ajaxchelsea at gmail.com> 写道: > > > 请问如何控制模块中定义的class或者function对其它的模块不可见呢? > > > _______________________________________________ > > > 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 > > > > > > > > > > > > > > -- > > 欢迎访问: > > http://blog.csdn.net/ccat > > > > 刘鑫 > > March.Liu > > > > _______________________________________________ > > 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 > > > > > > > -- > http://www.flyaflya.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 > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060213/86dce4b3/attachment.html
2006年02月13日 星期一 23:05
On 2/13/06, ajax chelsea <ajaxchelsea at gmail.com> wrote: > 不管用啊 > > ----chess.py > > def __faint(): > print 'faint' > > > ----caller.py > > import chess > > chess.__faint() > > 还是正常运行啊 > 模块不行。__是用在类中的。 -- I like python! My Blog: http://www.donews.net/limodou NewEdit Maillist: http://groups.google.com/group/NewEdit
2006年02月13日 星期一 23:16
那是不是就可以将不打算公开给其它模块的function弄个class包进去,函数名加个__前缀? -----some.py----- def pub_function(): pass class impl: def __private_function(self): pass 在06-2-13,limodou <limodou at gmail.com> 写道: > > On 2/13/06, ajax chelsea <ajaxchelsea at gmail.com> wrote: > > 不管用啊 > > > > ----chess.py > > > > def __faint(): > > print 'faint' > > > > > > ----caller.py > > > > import chess > > > > chess.__faint() > > > > 还是正常运行啊 > > > > 模块不行。__是用在类中的。 > > > -- > I like python! > My Blog: http://www.donews.net/limodou > NewEdit Maillist: http://groups.google.com/group/NewEdit > > _______________________________________________ > 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 > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060213/814a193c/attachment-0001.htm
2006年02月13日 星期一 23:25
On 2/13/06, ajax chelsea <ajaxchelsea at gmail.com> wrote: > 那是不是就可以将不打算公开给其它模块的function弄个class包进去,函数名加个__前缀? > 在python中还没有真正不能访问的。就是改成__也有办法。而且写成class的方法,那么有可能还要设成类方法,这样才不用创建实例。 -- I like python! My Blog: http://www.donews.net/limodou NewEdit Maillist: http://groups.google.com/group/NewEdit
2006年02月13日 星期一 23:39
怎么才能设置为类方法呢? 在06-2-13,limodou <limodou at gmail.com> 写道: > > On 2/13/06, ajax chelsea <ajaxchelsea at gmail.com> wrote: > > 那是不是就可以将不打算公开给其它模块的function弄个class包进去,函数名加个__前缀? > > > > 在python中还没有真正不能访问的。就是改成__也有办法。而且写成class的方法,那么有可能还要设成类方法,这样才不用创建实例。 > > -- > I like python! > My Blog: http://www.donews.net/limodou > NewEdit Maillist: http://groups.google.com/group/NewEdit > > _______________________________________________ > 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 > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060213/168349d9/attachment.html
2006年02月14日 星期二 00:28
On 2/13/06, ajax chelsea <ajaxchelsea at gmail.com> wrote: > 怎么才能设置为类方法呢? > 有两种: staticmethod 和 classmethod 参见python文档中的built-in function部分 -- I like python! My Blog: http://www.donews.net/limodou NewEdit Maillist: http://groups.google.com/group/NewEdit
2006年02月14日 星期二 12:42
那它能表达protected的语义嘛?? ============================== limodou <limodou at gmail.com> Sent by: python-chinese-bounces at lists.python.cn 2006-02-14 00:28 Please respond to python-chinese at lists.python.cn To python-chinese at lists.python.cn cc Subject Re: [python-chinese] Python中有没有public,protected,private? On 2/13/06, ajax chelsea <ajaxchelsea at gmail.com> wrote: > 怎么才能设置为类方法呢? > 有两种: staticmethod 和 classmethod 参见python文档中的built-in function部分 -- I like python! My Blog: http://www.donews.net/limodou NewEdit Maillist: http://groups.google.com/group/NewEdit _______________________________________________ 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060214/ab56bfd3/attachment.htm
2006年02月14日 星期二 13:06
On 2/14/06, andy.bu at kodak.com <andy.bu at kodak.com> wrote: > > 那它能表达protected的语义嘛?? > ============================== > 不能。在python中目前来说从官方版本支持的好象就只有在class中可以设置私有成员。对于模块无法设置。staticmethod和classmethod它们只是象c++中的静态成员方法,可以不用实例化即可以调用。没有protected这个控制。 Python因为相对简单,因此不需要很复杂的访问权限控制。在zope3中可能有一些,具体的不了解。不过不是官方版本所缺省实现的。 -- I like python! My Blog: http://www.donews.net/limodou NewEdit Maillist: http://groups.google.com/group/NewEdit
2006年02月14日 星期二 13:10
OK , i see . thank you. ============================== limodou <limodou at gmail.com> Sent by: python-chinese-bounces at lists.python.cn 2006-02-14 13:06 Please respond to python-chinese at lists.python.cn To python-chinese at lists.python.cn cc Subject Re: [python-chinese] Python 中有没有public,protected,private? On 2/14/06, andy.bu at kodak.com <andy.bu at kodak.com> wrote: > > 那它能表达protected的语义嘛?? > ============================== > 不能。在python中目前来说从官方版本支持的好象就只有在class中可以设置私有成 员。对于模块无法设置。staticmethod和classmethod它们只是象c++中的静态成员方 法,可以不用实例化即可以调用。没有protected这个控制。 Python因为相对简单,因此不需要很复杂的访问权限控制。在zope3中可能有一些, 具体的不了解。不过不是官方版本所缺省实现的。 -- I like python! My Blog: http://www.donews.net/limodou NewEdit Maillist: http://groups.google.com/group/NewEdit _______________________________________________ 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060214/5a3bfb94/attachment.htm
2006年02月14日 星期二 17:48
可不可以将"私有"的函数弄到单独的模块中,然后在Package的__all__中不包括这个模块? 在06-2-14,limodou <limodou at gmail.com> 写道: > > On 2/14/06, andy.bu at kodak.com <andy.bu at kodak.com> wrote: > > > > 那它能表达protected的语义嘛?? > > ============================== > > > > > 不能。在python中目前来说从官方版本支持的好象就只有在class中可以设置私有成员。对于模块无法设置。staticmethod和classmethod它们只是象c++中的静态成员方法,可以不用实例化即可以调用。没有protected这个控制。 > > Python因为相对简单,因此不需要很复杂的访问权限控制。在zope3中可能有一些,具体的不了解。不过不是官方版本所缺省实现的。 > > -- > I like python! > My Blog: http://www.donews.net/limodou > NewEdit Maillist: http://groups.google.com/group/NewEdit > > _______________________________________________ > 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 > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060214/5071911d/attachment.html
2006年02月14日 星期二 17:54
有费这个力气,是我就自己写扩展了,呵呵。 很多Python程序员也同时会一些编译语言的。 在06-2-14,ajax chelsea <ajaxchelsea at gmail.com> 写道: > > 可不可以将"私有"的函数弄到单独的模块中,然后在Package的__all__中不包括这个模块? > > 在06-2-14,limodou <limodou at gmail.com> 写道: > > > > On 2/14/06, andy.bu at kodak.com < andy.bu at kodak.com> wrote: > > > > > > 那它能表达protected的语义嘛?? > > > ============================== > > > > > > > 不能。在python中目前来说从官方版本支持的好象就只有在class中可以设置私有成员。对于模块无法设置。staticmethod和classmethod它们只是象c++中的静态成员方法,可以不用实例化即可以调用。没有protected这个控制。 > > > > > > Python因为相对简单,因此不需要很复杂的访问权限控制。在zope3中可能有一些,具体的不了解。不过不是官方版本所缺省实现的。 > > > > -- > > I like python! > > My Blog: http://www.donews.net/limodou > > NewEdit Maillist: http://groups.google.com/group/NewEdit > > > > _______________________________________________ > > 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 > > -- 欢迎访问: http://blog.csdn.net/ccat 刘鑫 March.Liu -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060214/c82465d1/attachment.htm
2006年02月14日 星期二 17:54
On 2/14/06, ajax chelsea <ajaxchelsea at gmail.com> wrote: > 可不可以将"私有"的函数弄到单独的模块中,然后在Package的__all__中不包括这个模块? > 这种方法应该是只对使用 from xxx import * 这种方式有效。对于from xxx import __yyy 应该无效吧。 -- I like python! My Blog: http://www.donews.net/limodou NewEdit Maillist: http://groups.google.com/group/NewEdit
2006年02月14日 星期二 17:58
为啥非得要不能访问呢,来个下划线意思一下就行了 在06-2-14,limodou <limodou at gmail.com> 写道: > > On 2/14/06, ajax chelsea <ajaxchelsea at gmail.com> wrote: > > 可不可以将"私有"的函数弄到单独的模块中,然后在Package的__all__中不包括这个模块? > > > > 这种方法应该是只对使用 from xxx import * 这种方式有效。对于from xxx import __yyy 应该无效吧。 > > > -- > I like python! > My Blog: http://www.donews.net/limodou > NewEdit Maillist: http://groups.google.com/group/NewEdit > > _______________________________________________ > 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 > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060214/d6c5bfb2/attachment-0001.htm
2006年02月14日 星期二 18:03
+1 :) python is NOT c++/java ----- Original Message ----- From: helium To: python-chinese at lists.python.cn Sent: Tuesday, February 14, 2006 5:58 PM Subject: Re: [python-chinese] Python 中有没有public,protected,private? 为啥非得要不能访问呢,来个下划线意思一下就行了 在06-2-14,limodou <limodou at gmail.com> 写道: On 2/14/06, ajax chelsea <ajaxchelsea at gmail.com> wrote: > 可不可以将"私有"的函数弄到单独的模块中,然后在Package的__all__中不包括这个模块? > 这种方法应该是只对使用 from xxx import * 这种方式有效。对于from xxx import __yyy 应该无效吧。 -- I like python! My Blog: http://www.donews.net/limodou NewEdit Maillist: http://groups.google.com/group/NewEdit _______________________________________________ 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060214/e6f8ca2b/attachment.html
2006年02月14日 星期二 23:01
ok, 感谢所有人的解答,总结了一下: http://blog.csdn.net/wuliaoshengji/archive/2006/02/14/599079.aspx 在06-2-14,Slowness Chen <chenzh at bhh.com.cn> 写道: > > +1 :) > python is NOT c++/java > > ----- Original Message ----- > *From:* helium <helium.sun at gmail.com> > *To:* python-chinese at lists.python.cn > *Sent:* Tuesday, February 14, 2006 5:58 PM > *Subject:* Re: [python-chinese] Python 中有没有public,protected,private? > > > 为啥非得要不能访问呢,来个下划线意思一下就行了 > > > > 在06-2-14,limodou <limodou at gmail.com> 写道: > > > > On 2/14/06, ajax chelsea <ajaxchelsea at gmail.com> wrote: > > > 可不可以将"私有"的函数弄到单独的模块中,然后在Package的__all__中不包括这个模块? > > > > > > > 这种方法应该是只对使用 from xxx import * 这种方式有效。对于from xxx import __yyy 应该无效吧。 > > > > > > -- > > I like python! > > My Blog: http://www.donews.net/limodou > > NewEdit Maillist: http://groups.google.com/group/NewEdit > > > > _______________________________________________ > > 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 > > > _______________________________________________ > 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 > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060214/3d7316a6/attachment.htm
2006年02月15日 星期三 00:09
On 2/14/06, ajax chelsea <ajaxchelsea at gmail.com> wrote: > ok, > 感谢所有人的解答,总结了一下:http://blog.csdn.net/wuliaoshengji/archive/2006/02/14/599079.aspx > 不错。 -- I like python! My Blog: http://www.donews.net/limodou NewEdit Maillist: http://groups.google.com/group/NewEdit
2006年02月15日 星期三 00:19
哈哈,limodou先生也还没睡啊? ajax同学真不错啊,我要向你学习. On 2/15/06, limodou <limodou at gmail.com> wrote: > > On 2/14/06, ajax chelsea <ajaxchelsea at gmail.com> wrote: > > ok, > > > 感谢所有人的解答,总结了一下:http://blog.csdn.net/wuliaoshengji/archive/2006/02/14/599079.aspx > > > > 不错。 > > -- > I like python! > My Blog: http://www.donews.net/limodou > NewEdit Maillist: http://groups.google.com/group/NewEdit > > _______________________________________________ > 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 > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060215/c541c04e/attachment-0001.html
Zeuux © 2025
京ICP备05028076号