Pickle: several class instance objects in one file?
Hi everyone I've never used the module 'pickle' so far, thus I've got some questions about how to use it: Lets say I have instances of class A and class B: a = A() b = B() Is it possible to pickle both of these instances to the same pkl-file or will that have any bad impact for unpickle (i.e. the instance are 'mixed' or 'destroyed')? Or should I rather use a seperate file for every class instance I want to pickle? Another very basic question about pickling class instances: To store the value of attributes of an instance is it enough for the pickling-algorithm to use the __dict__ or do I have to implement the _setstate_ and _getstate_ function? I didn't really get the meaning of those while reading the python user manual... Thanks in advance Dominique -- http://mail.python.org/mailman/listinfo/python-list
Easy install / setuptools
Hi everyone I'm trying to figure out the "best" way to distribute my own python packages. Basicly, what I want is to have something like an "installer.exe" (on windows) which puts my package under Python/Lib/site-packages (so that it can be found via the PYTHONPATH). I've played around a bit with "easy install" and "setuptools" and the .egg format. I've already managed to create a "myPackage.egg" file with setup tools and "install" (it's just a copying) it ito the site-packages directory using "easy install". What I was wondering now is if there's a way to actually EXTRACT the egg file and put the extracted file (i.e. the .py file) under site-packages. And not the .egg? The problem with egg files is that you can't use "open(os.path.join(os.path.dirname(__file__),'myFile')" and I'd need to rewrite such code which I'd like to avoid if possible. Also, I don't know whether leaving the python scripts packed inside the egg file is slower for execution or not... Would be cool if someone could give me some inputs on how to distribute python packages in an easy and effective way :-) Thx in advance Dominique * This e-mail and any files attached are strictly confidential, may be legally privileged and are intended solely for the addressee. If you are not the intended recipient please notify the sender immediately by return email and then delete the e-mail and any attachments immediately. The views and or opinions expressed in this e-mail are not necessarily the views of De La Rue plc or any of its subsidiaries and the De La Rue Group of companies, their directors, officers and employees make no representation about and accept no liability for its accuracy or completeness. You should ensure that you have adequate virus protection as the De La Rue Group of companies do not accept liability for any viruses. De La Rue plc Registered No.3834125, De La Rue Holdings plc Registered No 58025 and De La Rue International Limited Registered No 720284 are all registered in England with their registered office at: De La Rue House, Jays Close, Viables, Hampshire RG22 4BS * -- http://mail.python.org/mailman/listinfo/python-list
Problem with TimedRotatingFileHandler
Hi everyone I'm trying to use python's logging mechanism to write exception data into a log file with the TimedRotatingFileHandler but the rotating of the file is not working... Here's a bit of sample code of what I'm doing (just the interessting part of it ;-)): import logging import logging.handlers as handlers class MyError(Exception): fileName = os.path.join(os.path.dirname(__file__), 'Error.log') def __init__(self): fileHandler = handlers.TimedRotatingFileHandler(MyError.fileName, when='m', interval=1, backupCount=1) formatter = logging.Formatter('\n%(name)-12s: <%(asctime)s> %(levelname)-8s %(message)s') fileHandler.setFormatter(formatter) logging.getLogger('').addHandler(fileHandler) ## Reference to the logger object self.logger = logging.getLogger('FileLogger') self.logger.setLevel(logging.INFO) class MyInheritedError(MyError): def __init__(self): MyError.__init__(self) self.logger.error("some stupid text :-)") The error classes do write into the log file, however there's no rotating. No new file is created (and old ones renamed) nor are there any old log entries deleted/replaced... Does anyone have any idea what I could be missing? Might it be a problem due to the fact that these classes inherit from "Exception"? Would be really cool if some1 could help me :) * This e-mail and any files attached are strictly confidential, may be legally privileged and are intended solely for the addressee. If you are not the intended recipient please notify the sender immediately by return email and then delete the e-mail and any attachments immediately. The views and or opinions expressed in this e-mail are not necessarily the views of De La Rue plc or any of its subsidiaries and the De La Rue Group of companies, their directors, officers and employees make no representation about and accept no liability for its accuracy or completeness. You should ensure that you have adequate virus protection as the De La Rue Group of companies do not accept liability for any viruses. De La Rue plc Registered No.3834125, De La Rue Holdings plc Registered No 58025 and De La Rue International Limited Registered No 720284 are all registered in England with their registered office at: De La Rue House, Jays Close, Viables, Hampshire RG22 4BS * -- http://mail.python.org/mailman/listinfo/python-list
Problem with method overriding from base class
Hello everyone I have defined some sort of 'interface class' and a factory function that creates instance objects of specific classes, which implement that interface: Interface definition: *** import GUI.webGUI as webGUI class EditInterface(webGUI.WebGUI): def addEntry(self, *p): raise 'EditInterface.addEntry(): Interface must not be called directly' def clearScreen(self, *p): raise 'EditInterface.clearScreen(): Interface must not be called directly' def deleteEntry(self, *p): raise 'EditInterface.deleteEntry(): Interface must not be called directly' def editEntry(self, *p): raise 'EditInterface.editEntry(): Interface must not be called directly' def processUserInput(self, *p): raise 'EditInterface.processUserInput(): Interface must not be called directly' def show(self, entry, statustext): raise 'EditInterface.show(): Interface must not be called directly' *** Factory: *** def factory(type, *p): if type == common.databaseEntryTypes[0]: return module1.Class1(*p); elif type == common.databaseEntryTypes[1]: return module2.Class2(*p); elif type == common.databaseEntryTypes[2]: return module3.Class3(*p); elif type == common.databaseEntryTypes[3]: return module4.Class4(*p); *** Implementing Class1: *** import editInterface class Class1(editInterface.EditInterface): def __init__(self, product, database): # do something here ... def showEntry(self, entry, statustext): # do something here as well, return some string... *** Now, when I want to create an Instance of Class1 I do: myClass1Instance = factory.factory(common.databaseEntryTypes[1], 'Name', databaseObj ) Which seems to work fine according to the debugger. But when I do next: msg = myClass1Instance.show(firstEntry, '') Then the show() method of the class 'EditInterface' is called instead of the show() method of the class 'Class1' !! Does anyone have an idea why the method of the base class is called instead of the method of the derived class and how can I do it, so that the show() of Class1 is called instead? Greetings Dominique (did some data hiding there, but shouldn't really matter for the problem ;-)) -- http://mail.python.org/mailman/listinfo/python-list
Subprocess module
Hello all I want to convert a tex file into a pdf by using pdflatex. For that, I thought the 'subprocess' module might be a good option. My code doesn't work at all tho: Import os, subprocess def main(): scriptpath = os.path.dirname(__file__) p = subprocess.Popen("pdflatex --include-directory=%s --output-directory=%s/output --aux-directory=%s/temp --interaction=nonstopmode myFile.tex" % (scriptpath, scriptpath, scriptpath), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, cwd=scriptpath) (child_stdin, child_stdout, child_stderr) = (p.stdin, p.stdout, p.stderr) print 'stdin' print child_stdin print 'stdout' print child_stdout print 'stderr' print child_stderr When I run that code I get the following printouts: stdin ', mode 'wb' at 0x009E7968> stdout ', mode 'rb' at 0x009E7A40> stderr ', mode 'rb' at 0x009E79F8> Done The pdf file however is not created, nor are there any tex-temporary files (like *.log or *.aux) created. If I include a 'p.wait()' I see the python.exe and the pdflatex.exe processes are running, but I have it to terminate them manually (they never finish). My system is winXP btw. Does anyone have an idea what could be wrong? The reason why I want to use the Popen class is because it has the wait() function, so I can wait for the childprocess (pdflatex) to terminate before I start it again (because you need to run pdflatex several times to get all the references/index things correct in the generated pdf). Thanks for help, Dominique -- http://mail.python.org/mailman/listinfo/python-list
Problems with os.walk
Hi everyone The following code: scriptPath = os.path.dirname(__file__) (dirpath, dirnames, filenames) = os.walk(scriptPath) print 'dirpath\n' print dirpath print 'dirnames\n' pprint.pprint(dirnames) print 'filenames\n' pprint.pprint(filnames) Fails on the os.walk call with the following error: (dirpath, dirnames, filenames) = os.walk(scriptPath) ValueError: need more than 1 value to unpack Any ideas what could be wrong? Thx & greetings Dominique * This e-mail and any files attached are strictly confidential, may be legally privileged and are intended solely for the addressee. If you are not the intended recipient please notify the sender immediately by return email and then delete the e-mail and any attachments immediately. The views and or opinions expressed in this e-mail are not necessarily the views of De La Rue plc or any of its subsidiaries and the De La Rue Group of companies, their directors, officers and employees make no representation about and accept no liability for its accuracy or completeness. You should ensure that you have adequate virus protection as the De La Rue Group of companies do not accept liability for any viruses. De La Rue plc Registered No.3834125, De La Rue Holdings plc Registered No 58025 and De La Rue International Limited Registered No 720284 are all registered in England with their registered office at: De La Rue House, Jays Close, Viables, Hampshire RG22 4BS * -- http://mail.python.org/mailman/listinfo/python-list