Oracle, Web, Script, SQLserver, Tips & Trick

August 14, 2011

Ruby-style DSL’s in Python 2.5

Filed under: phyton — sikathabis @ 6:45 am
Tags: , ,
## {{{ (r1)
from __future__ import with_statement
from contextlib import contextmanager

class Table(object):
    def __init__(self, table_name):
        self.table_name = table_name
        self.fields = {}

    def __setattr__(self, attr, value):
        if attr in ("fields", "table_name"):
            object.__setattr__(self, attr, value)
            self.fields[attr] = value

    def execute(self):
        print "Creating table %s with fields: %s" % (self.table_name, self.fields)

def create_table(table_name):
    yield table

#try it!
with create_table("Employee") as t:
    t.first_name = {"type" : "char", "length" : 30 }
    t.last_name = {"type" : "char", "length" : 30 }
    t.age = {"type" : "int"}

#Creating table Employee with fields: {'first_name': {'length':
#30, 'type': 'char'}, 'last_name': {'length': 30, 'type': 'char'}, 'age':
#{'type': 'int'}}
## end of }}}

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at

Learning is not a spectator sport

Connor McDonald's Oracle blog

Teknologi Pendidikan

Just another weblog


Jurnalisme Yang Dapat Dipercaya

Qey050489's Blog

Ayo Bangkit sobat..!!!!!

B. S. Totoraharjo

Orang Bodoh Yang Tak Kunjung Pandai

culturekitchen foodlab

New Food and Art in Yogyakarta

Wahyu Catur Wibowo

Musafir Dunia Maya

SQL.... Still Learning

My Reference on SQL Server


"A distance is getting far if your heart is impatient" -ean-


Street Photography is like a box of a chocolates, you're never know what you're gonna get - Thomas Leuthard -

Keluarga Andrivito

-- Andrivito's Journal --


This site is about Latest NEWS, Articles, Videos, Books, Course, Presentations, Tips & Tricks related to I.T Pro's

Gaurav Saxena

|| तत् त्वम् असि ||

Be a good Moeslim

Menuju Pribadi Muslim Sejati yang Bertaqwa


Manajemen Sholat, renungan spiritual, Teknologi Informasi

Pelangi di khatulistiwa....

Mari berbagi kebaikan, pengalaman dan senyum denganku


Ceritanya saya, Pikirannya saya, Hatinya saya


sikathabis semua informasi disini

%d bloggers like this: