Writing Object Data to Disk

A

Amit Kumar Saha

Hello,

I have a Python class with data members, say:

class Foo:
def __init__(self):

self.a=7
self.b[]={1,3,4}
#couple of more lists, tuples, etc

I would like to know if "Pickling" the class object is the only way of
writing it to disk for persistent storage. Also, do we have a concept
similar to "array of objects" in Python? The number of objects is only
known at "run-time".

Thanks,
 
L

Lawrence D'Oliveiro

Amit Kumar said:
I would like to know if "Pickling" the class object is the only way of
writing it to disk for persistent storage.

Wouldn't it be better to use a language-independent data representation that
wasn't tied to Python? Also tying your external data representation to your
internal program structure (objects) makes it harder to change the program
in future.
 
B

Bjoern Schliessmann

Amit said:
I have a Python class with data members, say:

class Foo:
def __init__(self):

self.a=7
self.b[]={1,3,4}
^^
This is invalid syntax.
I would like to know if "Pickling" the class object is the only
way of writing it to disk for persistent storage.

It isn't. Every means of serialisation works, but pickling is
especially convenient if you only use Python.
Also, do we have a concept similar to "array of objects" in
Python?

You can put all objects in lists, be it a string, an integer or some
complex class instance.
The number of objects is only known at "run-time".

class and function definitions also happen at runtime. I suggest you
worked through the Python tutorial to get a deeper insight in
Python's concepts.

http://docs.python.org/tut/

Regards,


Björn
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top