Re: [Tutor] Subclassing vs. stand alone functions

2007-06-15 Thread Jorgen Bodde
Hi,

Basically you write a (sub)class when you want to preserve state
information of your instance. If the functionality in question lives
longer then the scope of the function, and will be called from
different methods to obtain the same information and state of the
functionality at that time, it is a candidate for a class.

Whenever the class lives very short, and there is no chance that
seperate threads might screw up the state of the functionality, it is
usually sufficient to keep it inside a module.

My 2ct,
- Jorgen

On 6/15/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Hi there,
>
> I am new to Python and trying to get my head around the OO stuff. I guess my 
> question is - when do you go with subclassing vs. making a standalone 
> function?
>
> Let's say you want to load a dictionary. Do I create a function that accepts 
> some argument (say a file name) and returns a dictionary, or do I subclass 
> dict and override the __init__  and __setitem__ functions to make 
> 'self-loading' dictionary? It seems the end result is the same.
>
> Here is a follow-up if you will indulge me...
>
> I created a class called WebPage which is a stand-alone class (I get that). 
> It loads a web page template, and has a function to update the replacement 
> vars with your data (updHtmlVar), and another to spit out the html to a file 
> (wrtHtml). Do you subclass WebPage for each particular page you want (because 
> you can customize it with load functions for each piece of data) or do you 
> just use it as is, and create separate functions outside the class that load 
> the data and you just use updHtmlVar to load it into your WebPage object? 
> Again, the end result is the same.
>
> (I can send code samples if it will help).
>
> Thanks,
>
> Chris
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Subclassing vs. stand alone functions

2007-06-15 Thread chrispython
Hi there,

I am new to Python and trying to get my head around the OO stuff. I guess my 
question is - when do you go with subclassing vs. making a standalone function? 

Let's say you want to load a dictionary. Do I create a function that accepts 
some argument (say a file name) and returns a dictionary, or do I subclass dict 
and override the __init__  and __setitem__ functions to make 'self-loading' 
dictionary? It seems the end result is the same.

Here is a follow-up if you will indulge me...

I created a class called WebPage which is a stand-alone class (I get that). It 
loads a web page template, and has a function to update the replacement vars 
with your data (updHtmlVar), and another to spit out the html to a file 
(wrtHtml). Do you subclass WebPage for each particular page you want (because 
you can customize it with load functions for each piece of data) or do you just 
use it as is, and create separate functions outside the class that load the 
data and you just use updHtmlVar to load it into your WebPage object? Again, 
the end result is the same.

(I can send code samples if it will help).

Thanks,

Chris
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Subclassing vs. stand alone functions

2007-06-15 Thread Senthil_OR
[EMAIL PROTECTED] wrote:
> 
> Let's say you want to load a dictionary. Do I create a function that
> accepts some argument (say a file name) and returns a dictionary, or
> do I subclass dict and override the __init__  and __setitem__
> functions to make 'self-loading' dictionary? It seems the end result
> is the same.

I am not understanding, what you mean by "loading" a dictionary or a
value in python.
You mean creating a custom dictionary? Then,
a) obj = Dict(list_of_tuples)
b) obj = mydict{}
c) def fun():
# process it and store in dict.
return mydict

These are are various ways.

Now, the question is when do you subclass?
Only when you want to extend the behaviour of particular class.

For e.g, you want to extend the Exception class to define your own
Exception, then you will subclass it.
Class MyException(Exception):
def __init__(self):
pass
def __str__(self):
return "My Exception, Hurray!"

The same, can applied to dictionary, say you want extend the behaviour
of dictionary with a get a random key-value pair.   

Next is, what if you want different instances of a class.
Well, those are the Objects.
In the class you define a property which can be variable and set those
property values when you create the objects from that Class.
 
> Do you subclass WebPage for each
> particular page you want (because you can customize it with load
> functions for each piece of data) or do you just use it as is, and
> create separate functions outside the class that load the data and

Objects.

> (I can send code samples if it will help).

Sure, please do. I might not check the email on sat/sun. But others here
are ofcourse very helpful.

I hope my explaination help u a bit.

Thanks,

-- 
Senthil


 Your own mileage may vary.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Subclassing vs. stand alone functions

