Re: Question about generators

2009-07-12 Thread Cameron Pulsford
I was initially looking at it there are some interesting patterns I might be able to extend into a generator that would yield only correct sets of numbers for the 6x + n pattern. On Jul 12, 2009, at 10:26 PM, John Machin wrote: On Jul 13, 11:24 am, Cameron Pulsford wrote: As far as the p

Re: Question about generators

2009-07-12 Thread Cameron Pulsford
ng up! On Jul 12, 2009, at 8:15 PM, Terry Reedy wrote: Cameron Pulsford wrote: When you start a new thread, you should start a new thread and not piggyback on an existing thread. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list

Question about generators

2009-07-12 Thread Cameron Pulsford
Hey everyone, I have this small piece of code that simply finds the factors of a number. import sys def factor(n): primes = (6*i+j for i in xrange(1, n) for j in [1, 5] if (i+j)%5 ! = 0) factors = [] for i in [2, 3, 5]: while n % i == 0: n /= i f

Problem with list of dicts and copying

2009-07-08 Thread Cameron Pulsford
Hello all, I'm redoing a sudoku solver of mine and I ran into an issue with lists of dicts. Bear with me for a second before I get to the actual problem... I'm representing the board as a dictionary, where the keys are (x, y) positions, and the values are candidates. So my program goes along pickin

Re: Help with dictionaries and multidimensial lists

2009-06-23 Thread Cameron Pulsford
Thanks! On Tue, Jun 23, 2009 at 11:29 AM, Jaime Fernandez del Rio < jaime.f...@gmail.com> wrote: > On Tue, Jun 23, 2009 at 4:45 PM, Cameron > Pulsford wrote: > > Hey all, I have a dictionary that looks like this (small example version) > > {(1, 2): 0} named a > >

Help with dictionaries and multidimensial lists

2009-06-23 Thread Cameron Pulsford
Hey all, I have a dictionary that looks like this (small example version) {(1, 2): 0} named a so I can do a[1,2] which returns 0. What I also have is a list of coordinates into a 2 dimensional array that might look like this b = [[1,2]]. Is there anyway I can call a[b[0]] and have it return 0? --

Reading and setting file permissions programmatically

2009-06-17 Thread Cameron Pulsford
Sorry to flood the list but my google fu isn't up to par today I guess. Basically, is it possible to read the permissions on one file and then set the permissions of another file to the ones we just read? os.dup2 seemed like it would work but I might not be using it correctly. I know there is os.c

Re: Pythonic way to overwrite a file

2009-06-17 Thread Cameron Pulsford
c...@sequans.com> wrote: > Cameron Pulsford wrote: > >> Hey all, hopefully a simple question. >> >> I'm writing a simple python tool that opens a file, and does something >> like >> >> for line in file.readlines(): >>temp.write(line.doStuf

Pythonic way to overwrite a file

2009-06-17 Thread Cameron Pulsford
Hey all, hopefully a simple question. I'm writing a simple python tool that opens a file, and does something like for line in file.readlines(): temp.write(line.doStuff()) However, I want to provide the option do this "in place", as in have the destination file be the same as the source file.

Re: Have a variable column length in printf

2009-05-31 Thread Cameron Pulsford
Thanks all, I think I'l stick with the '*' method because this is just a one time thing for a __repr__ function and it seems easiest. On Sun, May 31, 2009 at 6:32 AM, Terry Reedy wrote: > Gary Herron wrote: > >> Cameron Pulsford wrote: >> >>> Hello al

Have a variable column length in printf

2009-05-30 Thread Cameron Pulsford
Hello all, I'm trying to pretty print a list, so I am doing something like print '%3d' % integer only I would like that 3 to be a variable, instead of hardcoded. Is this possible, or are there any other ways to accomplish this? Thanks! -- http://mail.python.org/mailman/listinfo/python-list

NameError function not found

2009-05-29 Thread Cameron Pulsford
Hey everyone, I am extremely stumped on this. I have 2 functions.. def _determinant(m): return m[0][0] * m[1][1] - m[1][0] * m[0][1] def cofactor(self): """Returns the cofactor of a matrix.""" newmatrix = [] for i, minor in enumerate(self.minors()): newmatrix.append(_determinan

Re: Problem with objects copying each other in memory

2009-02-12 Thread Cameron Pulsford
Thanks, that did it! Why is that the case though? Or rather, why do the assignments to temp.x and temp.y not effect the self.x and self.y? How come I only run into the problem with the list? On Feb 12, 2009, at 5:15 PM, andrew cooke wrote: you're setting the new knight's "sl" to the value