Decorator 1.2

Decorator 1.2 Download Summary

  • Language: Python
  • Platform: Windows / Linux / Mac OS / BSD / Solaris
  • License: Other Free / Open Source License - Python License
  • Databases: N/A
  • Downloads: 481
  • Released: Jun 6, 2007

Decorator 1.2 Description

This script defines a "decorator" that, rather than decorating the function, calls it, passing it a file object that it had opened as the first argument.

Of course, it makes sure to close the file upon the function's return (or nonreturn) with a try...finally block. One can use this decorator to get the effect of a Lisp-like with_open_file block in Python.

In Common Lisp, there is a very convenient macro called with-open-file that opens a file, binds the file object to a block-local variable, and then executes the block. The file is automatically closed when that block is exited.

Not having macros in Python, we generally do this with a try...finally statement, which works fine.

But let's try to (ab)use decorators to get a with-open-file block anyways. The call_with_open_file decorator kind of gives us this effect: the decorated function acts as a code block. However, unlike try...finally, it has the limitations of nested functions, so unfortunately this recipe is not quite so useful as the Lisp macro.

Nevertheless, it might stil be useful in the occasional sitation where you have to use libraries that don't let you create and finalize objects yourself, but force you to use a callback. Having no way to use a try...finally, and needing to reference (but hopefully not rebind) local variables, a decorator like the one in this recipe could help.

Decorator Bookmark

Hyperlink code:
Hyperlink for Forum code:

Decorator 1.2 Script Download Notice

Top 4 Download periodically updates information of Decorator 1.2 script from the developer, but some information may be slightly out-of-date.

Our script download links are directly from our mirrors or publisher's website. Decorator 1.2 torrent files or shared files from free file sharing and free upload services, including Rapidshare, MegaUpload, YouSendIt, MailBigFile, DropSend, HellShare, HotFile, FileServe, MediaMax, zUpload, MyOtherDrive, SendSpace, DepositFiles, Letitbit, LeapFile, DivShare or MediaFire, are not allowed!

Iterating through large file like objects

This function provides a simple iterator for the lines of a file-like object. (It also provides a flag for removing/retaining ... that I wanted to read-in a very large file-like object (say a GB or two) line by ... just begging to be used...In Python 2.3, while file objects now support this sort of single-line iteration, not ...
Python

Automatic explicit file close

This script is a drop in replacement for open() function that automatically explicitly closes the file when its input is exhausted. ...
Python

catenateFilesFactory

catenateFilesFactory script generates a catenateFiles function parameterized for common variations.Catenating (or concatenating) files is a common data processing task, but there are at least three independent binary choices for the functional requirements. This could mean 8 different functions, or one functions with three additional boolean arguments.Binary files are relatively easy to handle. So are text ...
Python

File Subclass

If the 'file' object looks for a '.filename.pkl' file which contains the seek offset of the previous end of the file, then this subclass sets the seek offset to that number before returning the file.On closing the file or StopIteration, it writes the new max offset to this pickle file. ...
Python

Curses File Manager

Curses File Manager is a curses based filemanager loosely resembling emacs dired mode. ...
Python