473,503 Members | 1,646 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Writing Object Data to Disk

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,

--
Amit Kumar Saha
me blogs@ http://amitksaha.blogspot.com
URL:http://amitsaha.in.googlepages.com
Sep 22 '07 #1
3 1580
In message <ma*************************************@python.or g>, Amit Kumar
Saha wrote:
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.
Sep 22 '07 #2
Amit Kumar Saha wrote:
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

--
BOFH excuse #89:

Electromagnetic energy loss

Sep 22 '07 #3
On 22/09/2007 7:16 PM, Bjoern Schliessmann wrote:
Amit Kumar Saha wrote:
>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.
So are the braces.

Sep 22 '07 #4

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

Similar topics

48
8414
by: Joseph | last post by:
Hi I'm writing a commercial program which must be reliable. It has to do some basic reading and writing to and from files on the hard disk, and also to a floppy. I have foreseen a potential...
8
3316
by: Lu | last post by:
Hi there, I got a program to write data to a randomly accessed file (the program moves file pointer to a certain position of the file according the current "keyword" and then writes data). It...
5
1913
by: Ben Jeurissen | last post by:
Hello, I have to deal with the following issue in C++: Two threads are started from the main thread, both capturing images from a different firewire camera. Both threads take shots of 460800...
3
3376
by: ishekar | last post by:
Hi, I have an application where i want to write data to a file, the data is being sent from an external source. I know the total size of the data and then i retrieve the data in small segments...
6
2407
by: Virendra Verma | last post by:
This sounds weird, but I am looking for separate behaviors for destruction of a const and non-const object. I am trying to develop a smart/auto pointer class for writing objects to disk...
16
9079
by: Ali | last post by:
Hi I want to write (or read) to a stream, but the data is not byte array I converted the data to byte array manually, but it is very slow, (becuse the data is very large) Is another way for this...
2
6839
by: melanieab | last post by:
Hi, I'm trying to store all of my data into one file (there're about 140 things to keep track of). I have no problem reading a specific string from the array file, but I wasn't sure how to...
12
3733
by: Chris Springer | last post by:
I'd like to get some feedback on the issue of storing data out to disk and where to store it. I've never been in a production environment in programming so you'll have to bear with me... My...
16
7152
by: Claudio Grondi | last post by:
I have a 250 Gbyte file (occupies the whole hard drive space) and want to change only eight bytes in this file at a given offset of appr. 200 Gbyte (all other data in that file should remain...
0
7198
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7072
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7271
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7319
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4998
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3149
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1498
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
373
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.