Dependency Injection

2015-04-10 Thread Palpandi
Hi all, Can anyone explain about the dependency injection concept in python? I have a class A. A is used in all other classes(B, C, D, ..). Is it good to use dependency injection concept in this situation or else any other suggestions? Thanks in advance. -- https://mail.python.org/mailman/li

Re: find all multiplicands and multipliers for a number

2015-04-10 Thread Paul Rubin
Steven D'Aprano writes: > It may be a bit slow for very large numbers. On my computer, this takes 20 > seconds: > py> pyprimes.factors.factorise(2**111+1) > [3, 3, 1777, 3331, 17539, 25781083, 107775231312019L] This takes about 4 seconds on a Intel(R) Core(TM) i5-3230M CPU @ 2.60GHz laptop (64 bi

Re: Exception Handling

2015-04-10 Thread dieter
Palpandi writes: > Thanks for your responses. And I have one more question. > This is the situation. A python application which reads data from one .xml > file and generates some other file. Here what kind of exceptions occur? Ideally, you would not get any exceptions. In the not ideal case, y

Re: find all multiplicands and multipliers for a number

2015-04-10 Thread Stephen Tucker
Dario Alpern has written a program that uses the Elliptic Curve Method (ECM) for factorising a number. ECM is one of the _very_ fast methods for finding the prime factors of a number. He has even offered the code for his program. You could have a go at using or converting his code to do what you ar

Re: try..except with empty exceptions

2015-04-10 Thread Rustom Mody
On Saturday, April 11, 2015 at 9:47:36 AM UTC+5:30, Rustom Mody wrote: > On Saturday, April 11, 2015 at 9:17:16 AM UTC+5:30, Dave Angel wrote: > > On 04/10/2015 10:38 PM, Rustom Mody wrote: > > > On Saturday, April 11, 2015 at 7:53:31 AM UTC+5:30, Dave Angel wrote: > > >> On 04/10/2015 09:42 PM, St

Re: try..except with empty exceptions

2015-04-10 Thread Rustom Mody
On Saturday, April 11, 2015 at 9:17:16 AM UTC+5:30, Dave Angel wrote: > On 04/10/2015 10:38 PM, Rustom Mody wrote: > > On Saturday, April 11, 2015 at 7:53:31 AM UTC+5:30, Dave Angel wrote: > >> On 04/10/2015 09:42 PM, Steven D'Aprano wrote: > >>> On Sat, 11 Apr 2015 05:31 am, sohcahtoa82 wrote: > >

Re: try..except with empty exceptions

2015-04-10 Thread Dave Angel
On 04/10/2015 10:38 PM, Rustom Mody wrote: On Saturday, April 11, 2015 at 7:53:31 AM UTC+5:30, Dave Angel wrote: On 04/10/2015 09:42 PM, Steven D'Aprano wrote: On Sat, 11 Apr 2015 05:31 am, sohcahtoa82 wrote: It isn't document because it is expected. Why would the exception get caught if you

Re: try..except with empty exceptions

2015-04-10 Thread Rustom Mody
On Saturday, April 11, 2015 at 7:53:31 AM UTC+5:30, Dave Angel wrote: > On 04/10/2015 09:42 PM, Steven D'Aprano wrote: > > On Sat, 11 Apr 2015 05:31 am, sohcahtoa82 wrote: > > > >> It isn't document because it is expected. Why would the exception get > >> caught if you're not writing code to catch

Re: try..except with empty exceptions

2015-04-10 Thread Dave Angel
On 04/10/2015 09:42 PM, Steven D'Aprano wrote: On Sat, 11 Apr 2015 05:31 am, sohcahto...@gmail.com wrote: It isn't document because it is expected. Why would the exception get caught if you're not writing code to catch it? If you write a function and pass it a tuple of exceptions to catch, I'

Re: wikipedia data sets

