RE: [PyCrust] 0.6 in the oven, now with PyFilling, should be done cooking soon
Brought to you by:
pobrien
From: Patrick K. O'B. <po...@or...> - 2001-09-19 21:29:26
|
Richie Hindle had submitted a patch that added a lot of command history retrieval functionality. The only part I didn't apply was saving to and retrieving from a file. I had hoped to have a Session class developed by now, where this functionality will ultimately reside. But I am behind schedule. So in the mean time, you may want to look at the methods Richie supplied. They should work with the existing code: + def savehistory( self, filename="PyCrustHistory.txt" ): + """Saves the command history to the named file, or to PyCrustHistory.txt if no name is given.""" + # Reverse the list so that the commands come out in chronological order in the file. + commands = self.history[:] + commands.reverse() + file = open( filename, "wt" ) + for command in commands: + file.write( command + "\n" ) + file.close() + self.write( "History saved." ) + + def loadhistory( self, filename="PyCrustHistory.txt" ): + """Loads the command history from the named file, or from PyCrustHistory.txt if no name is given.""" + # Reset the history before loading up the new one. + self.history = [] + self.historyPos = -1 + file = open( filename, "rt" ) + for command in file.readlines(): + self.history.insert( 0, command[ :-1 ] ) # Strip the trailing newline. + file.close() + self.write( "History loaded." ) --- Patrick K. O'Brien Orbtech (http://www.orbtech.com) "I am, therefore I think." -----Original Message----- From: pyc...@li... [mailto:pyc...@li...]On Behalf Of Raul Cota Sent: Wednesday, September 19, 2001 1:02 PM To: pyc...@li... Subject: Re: [PyCrust] 0.6 in the oven, now with PyFilling, should be done cooking soon <snip> BTW... I'm implementing some small methods for my own purposes: def StartSavingToFile(self, filePath=None, append=false): """Begin saving all the code sent or written to the interpreter""" def CloseFile(self): """Close the file and stop saving commands""" def ChangeFileName(self, filePath, append=false): """Begins saving in a new file, copying all the info from the last file""" They are basically methods to save all the commands written in the interpreter, so the user can load them from a file. Are you interested at all ??? Raúl |