Zope- Error Type: cPickle.PicklingError, Error Value: Cannot pickle objects.

ryzam at my-deja.com ryzam at my-deja.com
Mon Nov 13 00:03:25 EST 2000


Error Type: cPickle.PicklingError
Error Value: Cannot pickle objects.

I get an error when try to write data to external file from zope
product.I hacked/modified into Boring product to add more method "def
f_open(), def f_write(), def f_close()". Main purpose i split it to 3
method because i want to call looping to write to f_write() without
having open and close for each looping.It just making a loop in
f_write().

See example:
def f_open(self):
        self.f=open('ex_data.txt','w')

def f_write(self,dat1,dat2,dat3,dat4):
        self.f.write(dat1+'|'+dat2+'|'+dat3+'|'+dat4+'\n')

def f_close(self):
        self.f.close()

This method i add to the code below.


 __doc__ = """Boring product module.

 from Globals import HTMLFile      # fakes a method from a DTML file
 from Globals import MessageDialog # provid
 from Globals import Persistent    # makes an object stick in theZODB

 import OFS.SimpleItem
 import Acquisition
 import AccessControl.Role


 manage_addBoringForm = HTMLFile('boringAdd', globals())

 def manage_addBoring(self, id, title='', REQUEST=None):
    """Add a Boring to a folder."""
    self._setObject(id, Boring(id, title))
    if REQUEST is not None:
        return self.manage_main(self, REQUEST)


 class Boring(
    OFS.SimpleItem.Item,   #
    Persistent,            # Make us persistent. Yaah!
    Acquisition.Implicit,  # Uh, whatever.
    AccessControl.Role.RoleManager # Security manager.
    ):
    """Boring object.

    This is an attempt at writing a product from scratch using mostly
    Python instead of ZClasses. We'll see how it all goes.
    """

    meta_type = 'Boring' # what do people think they're adding?

    manage_options = ( # what management options are there?
	{'label': 'Edit',       'action': 'manage_main'},
	{'label': 'View',       'action': ''}, # defaults to
index_html
	{'label': 'Security',   'action': 'manage_access'},
        )

    __ac_permissions__=( # what permissions make sense for us?
	('View management screens', ('manage_tabs','manage_main')),
	('Change permissions',      ('manage_access',)           ),
	('Change Borings'     ,     ('manage_edit',)             ),
	('View Borings',            ('',)                        ),
	)

    def __init__(self, id, title=''):
        """initialise a new instance of Boring"""
        self.id = id
        self.title = title

    index_html = HTMLFile('index', globals()) # View Interface

    manage_main = HTMLFile('boringEdit', globals())

    ###  Here i add another method

    def f_open(self):
        self.f=open('ex_data.txt','w')

    def f_write(self,dat1,dat2,dat3,dat4,REQUEST=None):
        self.f.write(dat1+'|'+dat2+'|'+dat3+'|'+dat4+'\n')

    def f_close(self):
        self.f.close()

    #############################
    def manage_edit(self, title, REQUEST=None):
        """does this really need a doc string?"""
        self.title = title
	if REQUEST is not None:
	    return MessageDialog(
		title = 'Edited',
		message = "Properties for %s changed." % self.id,
		action = './manage_main',
		)

Then i make an instance to this product. Set this product with new ID.
Let say this ID is BoringWrite.

So in DTML-Document

<dtml-var standard_html_header>
<dtml-call "BoringWrite.do_open()">
<dtml-in "_.range(3)">
<dtml-call "BoringWrite.do_write('Test')">
Test
</dtml-in>
<dtml-call "Boring.do_close()">
<dtml-var standard_html_footer>


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list