部分课程 [英] Partial classes

查看:53
本文介绍了部分课程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


无法弄清楚如何用Python编码部分类。


示例:假设我有一个代码生成器生成

业务类的一部分,其中作为客户部分由我编写。在

ruby​​(或C#)中,我将代码分成两个源文件。像这样:


GeneratedPerson.rb

班级人员

解决方案

Sanjay写道:


无法弄清楚如何用Python编码部分类。



嗨Sanjay,


据我所知,Python目前不支持

部分课程。


但是,BOO( http: //boo.codehaus.org/ ) - 这是一个类似Python的

语言的.NET CLI) - _does_支持部分类

(< a rel =nofollowhref =http://jira.codehaus.org/browse/BOO-224)\"target =_ blank> http://jira.codehaus.org/browse/BOO-224)。虽然它不是Python,但是b $ b可能有足够的相似之处让你有价值,如果

你绝对必须有部分课程。


(免责声明:我从未使用过BOO)


希望这会有所帮助。


-alex23




Sanjay写道:


大家好,


无法弄清楚如何用Python编写部分类。


示例:假设我有一个代码生成器生成

商务舱,由我自己编写的客户部分。在

ruby​​(或C#)中,我将代码分成两个源文件。像这样:


GeneratedPerson.rb

班级人员








结束班


手工制作人员.rb

班级人员







结束班级


intrepretor在两者中添加代码编写类Person。


Python中的等价物是什么?继承是一种方式,但不是在所有场景中工作。


谢谢

Sanjay


Python没有部分类的概念,因为它是一个纯编译的

时间结构。您可以通过

a元类合并不同的类定义,将所有内容放在一起,但是合并类中的某些

方法是否可用取决于哪些模块是

已导入。这可能会产生虚拟的虚拟。或运行时模块。它是一个模块,它指的是光盘上的物理文件但是纯粹的b $ b运行时构造。在创建此模块时,可以通过元类

机制将所有定义类片段的物理模块放在一起。在使用C#中的部分类重新实现它之前,我确实使用了这种结构来统一不同的访问

点。这是非常好的IMO




您好Alex,


感谢您的输入。


成为Python的新手,并且在拥有之后选择Python与

ruby​​(Turbogears vs Rails)相比,让我有点慌张。在我的公开中它应该是一个明显且易于实现的功能,并且必须是,如果还没有已经计划在未来的Python版本中。



很想听别人说话。


Sanjay


Hi All,

Not being able to figure out how are partial classes coded in Python.

Example: Suppose I have a code generator which generates part of a
business class, where as the custome part is to be written by me. In
ruby (or C#), I divide the code into two source files. Like this:

GeneratedPerson.rb
Class Person

解决方案

Sanjay wrote:

Not being able to figure out how are partial classes coded in Python.

Hi Sanjay,

To the best of my knowledge, Python currently has no support for
partial classes.

However, BOO (http://boo.codehaus.org/) - which is a Python-like
language for the .NET CLI)- _does_ support partial classes
(http://jira.codehaus.org/browse/BOO-224). While it _isn''t_ Python,
there could be enough similarities to make this worthwhile for you if
you absolutely have to have partial classes.

(Disclaimer: I''ve never used BOO)

Hope this helps.

-alex23



Sanjay wrote:

Hi All,

Not being able to figure out how are partial classes coded in Python.

Example: Suppose I have a code generator which generates part of a
business class, where as the custome part is to be written by me. In
ruby (or C#), I divide the code into two source files. Like this:

GeneratedPerson.rb
Class Person
.
.
.

End Class

HandcraftedPerson.rb
Class Person
.
.
.
End Class

The intrepretor adds the code in both to compose the class Person.

What is the equivalent in Python? Inheriting is a way, but is not
working in all scenerios.

Thanks
Sanjay

Python has no notion of a partial class because it is a pure compile
time construct. You might merge different class definitions by means of
a meta class that puts everything together but whether or not certain
methods in the merged class are available depends on which modules are
imported. This might give rise to a "virtual" or runtime module. It is
not a module that refers to a physical file on the disc but is a pure
runtime construct. When creating this module all physical modules that
define class fragments might be put together by means of the metaclass
mechanism. I indeed used this construction to unify different access
points before I reimplemented it using partial classes in C# which are
very fine IMO.


Hi Alex,

Thanks for the input.

Being new to Python, and after having selected Python in comparison to
ruby (Turbogears vs Rails) , is jerks me a bit. In my openion it should
be an obvious and easy to implement feature and must be, if not already
have been, planned in future releases of Python.

Would love to listen to others.

Sanjay


这篇关于部分课程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