472,364 Members | 2,087 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,364 software developers and data experts.

Best way to have intermediate object description format

Hi,
Is there any standard text format for storing data of object oriented
nature.
The text file should be readable.

That is, Is there any better way than having to write out a file like
this from the original place and read it in python and process it.

#----------------------------
world = World(name='MyWorld')
world.objects.append(Box(color='red'))
world.objects.append(Circle(color='green'))
world.someProp = "123"
#-----------------------------

Thanks.
Suresh

Nov 3 '06 #1
4 1175

jm*******@no.spam.gmail.com wrote:
Hi,
Is there any standard text format for storing data of object oriented
nature.
The text file should be readable.

That is, Is there any better way than having to write out a file like
this from the original place and read it in python and process it.

#----------------------------
world = World(name='MyWorld')
world.objects.append(Box(color='red'))
world.objects.append(Circle(color='green'))
world.someProp = "123"
#-----------------------------

Thanks.
Suresh
XML ?
YAML ?
JSON ?
ConfigParser module ?
CSV file ?
UML ?

I'm finding it hard to be more specific, given your original post. so
just squirted some data formats that are supported by multiple
languages and can be used to transfer data between them.

P.S. I don't know why I put XML first :-)
P.P.S. And UML seems to be about pretty diagrams rather than a textual
format, but no doubt, with the size of the companies behind it, there's
probably a textual format hidden in their too.
- Paddy.

Nov 3 '06 #2
Thanks paddy, Since the original language from which I am translating
does not support any of these formats, I will have to write one myself.
So, which one is easy to write out in a C like environment.

regards,
Suresh
Paddy wrote:
jm*******@no.spam.gmail.com wrote:
Hi,
Is there any standard text format for storing data of object oriented
nature.
The text file should be readable.

That is, Is there any better way than having to write out a file like
this from the original place and read it in python and process it.

#----------------------------
world = World(name='MyWorld')
world.objects.append(Box(color='red'))
world.objects.append(Circle(color='green'))
world.someProp = "123"
#-----------------------------

Thanks.
Suresh

XML ?
YAML ?
JSON ?
ConfigParser module ?
CSV file ?
UML ?

I'm finding it hard to be more specific, given your original post. so
just squirted some data formats that are supported by multiple
languages and can be used to transfer data between them.

P.S. I don't know why I put XML first :-)
P.P.S. And UML seems to be about pretty diagrams rather than a textual
format, but no doubt, with the size of the companies behind it, there's
probably a textual format hidden in their too.
- Paddy.
Nov 3 '06 #3
jm*******@no.spam.gmail.com wrote:
Hi,
Is there any standard text format for storing data of object oriented
nature.
The text file should be readable.

That is, Is there any better way than having to write out a file like
this from the original place and read it in python and process it.

#----------------------------
world = World(name='MyWorld')
world.objects.append(Box(color='red'))
world.objects.append(Circle(color='green'))
world.someProp = "123"
#-----------------------------

Thanks.
Suresh
While it is a little hard to determine your exact use case, I'll
try. I have an application that dynamically creates objects from
..INI configuration file. I use ConfigParser to process it. The
entries are something like the following:

[world_MyWorld]
object_001=Box(color='red')
object_002=Circle(color='green')
property_someProp=123
property_someOtherProp=XYZ

I then read using ConfigParser and use list comprehensions to isolate
what I'm looking for in the file. Code not tested, but should serve as
and example and I think you will get the idea. Note: Please don't get
too caught up in "premature optimization". I use this to process .INI
files with thousands of lines and it goes through the process in fractions
of a second.

-Larry
Sample Code (written completely from my memory):

