Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #20531 > unrolled thread
| Started by | Stodge <stodge@gmail.com> |
|---|---|
| First post | 2012-02-16 17:15 -0800 |
| Last post | 2012-02-17 13:57 +0100 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.lang.python
Generating class definitions at runtime in memory from XSD or JSON Stodge <stodge@gmail.com> - 2012-02-16 17:15 -0800
Re: Generating class definitions at runtime in memory from XSD or JSON Nobody <nobody@nowhere.com> - 2012-02-17 10:02 +0000
Re: Generating class definitions at runtime in memory from XSD or JSON Stefan Behnel <stefan_ml@behnel.de> - 2012-02-17 13:57 +0100
| From | Stodge <stodge@gmail.com> |
|---|---|
| Date | 2012-02-16 17:15 -0800 |
| Subject | Generating class definitions at runtime in memory from XSD or JSON |
| Message-ID | <5cf03bed-8173-4910-80d1-5716334a6184@z9g2000vbv.googlegroups.com> |
Does anyone know of a library to generate class definitions in memory, at runtime, from XSD or JSON? I know about PyXB, generateDS and some others, but they all rely on generating python source files at the command line, and then using those to parse XML. Thanks
[toc] | [next] | [standalone]
| From | Nobody <nobody@nowhere.com> |
|---|---|
| Date | 2012-02-17 10:02 +0000 |
| Message-ID | <pan.2012.02.17.10.02.26.887000@nowhere.com> |
| In reply to | #20531 |
On Thu, 16 Feb 2012 17:15:59 -0800, Stodge wrote:
> Does anyone know of a library to generate class definitions in memory,
> at runtime, from XSD or JSON? I know about PyXB, generateDS and some
> others, but they all rely on generating python source files at the
> command line, and then using those to parse XML.
You don't need a library to generate classes. If the type() function is
called with 3 arguments, it creates and returns a new class. The first
argument is the name of the class, the second argument a tuple of base
classes, the third argument is the class' dictionary. E.g.:
class Foo(Bar, Baz):
def __init__(self):
pass
could be written as:
def foo_init(self):
pass
Foo = type('Foo', (Bar, Baz), {'__init__': foo_init})
If you want to generate the function bodies from the contents of the
JSON or XML file, use exec().
[toc] | [prev] | [next] | [standalone]
| From | Stefan Behnel <stefan_ml@behnel.de> |
|---|---|
| Date | 2012-02-17 13:57 +0100 |
| Message-ID | <mailman.5917.1329483445.27778.python-list@python.org> |
| In reply to | #20531 |
Stodge, 17.02.2012 02:15: > Does anyone know of a library to generate class definitions in memory, > at runtime, from XSD or JSON? The question is: why do you want to do that? There may be other ways to do what you *actually* want to do, but we don't know what that is. Stefan
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web