authored by Wayne Witzel III

Moving to waynewitzel.com

On February 14, 2014 In community Permalink

I've moved! Checkout the latest posts on waynewitzel.com

This site will remain online to preserve links. All new content will be at the new domain.

Read and Post Comments

Moving My Blog

On May 18, 2010 In community Permalink
I'm moving my blog to http://waynewitzel.com I have three separate blogs right now and trying to post and maintain them is a big pain in the ass. So I've consolidated all of them in to a self title blog that will range from general posts about life and news to tech posts like you've read here on Piece of Py. There will be three separate feeds on top of the Everything (http://waynewitzel.com/category/everything/feed/rss/) feed for those who only care about one aspect of the blog. * Life http://waynewitzel.com/category/life/feed/rss/ * Tech http://waynewitzel.com/category/tech/feed/rss/ * Food http://waynewitzel.com/category/food/feed/rss/ For Piece of Py subscribers, if you only care about the tech stuff use the Tech Feed.
Read and Post Comments

Python 3.0 (final) release.

On December 04, 2008 In python, community Permalink
As I am sure most of you have heard Python 3.0 (final) has been released. For me, this means some nights getting some continuing development projects updated for the language changes and freezing some projects in maintence mode with their own copy of Python 2.6 (or in some cases 2.4). Some highlights
  • print is now a function: print("5x5", "is", 5*5, sep=" ")
  • annotations for methods (I create a lot of libraries, so this is great!)
  • extended unpacking: x, y , *z = [1,2,3,4,5] now x is 1, y is 2, and z is 3-5
  • <> removed, use != (personal favorite cause I hate <>)
  • no longer can you from import * inside functions
See the whole list here: http://docs.python.org/3.0/whatsnew/3.0.html
Read and Post Comments

Blog a day or something... Proxy Pattern!

On November 03, 2008 In python, patterns, community Permalink

Been reading around and I guess November is the official blog entry a day writers month or something. I'll make a go again. In October, I tried the one post a day run for my blog. I did well, but fell short in the end. Though I've already missed the first two days in November, I'll call that the margin of error.

Oh and I believe the posts should have some meat to them. Not just another "Hey look, a post, I win November." Though as a last resort, I am not above that.

So for lack of anything better to write about, here is an oldie but goodie. A Python implementation of the proxy pattern (virtual proxy) with a real worldish feel to it.

First we define our ABC and subclass it for our needs.

class File(object):
    def load(self):
        pass

class RealFile(File): def init(self, name): self.name = name self.load()

    def load(self):
    print "Loading %s..." % (self.name)
def process1(self):
    print "[phase1] Processing %s..." % (self.name)
def process2(self):
    print "[phase2] Processing %s..." % (self.name)

Now, we can subclass File for our proxy. Now I know what you are saying. You don't need the extra levels of abstraction because Python doesn't have the levels of type sensitivity of other languages. Could you just implement this in the first RealFile subclass? Yes, but that isn't the point of this. The verbosity helps define the example and keeps this implementation language independent (mostly).

class ProxyFile(File):
    def __init__(self, name):
        self.name = name
        self.file = None

def process1(self):
        if not self.file:
            self.file = RealFile(self.name)
        self.file.process1()

def process2(self):
        if not self.file:
            self.file = RealFile(self.name)
        self.file.process2()

So you can see, this hides away the details of loading the file. Allows the user to call process1 / process2 as the business logic determines and preforms lazy loading. The Proxy pattern is very powerful when combined with other patterns. Like Null Object and Lazy loading.

def main():
    f1 = ProxyFile("bigdb01.csv")
    f2 = ProxyFile("bigdb02.csv")
    f3 = ProxyFile("bigdb03.csv")

f1.process1()
    # some busines logic
    f1.process2()
    # more BL
    f2.process2()
    # more BL
    f2.process1()
    # Hey, we found what we needed, skipped f3
    #f3.process()

if __name__ == '__main__':
    main()

You can view full source at: http://trac.pieceofpy.com/pieceofpy/browser/patterns/proxy.py

Read and Post Comments

OOPSLA 2008 - Day 3

On October 22, 2008 In community Permalink
After a few drinks at the hotel bar, we head to bed to get ready for Day 3 of OOPSLA. Keynote: Pyrimids and Software or something... I showed up late for this, but from what I gathered, it was a comparison to the Pyrmids and software. It was really facinating and I enjoyed Mark Lehner's talk about finding the lost city and everything .. but something this heavy at 8:30 in the morning is well .. yeah, neat. Introducing New Ideas Into Your Organization Linda Rising (http://lindarising.com for those of you living in a cave) gave a great tutorial on how people can get new idea into their organization. Everyone has had to deal with this at one time or another no matter where they have worked. People don't like change. They don't wanna change if they don't have to, even if all the reasons are good and they agree with the new idea, in the end, if they don't want to change, they won't. As my wife always says. "I want you to WANT to take out the garbage." Quick side note, I was speaking with Ricardo Lopez on the day previous to Linda's tutorial and his advice was to make sure you have enough in your savings for when you get fired. Now as funny as it sounds, his reason, which was being fearless and with standing pressures to make concessions was directly inline with the ideas and patterns Linda provided in her tutorial. Back to the tutorial. I arrived early (mistake), so the other early arriver's and myself ended up being actors in a play. The play of how to introduce new ideas into your organization. The play included Innovators, Early Adopters, Connectors, etc.. and how/when you can use these different types of people in the organization to our benefit and pitfalls to avoid so they don't become enemies. The Cliff notes version, get the easy ones on board first (innovators like new cool stuff), put a small step of the new idea in place with this group. Now take it to the early adopters (how depends on your corporate culture), get them involved and maybe add another step. Continue to promote this style growth until you have enough good results from this new thing to ask some of the good ol' boys who might have middle managements ear, continue on this path with Brown Bags and cookie offerings. At this point the movement itself is viral and you'll need to start tending to the delicate process of getting the upper management stamp of approval. Anyway, the tutorial was a pattern language for introducing new ideas based of her latest book and I must say, I really enjoyed the tutorial and acting out my part. Though the pattern language should be adjusted and tailored to fit your corporate culture, I think it is an excellent start for anyone having problems getting no ideas in to their company, be it agile development or more water fountains. The tutorial finished with a set of group sessions tasked with solving a member of each groups problem. You can find more information about these patterns and her on Linda's website mentioned at the start of this post. Afterwards After the keynote and tutorial, my wife and I ate at the hotel restaurant and called it a night. This conference is fun and loaded with great information and conversation, but leaves my brain so tired at the end of the day it is hard to to much else but eat some food and go to sleep.
Read and Post Comments
Next Page ยป