INI=ConfigParser.ConfigParser()
INI.read(inifilepath)
#
# Get a list of the world sections in the .INI file
#
world_sections=[section for section in INI.sections()
if section.beginswith('world')
..
.. Get lists of any other objects/sections here
..
#
# Create a list to store your instances of world_objects
#
world_instances=[]
#
# Loop over all the sections in the .INI file that create world objects
#
for section in world_sections:
#
# Isolate the name of this world object
#
name=section.split('_')[1]
obj=World(name=name)
#
# Create a list to store world instance objects here
#
world_objects=[object for object in INI.options(section)
if object.startswith('object')]
#
# Loop over all the instance objects defined and append them here
#
for object in world_objects:
#
# Use eval to create object then append it. Note: eval is
# dangerous if you don't control the .INI file. Untrusted .INI
# file could have eval doing BAD things.
#
obj.append(eval(object))
#
# Create a list to store world instance properties here
#
world_properties=[object for object in INI.options(section)
if object.startswith('property')]
#
# Loop over all the instance objects defined and append them here
#
for property in world_properties:
value=INI.get(section, property)
property_name=property.split('_')[1]
#
# Use setattr to set the property
#
setattr(obj, property_name, value)

#
# Append this world object onto the list
#
world_instances.append(obj)
Nov 3 '06 #4

jm*******@no.spam.gmail.com wrote:
Thanks paddy, Since the original language from which I am translating
does not support any of these formats, I will have to write one myself.
So, which one is easy to write out in a C like environment.

regards,
Suresh
Paddy wrote:
jm*******@no.spam.gmail.com wrote:
Hi,
Is there any standard text format for storing data of object oriented
nature.
The text file should be readable.
>
That is, Is there any better way than having to write out a file like
this from the original place and read it in python and process it.
>
#----------------------------
world = World(name='MyWorld')
world.objects.append(Box(color='red'))
world.objects.append(Circle(color='green'))
world.someProp = "123"
#-----------------------------
>
Thanks.
Suresh
XML ?
YAML ?
JSON ?
ConfigParser module ?
CSV file ?
UML ?

I'm finding it hard to be more specific, given your original post. so
just squirted some data formats that are supported by multiple
languages and can be used to transfer data between them.

P.S. I don't know why I put XML first :-)
P.P.S. And UML seems to be about pretty diagrams rather than a textual
format, but no doubt, with the size of the companies behind it, there's
probably a textual format hidden in their too.
- Paddy.
Could you write out the data as a series of python dicts to file
ending in .py?,

If it is hard to write out the data in the language you are coming from
then it might be easier to stick to a simple format like CSV (comma
separated value/tab separated value), and then put more smarts in the
Python reader to reconstruct your objects.

- Paddy.

Nov 3 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: brianobush | last post by:
# # My problem is that I want to create a # class, but the variables aren't known # all at once. So, I use a dictionary to # store the values in temporarily. # Then when I have a complete set, I...
16
by: D Witherspoon | last post by:
I am developing a Windows Forms application in VB.NET that will use .NET remoting to access the data tier classes. A very simple way I have come up with is by creating typed (.xsd) datasets. For...
13
by: deko | last post by:
I use this convention frequently: Exit_Here: Exit Sub HandleErr: Select Case Err.Number Case 3163 Resume Next Case 3376 Resume Next
4
by: Sasha | last post by:
Hi everyone, What is the best way to implement many-to-many relationship between objects? Any examples or links are welcome! Thank you, Sasha
14
by: 42 | last post by:
Hi, Stupid question: I keep bumping into the desire to create classes and properties with the same name and the current favored naming conventions aren't automatically differentiating them......
0
by: Anonieko Ramos | last post by:
ASP.NET Forms Authentication Best Practices Dr. Dobb's Journal February 2004 Protecting user information is critical By Douglas Reilly Douglas is the author of Designing Microsoft ASP.NET...
3
by: Patrick.O.Ige | last post by:
I'm loading an Array below but getting the error "Object reference not set to an instance saying 'ItemNumber = CType(Args.Item.FindControl("ItemNumber"), TextBox).Text' is the error line. I DON'T...
29
by: gs | last post by:
let say I have to deal with various date format and I am give format string from one of the following dd/mm/yyyy mm/dd/yyyy dd/mmm/yyyy mmm/dd/yyyy dd/mm/yy mm/dd/yy dd/mmm/yy mmm/dd/yy
1
by: Muchach | last post by:
Hello, Ok so what I've got going on is a form that is populated by pulling info from database then using php do{} to create elements in form. I have a text box in each table row for the user to...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.