2015-04-10 Thread Paul Rubin
alexgla...@gmail.com writes: > anyone know anything about downloading wikipedia data sets? They are at dumps.wikimedia.org > are there any data field descriptions? I think there is some old and light documentation on that site, but mostly you can just look at the files and see where stuff is. >

Re: find all multiplicands and multipliers for a number

2015-04-10 Thread Steven D'Aprano
On Sat, 11 Apr 2015 11:06 am, Dave Angel wrote: > But the real place to get improvement is to only divide by primes, > rather than every possible integer.  And once you've done the division, > let q be the next value for dividend.  So you'll get a list like > > [3, 3, 3, 37] > > for the value 99

Re: try..except with empty exceptions

2015-04-10 Thread Rustom Mody
On Friday, April 10, 2015 at 2:18:22 PM UTC+5:30, Pavel S wrote: > Hi, > > I noticed interesting behaviour. Since I don't have python3 installation > here, I tested that on Python 2.7. > > Well known feature is that try..except block can catch multiple exceptions > listed in a tuple: > > > ex

wikipedia data sets

2015-04-10 Thread alexglaros
anyone know anything about downloading wikipedia data sets? are there any data field descriptions? am searching for table of all government organizations. While there may not be specific wikipedia fields indicating whether an organization is a government entity or not, there may be a URL fiel

Re: try..except with empty exceptions

2015-04-10 Thread Steven D'Aprano
On Sat, 11 Apr 2015 05:31 am, sohcahto...@gmail.com wrote: > It isn't document because it is expected. Why would the exception get > caught if you're not writing code to catch it? If you write a function > and pass it a tuple of exceptions to catch, I'm not sure why you would > expect it to catc

Re: find all multiplicands and multipliers for a number

2015-04-10 Thread Paul Rubin
ravas writes: > for divisor in range(1, end): > q, r = dm(dividend, divisor) > if r is 0: > rlist.append((divisor, q)) Use r == 0 instead of r is 0 there. "r is 0" is object identity that might happen to work but that's an implementation detail in the interpreter.

Re: find all multiplicands and multipliers for a number

2015-04-10 Thread Dave Angel
On 04/10/2015 09:06 PM, Dave Angel wrote: On 04/10/2015 07:37 PM, ravas wrote: def m_and_m(dividend): rlist = [] dm = divmod end = (dividend // 2) + 1 for divisor in range(1, end): q, r = dm(dividend, divisor) if r is 0: rlist.append((divisor, q

Re: find all multiplicands and multipliers for a number

2015-04-10 Thread Dave Angel
On 04/10/2015 07:37 PM, ravas wrote: def m_and_m(dividend): rlist = [] dm = divmod end = (dividend // 2) + 1 for divisor in range(1, end): q, r = dm(dividend, divisor) if r is 0: rlist.append((divisor, q)) return rlist print(m_and_m(999)) -

find all multiplicands and multipliers for a number

2015-04-10 Thread ravas
def m_and_m(dividend): rlist = [] dm = divmod end = (dividend // 2) + 1 for divisor in range(1, end): q, r = dm(dividend, divisor) if r is 0: rlist.append((divisor, q)) return rlist print(m_and_m(999)) --- output: [(1, 999), (3, 333), (9, 111), (27,

Re: Sudoku solver

2015-04-10 Thread Albert van der Horst
In article <87iodoakft@elektro.pacujo.net>, Marko Rauhamaa wrote: >Ian Kelly : > >> The test puzzle that you posted has 23 values already filled in. How >> does it perform on harder puzzles with only 17 clues (the proven >> minimum)? One would expect it to be around a million times slower. >

Re: try..except with empty exceptions

2015-04-10 Thread Dave Angel
On 04/10/2015 04:48 AM, Pavel S wrote: Hi, I noticed interesting behaviour. Since I don't have python3 installation here, I tested that on Python 2.7. Well known feature is that try..except block can catch multiple exceptions listed in a tuple: exceptions = ( TypeError, ValueError ) try: