动态类实例化

编程入门 行业动态 更新时间:2024-10-23 11:22:39
本文介绍了动态类实例化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个语言定义。文件,类似于: 页面:: 名称:简单 标题:简单 功能:复杂 功能:: 名称:简单 代码:简单 组件:: 名称:简单 类型:简单 数据集:复杂 等 另一方面,作为输入,我有.xml类型的文件: < page> < name> WebPage< / name> < caption>浏览器可见标题< / caption> < component> < name> Countrylist< / name> < type> dropdown< / type> < value> $ dropdownlist< / value> < function> < name> sqlSelect< / name> < code> select countries from blah into $ dropdownlist< / code> < / function> < / component> < / page> 我有一个解析器,它将通过语言定义 文件并生成以下单独的.py文件: 类页面(对象): def __init __(): self.name =无 self.caption =无 self.functions = [] 类函数(对象): def __init __(): self.name =无 self.code =无 现在我想使用像xml.dom.minidom这样的东西来解析将 ..xml文件放入根据语言 定义定义的一组类中。文件。 xml.dom.minidom 包中的parse()方法将返回一个文档实例,我可以从中获取节点 名称。说我得到了页面作为一个字符串。我如何从这条信息中实例化一个类??为了使它更明显我如何基于页面创建page()类? 字符串我有?我想制作这个通用的,所以对我来说语言 定义文件将包含页面,函数,数据集等但是 对于其他人来说里程会有所不同。 谢谢, Ognen

Hi, I have a "language definition" file, something along the lines of: page :: name : simple caption : simple function : complex function :: name : simple code : simple component :: name : simple type : simple dataset : complex etc. On the other hand as input I have .xml files of the type: <page> <name>WebPage</name> <caption>Browser Visible Caption</caption> <component> <name>Countrylist</name> <type>dropdown</type> <value>$dropdownlist</value> <function> <name>sqlSelect</name> <code>select countries from blah into $dropdownlist</code> </function> </component> </page> I have a parser that will go through the language definition file and produce the following as a separate .py file: class page(object): def __init__(): self.name = None self.caption = None self.functions = [] class function(object): def __init__(): self.name = None self.code = None Now I want to use something like xml.dom.minidom to "parse" the ..xml file into a set of classes defined according to the "language definition" file. The parse() method from the xml.dom.minidom package will return a document instance and I can get the node name from it. Say I got "page" as a string. How do I go about instantiating a class from this piece of information? To make it more obvious how do I create the page() class based on the "page" string I have? I want to make this generic so for me the language definition file will contain pages, functions, datasets etc. but for someone else mileage will vary. Thanks, Ognen

推荐答案

dropdownlist< / value> < function> < name> sqlSelect< / name> < code>选择国家 从blah into dropdownlist</value> <function> <name>sqlSelect</name> <code>select countries from blah into

下拉列表< / code> < / function> < / component> < ; / page> 我有一个解析器将通过语言定义 文件并生成以下单独的.py文件: 班级页面(对象): def __init __(): self.name =无 self .caption =无 self.functions = [] 类函数(对象): def __init __(): self.name =无 self.code =没有 现在我想使用像xml.dom.minidom这样的东西来解析将 ..xml文件放入根据语言 定义定义的一组类中。文件。 xml.dom.minidom 包中的parse()方法将返回一个文档实例,我可以从中获取节点 名称。说我得到了页面作为一个字符串。我如何从这条信息中实例化一个类??为了使它更明显我如何基于页面创建page()类? 字符串我有?我想制作这个通用的,所以对我来说语言 定义文件将包含页面,函数,数据集等但是 对于其他人来说里程会有所不同。 谢谢, Ognen dropdownlist</code> </function> </component> </page> I have a parser that will go through the language definition file and produce the following as a separate .py file: class page(object): def __init__(): self.name = None self.caption = None self.functions = [] class function(object): def __init__(): self.name = None self.code = None Now I want to use something like xml.dom.minidom to "parse" the ..xml file into a set of classes defined according to the "language definition" file. The parse() method from the xml.dom.minidom package will return a document instance and I can get the node name from it. Say I got "page" as a string. How do I go about instantiating a class from this piece of information? To make it more obvious how do I create the page() class based on the "page" string I have? I want to make this generic so for me the language definition file will contain pages, functions, datasets etc. but for someone else mileage will vary. Thanks, Ognen

Ognen Duzlevski写道: Ognen Duzlevski wrote: 我有语言定义文件,东西就行了: page :: 名称:简单说明:简单功能:复杂 功能: :名称:简单代码:简单 组件:: 名称:简单类型:简单数据集:complex 另一方面,作为输入,我有.xml文件的类型: < page> < name> WebPage< / name> < caption>浏览器可见标题< / caption> < component> < name> Countrylist< / name> < type> dropdown< ; / type> < value> Hi, I have a "language definition" file, something along the lines of: page :: name : simple caption : simple function : complex function :: name : simple code : simple component :: name : simple type : simple dataset : complex etc. On the other hand as input I have .xml files of the type: <page> <name>WebPage</name> <caption>Browser Visible Caption</caption> <component> <name>Countrylist</name> <type>dropdown</type> <value>

更多推荐

动态类实例化

本文发布于:2023-08-04 17:34:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1298264.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:实例   动态

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!