2007-06-15 Thread Alan Gauld
<[EMAIL PROTECTED]> wrote 

> I am new to Python and trying to get my head around 
> the OO stuff. I guess my question is - when do you go 
> with subclassing vs. making a standalone function? 

OK, I'll take a slightly different approach than the other 
answers so far.

First: procedural and OO styles of programming are diffrent 
ways of thinking about a problem. Any programming problem 
can be solved using either approach and both approaches 
are equally good, neither is intrinsically "better" than the other.

Second: Some problems are more amenable to an OO
aproach than a procedural and vice versa. And the majority 
can be done either way with very little to choose between 
them.

I will now assume that you understand the procedural way 
and already know how to apply good procedural design, 
including modularity featuring loose coupling and tight 
cohesion. In addition data structure design and its relationship 
to your procedural design should be a concept familiar to you.
( In a perfect world you'll also be familiar with the princuiples of 
functional programming and the lambda calculus, but that's 
possibly asking too much.)

That leaves the question of why and wjen should we use OOP?
OOP suits programs that feature a high level of correspondence 
between the "real world" and the software modfel we are building.
For example simulation software (including many games) usually 
involves the representation and control of a number of objects. 
It is a natural link to model these objects as classes and create 
corresponding objects in our solution. Similarly GUIs are made 
up of windows, widgets, etc. Again these have a fairtly clear 
translation into objects.

When we get into problems primarily of algorithms, or of 
transforms to fixed data then an OOP style is not always such 
an obvious fit. Similarly when modelling complex state 
machines the applicability of OOP can be less obvious and 
a traditional table driven procedural style may seem better suited.

In those cases the decision to use OOP is likely to be driven 
by the desire to create a reusable component. Something that 
can be utilised across multiple projects. or it may be driven by 
the desire to abstract away a complex process or data structure.
Hiding it behind a simplere API.  This can be done using 
traditional approaches but usually only at the cost od writing 
an awful lot of code or by exposing the data structure at least 
for initialisation purposes.

Now to your examples:

> Let's say you want to load a dictionary. 

Why would anyone ever want to load a dictionary?
What is the higher level goal you are trying to achieve?
Is the dictionary part of the solution or the problem?
If it is part of the problem a dictionary object may be appropriate. 
If its part of the solution, and you are already using a non 
OOP approach why would you want an object? Unless its 
for the reasons above - reuse or abstraction that is hard using 
procedures. But you should very rarely be making decisions
at this level unless you have alrwady decided on amn overall 
approach and you are considering an exception to the overall 
style. ie Should I create a function in an OOP design or should 
I create a class in a procedural design. (Mixing styles is OK 
but will normally involve some compromises)

> Do I create a function that accepts some argument 
> or do I subclass dict and override 
> It seems the end result is the same.

Quite so and the andswer will depend on what you are 
trying to achieve. There is no definitive right answer.

> I created a class called WebPage which is a stand-alone 
> class (I get that). 

Sorry, I don't get it! :-).
Do you mean you only have a class and never create any instances?
Or do you mean you don;t subclass anything in defining it?
Or do you mean you only create a single instance?

> It loads a web page template, and has a function to update 
> the replacement vars with your data (updHtmlVar), and another 
> to spit out the html to a file (wrtHtml). 

The data that this page holds is an html template.
Does it also hold the data displayed by the html? in 
which case its not updating with 'your' data but with 
*its own* data. But it may allow you to pass some data 
to it. Or is it that it renders the html only when given 
some data? Which it doesn't store?

The issue of what data a class is responsible for is key 
to its design. If the WebPage ownds the data then all access 
to that data should be via the webPage. If the WebPage accesses 
the data then it needs an interface to the supplying object. 

> Do you subclass WebPage for each particular page 
> you want 

Almost certainly not. You should have different instances.
But you might have different *kinds* of page (Frame, CSS, 
Table, Dynamic, Static etc) and those could be subclasses.

> (because you can customize it with load functions for 
> each piece of data) or do you just use it as is, and create 
> separate functions outside the class that load the data 
> and you ju

Re: [Tutor] Automatic generation of an "all possible combinations" array

2007-06-15 Thread Andy Cheesman
The code works great, Thanks for the speedy response. The only problem
which I can see is that the code scales very bad with the size of n.

