© Copyright 2000-2020 Source Code Online. Free Source Code and Scripts Downloads.
|Code Listing by Ori Peleg|
Overriding __setattr__ in classes requires care when setting attributes yourself. Here's an idea for safely setting attributes in __init__.
Update: this idea doesn't work. See Mike Foord's recipe for one that does:
When comparing text generated on different platforms, the newlines are different. This recipe normalizes any string to use unix-style newlines.
This code is used in the TestOOB unit testing framework (http://testoob.sourceforge.net).
Adding new format specifiers to the logging module.
In this example, it's for the user name and the name of the function that logged the message.
A 'fields' class is a class that acts like a struct full of fields, e.g.:
def __init__(self, name): self.name = name
def dr(self): return "Dr. " + self.name
expand_tabs.py - Similar to Unix's expand(1) command, but can edit the files in-place.
Convert strings to floats in the range [0, 1), using a hash function
Create an proxy that forwards methods to a group of observers
Extremely simple/straightforward implementation.
Posted mainly to receive comments on alternative implementations.
Great for deciding automatically whether to use colors.
Based on http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/475116
Note: This recipe is superceded by TestOOB, a Python unit testing framework that extends unittest and provides many new features - including running tests in threads! http://testoob.sourceforge.net
Trying to extend unittest to provide...
All files and free downloads are copyright of their respective owners. We do not provide any hacked, cracked, illegal, pirated version of scripts, codes, components downloads. All files are downloaded from the publishers website, our file servers or download mirrors. Always Virus check files downloaded from the web specially zip, rar, exe, trial, full versions etc. Download links from rapidshare, depositfiles, megaupload etc not published.