So, as  I want a small subsection of the data (i.e lines where there are
only 4 1s, number in the code below) for a system where n is large(>20).
The idea is that this  would reduce the number of iterations dramatic
despite the individual loop taking longer to operate.(see example data).
I've modified the bit_list_maker to allow for this but it has started to
 produce rows which are identical.
Can anyone make any suggestion/improvements to the code

def bit_list_maker_mod(n, number):
x = n*number
solution_set = []
row_total = number
for i in range(x):
this_answer = []
row = 0
while i>0:
this_answer.append(i%2)
if i%2 == 1:
row +=1
i=i/2
if row == row_total:
break
while len(this_answer) The 2**n different lists that you are seeking have a direct association
> to the binary representation of the integers 0 through (2**n)-1.
> 
> You can use this fact and the "repeated division method" for converting
> numbers between different bases to generate these lists and form the
> desired list of lists:
> 
> def bit_list_maker(n):
> x = 2**n
> solution_set = []
> for i in range(x):
> this_answer = []
> while i>0:
> this_answer.append(i%2)
> i=i/2
> while len(this_answer) this_answer.append(0)
> this_answer.reverse()
> solution_set.append(this_answer)
> return solution_set
> *
> *
> Another fun way to do it is to build up the lists recursively.  The
> possibilities for n bits can be built from the possibilities for n-1
> bits by adding a 1 and a 0 to each possibility (ending up with twice as
> many elements):
> 
> def recursive_bit_list(n):
> if n==1:
> return [[0],[1]]
> else:
> return map(lambda x: x+[0], recursive_bit_list(n-1)) + \
>map(lambda x: x+[1], recursive_bit_list(n-1))
> 
> Hope this helps!
> 
> -Hugh
> 
>  
> On 6/14/07, *Andy Cheesman* <[EMAIL PROTECTED]
> > wrote:
> 
> Hi people
> 
> I am trying to generate an array of all possible combinations of 1, and
> zeros (see example data) for a rather nice Kinetic mote Carlo program
> which I am writing python. So far, I've been working out for
> combinations for 4 or less species by hand as it is quick! but I am
> looking to automate the process so I can compute combinations for large
>   numbers of possible species.
> I could automate the generation of the array by the use of multiple
> loops but that doesn't seem rather pythonic. I was wondering if anyone
> had any sensible suggestions or pointers for efficient mechanisms for
> the array.
> 
> Many Thanks
> Andy
> 
> Example Data
> 3 species
> array([[1, 1, 1],
>[1, 1, 0],
>[1, 0, 1],
>[0, 1, 1],
>[1, 0, 0],
>[0, 1, 0],
>[0, 0, 1],
>[0, 0, 0]])
> 4 species
> array([[1, 1, 1, 1],
>[0, 1, 1, 1],
>[1, 0, 1, 1],
>[1, 1, 0, 1],
>[1, 1, 1, 0],
>[1, 1, 0, 0],
>[1, 0, 1, 0],
>[1, 0, 0, 1],
>[0, 1, 1, 0],
>[0, 1, 0, 1],
>[0, 0, 1, 1],
>[1, 0, 0, 0],
>[0, 1, 0, 0],
>[0, 0, 1, 0],
>[0, 0, 0, 1],
>[0, 0, 0, 0]])
> 
> ___
> Tutor maillist  -   Tutor@python.org 
> http://mail.python.org/mailman/listinfo/tutor
> 
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Automatic generation of an "all possible combinations" array

2007-06-15 Thread Luke Paireepinart
Andy Cheesman wrote:
> The code works great, Thanks for the speedy response. The only problem
> which I can see is that the code scales very bad with the size of n.
>   
You could also do this by iterating in base-16 instead of base-10...
given a string of hex,
like "59FDE", there is a direct correlation between the value of each 
digit and the value in binary representation.
In other words, every digit is 4 binary bits.
So if you have a dictionary or something mapping these values to their 
binary equivalents,
hexmap = {"0":"","1":"0001","2":"0010","3":"0011","4":"0100","5":"0101",
"6":"0110","7":"0111","8":"1000","9":"1001","a":"1010","b":"1011","c":"1100",
"d":"1101","e":"1110","f":""}

then for any number n,
you simply do the following:
binary = ""
for x in hex(n)[2:]:
  binary += (hexmap[x])

this is very simple, but I am unsure how efficient it is.
You'd have to test it out.
But it might be faster for large n, compared to a repeated-division or 
recursive approach (I have no idea.)
I used strings for brevity of the code, but you could do the same with 
lists.
obviously you'd need another loop to generate your values (0 -> n) so 
that this can convert them to hex.
HTH,
-Luke
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Automatic generation of an "all possible combinations" array

2007-06-15 Thread Alan Gauld

"Luke Paireepinart" <[EMAIL PROTECTED]> wrote

> You could also do this by iterating in base-16 instead of base-10...

I was going to suggest the same but using octal which
has the same property but fewer values to map. :-)

> hexmap = 
> {"0":"","1":"0001","2":"0010","3":"0011","4":"0100","5":"0101",
> "6":"0110","7":"0111","8":"1000","9":"1001","a":"1010","b":"1011","c":"1100",
> "d":"1101","e":"1110","f":""}
>
> then for any number n,
> you simply do the following:
> binary = ""
> for x in hex(n)[2:]:
>  binary += (hexmap[x])
>
> this is very simple, but I am unsure how efficient it is.

Its very efficient, many of the C standard library routines (tolower 
etc)
use a similar technique. The amount of memory used is low and the
speed of a dictionary lookup is much less that multiple divisions etc
You can even avoid the dictionary and just use a list for octal since
n is the number of the index position, but I don't think list indexing 
is
any/much faster than a dictionary lookup in Python. (Time for timeit()
here I think...)

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Subclassing vs. stand alone functions

2007-06-15 Thread chrispython

I am new to Python and trying to get my head around 
the OO stuff. I guess my question is - when do you go 
with subclassing vs. making a standalone function? 

OK, I'll take a slightly different approach than the other 
answers so far.

First: procedural and OO styles of programming are diffrent 
ways of thinking about a problem. Any programming problem 
can be solved using either approach and both approaches 
are equally good, neither is intrinsically "better" than the other.

Second: Some problems are more amenable to an OO
aproach than a procedural and vice versa. And the majority 
can be done either way with very little to choose between 
them.

I will now assume that you understand the procedural way 
and already know how to apply good procedural design, 
including modularity featuring loose coupling and tight 
cohesion. In addition data structure design and its relationship 
to your procedural design should be a concept familiar to you.
( In a perfect world you'll also be familiar with the princuiples of 
functional programming and the lambda calculus, but that's 
possibly asking too much.)

>Not sure about the lambda calculus, but I have been doing procedural 
>programming 
>for about 10 years. (I try my best for  modularity and all that good stuff :)
>That leaves the question of why and wjen should we use OOP?

OOP suits programs that feature a high level of correspondence 
between the "real world" and the software modfel we are building.
For example simulation software (including many games) usually 
involves the representation and control of a number of objects. 
It is a natural link to model these objects as classes and create 
corresponding objects in our solution. Similarly GUIs are made 
up of windows, widgets, etc. Again these have a fairtly clear 
translation into objects.

When we get into problems primarily of algorithms, or of 
transforms to fixed data then an OOP style is not always such 
an obvious fit. Similarly when modelling complex state 
machines the applicability of OOP can be less obvious and 
a traditional table driven procedural style may seem better suited.

In those cases the decision to use OOP is likely to be driven 
by the desire to create a reusable component. Something that 
can be utilised across multiple projects. or it may be driven by 
the desire to abstract away a complex process or data structure.
Hiding it behind a simplere API.  This can be done using 
traditional approaches but usually only at the cost od writing 
an awful lot of code or by exposing the data structure at least 
for initialisation purposes.

>Thanks, this is just what I needed! A way to think about which to use.

Now to your examples:

Let's say you want to load a dictionary. 

Why would anyone ever want to load a dictionary?

>I just want to create dictionary with some data in it. The data
>comes from a file, let's say. I would then go on to do something with
>the dictionary - like use it as input to another function. (Sorry, I am 
>thinking
>procedurally, or are dictionaries typically populated for you by 
>the functions you call... maybe it's just a bad example.

What is the higher level goal you are trying to achieve?
Is the dictionary part of the solution or the problem?
If it is part of the problem a dictionary object may be appropriate. 
If its part of the solution, and you are already using a non 
OOP approach why would you want an object? Unless its 
for the reasons above - reuse or abstraction that is hard using 
procedures. But you should very rarely be making decisions
at this level unless you have alrwady decided on amn overall 
approach and you are considering an exception to the overall 
style. ie Should I create a function in an OOP design or should 
I create a class in a procedural design. (Mixing styles is OK 
but will normally involve some compromises)

Do I create a function that accepts some argument 
or do I subclass dict and override 
It seems the end result is the same.

Quite so and the andswer will depend on what you are 
trying to achieve. There is no definitive right answer.

I created a class called WebPage which is a stand-alone 
class (I get that). 

Sorry, I don't get it! :-).
Do you mean you only have a class and never create any instances?
>No.
Or do you mean you don;t subclass anything in defining it?
>Yes.
Or do you mean you only create a single instance?
>You could have multiple instances. 

It loads a web page template, and has a function to update 
the replacement vars with your data (updHtmlVar), and another 
to spit out the html to a file (wrtHtml). 

The data that this page holds is an html template.
Does it also hold the data displayed by the html? 
in 
which case its not updating with 'your' data but with 
*its own* data. But it may allow you to pass some data 
to it. Or is it that it renders the html only when given 
some data? Which it doesn't store?
>It stores the data and the template. When it is instantiated, 
>you just have the template and the

Re: [Tutor] Automatic generation of an "all possible combinations" array

2007-06-15 Thread Hugh M

Ah, in the case of looking for all n-digit bit-strings that contain exactly
m-1's, the recursive solution is even nicer.  Here's how I think of it:
Base Case(s):
- if you want 0 1's (m==0) then return all 0's.
- if you want all 1's (n==m) then return all 1's.

Otherwise Recursive Case:
- return the set of all (n-1)digit bit-strings that contain exactly m-1's
plus a 0
combined with the set of all (n-1)digit bit-strings that contain exactly
m-1's plus a 1

Here's some code that does just that:

def recursive_bit_list(n,m):
   if m==0:
   return [n*[0]]
   elif n==m:
   return [n*[1]]
   else:
   return map(lambda x: x+[0], recursive_bit_list(n-1,m)) + \
  map(lambda x: x+[1], recursive_bit_list(n-1,m-1))


If you want it faster and don't mind building up a large in-memory
dictionary as you compute this, you can try incorporating a "memoizer" so
that you don't repeatedly compute the same answer many times.

e.g.:

memoizer = {}

def recursive_bit_list(n,m):
   global memoizer
   if memoizer.has_key((n,m)):
   return memoizer[(n,m)]
   elif m==0:
   return [n*[0]]
   elif n==m:
   return [n*[1]]
   else:
   answer = map(lambda x: x+[0], recursive_bit_list(n-1,m)) + \
  map(lambda x: x+[1], recursive_bit_list(n-1,m-1))
   memoizer[(n,m)] = answer
   return answer


I didn't do any extensive tests- when n is large both of these are far from
speedy...  Maybe there are other ideas?

Good luck!

-Hugh



On 6/15/07, Andy Cheesman <[EMAIL PROTECTED]> wrote:


The code works great, Thanks for the speedy response. The only problem
which I can see is that the code scales very bad with the size of n.

So, as  I want a small subsection of the data (i.e lines where there are
only 4 1s, number in the code below) for a system where n is large(>20).
The idea is that this  would reduce the number of iterations dramatic
despite the individual loop taking longer to operate.(see example data).
I've modified the bit_list_maker to allow for this but it has started to
produce rows which are identical.
Can anyone make any suggestion/improvements to the code

def bit_list_maker_mod(n, number):
x = n*number
solution_set = []
row_total = number
for i in range(x):
this_answer = []
row = 0
while i>0:
this_answer.append(i%2)
if i%2 == 1:
row +=1
i=i/2
if row == row_total:
break
while len(this_answer) The 2**n different lists that you are seeking have a direct association
> to the binary representation of the integers 0 through (2**n)-1.
>
> You can use this fact and the "repeated division method" for converting
> numbers between different bases to generate these lists and form the
> desired list of lists:
>
> def bit_list_maker(n):
> x = 2**n
> solution_set = []
> for i in range(x):
> this_answer = []
> while i>0:
> this_answer.append(i%2)
> i=i/2
> while len(this_answer) this_answer.append(0)
> this_answer.reverse()
> solution_set.append(this_answer)
> return solution_set
> *
> *
> Another fun way to do it is to build up the lists recursively.  The
> possibilities for n bits can be built from the possibilities for n-1
> bits by adding a 1 and a 0 to each possibility (ending up with twice as
> many elements):
>
> def recursive_bit_list(n):
> if n==1:
> return [[0],[1]]
> else:
> return map(lambda x: x+[0], recursive_bit_list(n-1)) + \
>map(lambda x: x+[1], recursive_bit_list(n-1))
>
> Hope this helps!
>
> -Hugh
>
>
> On 6/14/07, *Andy Cheesman* <[EMAIL PROTECTED]
> > wrote:
>
> Hi people
>
> I am trying to generate an array of all possible combinations of 1,
and
> zeros (see example data) for a rather nice Kinetic mote Carlo
program
> which I am writing python. So far, I've been working out for
> combinations for 4 or less species by hand as it is quick! but I am
> looking to automate the process so I can compute combinations for
large
>   numbers of possible species.
> I could automate the generation of the array by the use of multiple
> loops but that doesn't seem rather pythonic. I was wondering if
anyone
> had any sensible suggestions or pointers for efficient mechanisms
for
> the array.
>
> Many Thanks
> Andy
>
> Example Data
> 3 species
> array([[1, 1, 1],
>[1, 1, 0],
>[1, 0, 1],
>[0, 1, 1],
>[1, 0, 0],
>[0, 1, 0],
>[0, 0, 1],
>[0, 0, 0]])
> 4 species
> array([[1, 1, 1, 1],
>[0, 1, 1, 1],
>[1, 0, 1, 1],
>[1, 1, 0, 1],
>[1, 1, 1, 0],
>[1, 1, 0, 0],
>[1, 0, 1, 0],
>[1, 0, 0, 1],
>[0, 1, 1, 0],
>[0, 1, 0, 1],
>[0, 0, 1, 1],
>[1, 0, 0, 0],

[Tutor] How to localize PyKaraoke ?

2007-06-15 Thread Eiwot

Hi all,
   Can I use PyKaraoke in another language such as German ? How to make a song 
lyrics that match with the song , any word break or phrase break algorithm 
required ?
 
Thanks
Eiwot
http://pyarticles.blogspot.com/
http://pythonforge.blogspot.com
_
Play free games, earn tickets, get cool prizes! Join Live Search Club. 
http://club.live.com/home.aspx?icid=CLUB_wlmailtextlink___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tutor Digest, Vol 40, Issue 38

2007-06-15 Thread János Juhász
Hi Andy,

> The code works great, Thanks for the speedy response. The only problem
> which I can see is that the code scales very bad with the size of n.

> So, as  I want a small subsection of the data (i.e lines where there are
> only 4 1s, number in the code below) for a system where n is large(>20).
> The idea is that this  would reduce the number of iterations dramatic
> despite the individual loop taking longer to operate.(see example data).
> I've modified the bit_list_maker to allow for this but it has started to
> produce rows which are identical.
> Can anyone make any suggestion/improvements to the code

I feel that you would use this table for something else than simple print 
it.
It is probably a decision table.
As each cell of this table can be calculated anytime, I think to not store 
it in
any big table with a lot of integers in each cell, but simple calculate it 
at need.
You can save a lot of memory in that way.
If it is a decision table, I don't mind to starting the permutation on the 
first col
instead of the last. It doesn't change the permutation itself, just its 
order.

def Perm_matrix(row, col):
if (row & (2**col)): return 1
return 0

n = 4

for row in range(2**n):
for col in range(n):
print Perm_matrix(row, col),
print ';'


It is easy to turn it into a class.

class Perm:
def __init__(self, num):
self.rownum = 2**num
self.colnum = num

def Perm_matrix(self, row, col):
if (row & (2**col)): return 1
return 0

def __getitem__(self,(row,col)):
return self.Perm_matrix(row,col)

m = Perm(4)

for row in range(m.rownum):
for col in range(m.colnum):
print m[row, col],
print ''


Regards,
Janos
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor