Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-23 Thread Slaunger
As a general note concerning the use of Python on Project Euler, and the one minute guideline. For problems 1-100, each problem is easily solved in less than 1 minute processing time *if* the algorithms and math is done "right" and with thought. My project Euler scripts solves the first 100 probl

Re: mmap 2GB allocation limit on Win XP, 32-bits, Python 2.5.4

2009-07-27 Thread Slaunger
On 27 Jul., 13:21, Dave Angel wrote: > (forwarding this message, as the reply was off-list) > > > > Kim Hansen wrote: > > 2009/7/24 Dave Angel : > > >> It's not a question of how much disk space there is, but how much virtual > >> space 32 bits can address.  2**32 is about 4 gig, and Windows XP re

mmap 2GB allocation limit on Win XP, 32-bits, Python 2.5.4

2009-07-24 Thread Slaunger
OS: Win XP SP3, 32 bit Python 2.5.4 Hi I have run into some problems with allocating numpy.memmaps exceeding and accumulated size of about 2 GB. I have found out that the real problem relates to numpy.memmap using mmap.mmap I've written a small test program to illustrate it: import itertools imp

Re: Skipping bytes while reading a binary file?

2009-02-06 Thread Slaunger
You might also want to have a look at a numpy memmap viewed as a recarray. from numpy import dtype, memmap, recarray # Define your record in the file, 4bytes for the real value, # and 4 bytes for the imaginary (assuming Little Endian repr) descriptor = dtype([("r", "http://mail.python.org/mailman

Re: Best way to report progress at fixed intervals

2008-12-10 Thread Slaunger
print "Processed %d of %d." % (self.i + 1, self.max) time.sleep(self.progress_interval) p = ProgressReporter() if verbose: print "Work through all %d steps reporting every %3.1f secs..." % \ (max_iter, progress_interval) p.start() for i in xrange(max_iter): work(i) p.i = i if verbose: print "Finished working through %d steps" % max_iter if __name__ == "__main__": workAll() = end src I like this much better than my own first attempt in my initial post on this thread. -- Slaunger -- http://mail.python.org/mailman/listinfo/python-list

Re: Best way to report progress at fixed intervals

2008-12-09 Thread Slaunger
On 10 Dec., 08:03, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > Slaunger <[EMAIL PROTECTED]> writes: > > On 10 Dec., 03:44, George Sakkis <[EMAIL PROTECTED]> wrote: > >> On Dec 9, 11:40 am, Slaunger <[EMAIL PROTECTED]> wrote: > > >> > I wo

Re: Best way to report progress at fixed intervals

2008-12-09 Thread Slaunger
On 10 Dec., 03:44, George Sakkis <[EMAIL PROTECTED]> wrote: > On Dec 9, 11:40 am, Slaunger <[EMAIL PROTECTED]> wrote: > > > I would therefore like some feedback on this proposed generic "report > > progress at regular intervals" approach presented here. Wh

Re: Best way to report progress at fixed intervals

2008-12-09 Thread Slaunger
ther than the main thread.  (I ran into this in a Windows GUI ap I > wrote using wxPython). > Ah, yes, you right. For GUIs this is often quite important. I don't do much GUI, so This is not something I had strongly in mind. Br, -- Slaunger -- http://mail.python.org/mailman/listinfo/python-list

Re: Best way to report progress at fixed intervals

2008-12-09 Thread Slaunger
t;__main__": >      #Create the monitor. >      monitor = Monitor() >      #Run the work function under monitoring. >      monitor(work) I was unfamiliar with this notation, but now I understand it simply invokes __call__. Thank you for showing me that! OK. I agree this is a more elegant implementation, although I my mind, I find it more natural if the reporting goes on in a subthread, but that is a matter of taste, I guess. Anyway: Thank you again for spending your lunch break on this! -- Slaunger -- http://mail.python.org/mailman/listinfo/python-list

Re: When (and why) to use del?

2008-12-09 Thread Slaunger
you. In my mind there is no reason for such kinds of deletes. The code seems to have been made by a person who úsually programs in a language which does not have a garbage collector. I do not know if it has any noticeable impact on the performance. -- Slaunger -- http://mail.python.org/mailman/listinfo/python-list

Best way to report progress at fixed intervals

2008-12-09 Thread Slaunger
rkAll() Quite frankly, I do not like what I have made! It is a mess, responsibilities are mixed, and it seems overly complicated. But I can't figure out how to do this right. I would therefore like some feedback on this proposed generic "report progress at regular intervals" approach presented here. What could I do better? -- Slaunger -- http://mail.python.org/mailman/listinfo/python-list

Re: Pythonic design patterns

2008-12-04 Thread Slaunger
Thank you all for sharing your views, links and suggestions on my question. I see where this is getting, and I have extracted the following points: 1. Many classic design patterns, especially the creational ones (Factory, etc.) aren't really that useful in Python as the built-in features in the la

Pythonic design patterns

2008-12-04 Thread Slaunger
possibilities in Python? In that manner I may be able to both learn programming more pythonic AND learn the design patterns. -- Slaunger -- http://mail.python.org/mailman/listinfo/python-list

Re: How to instantiate in a lazy way?

2008-12-03 Thread Slaunger
On 3 Dec., 15:30, Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > Slaunger <[EMAIL PROTECTED]> wrote: > >  On 3 Dec., 11:30, Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > > > > ? ? ? ? ?cls = self.__class__ > > > > ? ? ? ? ?if attr_name in cls.data

Re: How to instantiate in a lazy way?

2008-12-03 Thread Slaunger
not figure out how to kake a general purpose decorator. For this to actually work the "instant" PayloadBaconAndEggs class simply has to define and implement a few class attributes and static utility functions for the unpacking. -- Slaunger -- http://mail.python.org/mailman/listinfo/python-list

Re: How to instantiate in a lazy way?

2008-12-02 Thread Slaunger
by selecting a tuple instead of a frozenset. The bytes_to_data function is the performance bottleneck in the actual application (implemented in parent class). -- Slaunger -- http://mail.python.org/mailman/listinfo/python-list

Re: How to instantiate in a lazy way?

2008-12-02 Thread Slaunger
it test cases I have come up with so far. No guarantees though, as I may simply not have been smart enough to bring forth unit test cases which make it crash. Comments on the code is still appreciated though. I am still a novice Python programmer, and I may have overlooked more Pythonic ways to do it. -- Slaunger -- http://mail.python.org/mailman/listinfo/python-list

Re: How to instantiate in a lazy way?

2008-12-02 Thread Slaunger
possibility, just gotta understand > >  how to decorate a setter and delete method as well, but I should be > >  able to look that up by myself... > > I'm sure you will! > > http://www.python.org/doc/2.5.2/lib/built-in-funcs.html > Yeah, I just visited that page yesterday! Again, thank you for your assistance, Nick! -- Slaunger -- http://mail.python.org/mailman/listinfo/python-list

Re: How to instantiate in a lazy way?

2008-12-01 Thread Slaunger
d of trouble are you referring to in __getattr__? Is it recursive calls to the method on accessing object attributes in that method itself or other complications? On a related issue, thank you for showing me how to use @property as a decorator - I was not aware of that possibility, just gotta un

Re: Emacs vs. Eclipse vs. Vim

2008-12-01 Thread Slaunger
ese classic editors. I also think it depends much upon your coding style. Personally I spend much more time thinking on "how" to implement this-and-that, than actually coding. That may reflect that I am still a novice Python Programmer. -- Slaunger -- http://mail.python.org/mailman/listinfo/python-list

Re: How to instantiate in a lazy way?

2008-12-01 Thread Slaunger
Slaunger wrote: > > class PayloadOnDemand(object): >     """ >     Behaves as a PayloadInstant object, but instantiation is faster >     as only the position of the payload in the file is stored > initially in the object. >     Only when acessing the i

How to instantiate in a lazy way?

2008-12-01 Thread Slaunger
ass, such that the inner lazy creation of the attribute is completely hidden from the outside. I guess I could also just make a single class, and let an OnDemand attribute decide how it should behave. My real application is considerably more complicated than this, but I think the example grasps the problem in a nutshell. -- Slaunger -- http://mail.python.org/mailman/listinfo/python-list

Re: Best strategy for finding a pattern in a sequence of integers

2008-11-21 Thread Slaunger
On 21 Nov., 18:10, Gerard flanagan <[EMAIL PROTECTED]> wrote: > Slaunger wrote: > > Hi all, > > > I am a Python novice, and I have run into a problem in a project I am > > working on, which boils down to identifying the patterns in a sequence > > of integers, fo

Re: Best strategy for finding a pattern in a sequence of integers

2008-11-21 Thread Slaunger
ignored number between the patterns? Is > 9,3,3,0,7,10,6,6,1 > legal? If NO, you violate Rule 5. If YES, you violate the second Rule > 7. Yes you are right. This complication is again eliminated by prefiltering "other" numbers out -- Slaunger -- http://mail.python.org/mailman/listinfo/python-list

Re: Best strategy for finding a pattern in a sequence of integers

2008-11-21 Thread Slaunger
> > > I am pretty sure I can figure out how to do that, but I would like to > > have some guidance on the most pythonic approach to this. > > Then it would be a good starting point to write some code. Then you > could post it and ask how it can be made more 'pythonic'. > That is actually a good poi

Best strategy for finding a pattern in a sequence of integers

2008-11-21 Thread Slaunger
in the sequence, e.g., ...ABABABAB..., ...AAA..., or ...BBB... Thank you, -- Slaunger -- http://mail.python.org/mailman/listinfo/python-list

Re: Best practise hierarchy for user-defined exceptions

2008-11-17 Thread Slaunger
On 17 Nov., 13:05, "Chris Rebert" <[EMAIL PROTECTED]> wrote: > On Mon, Nov 17, 2008 at 3:47 AM, Slaunger <[EMAIL PROTECTED]> wrote: > > > . > > Here is my stub-implemented idea on how to do it so far, which is > > inspired by how I would have

Best practise hierarchy for user-defined exceptions

2008-11-17 Thread Slaunger
to do? 4. Which __xx__ methods would you normally implement for the user- defined exception classes? I was thinking of __str__, for example? Is there a recommended __str__ idiom to use for that? -- Slaunger -- http://mail.python.org/mailman/listinfo/python-list

Re: How to "reduce" a numpy array using a costum binary function

2008-11-13 Thread Slaunger
On 13 Nov., 22:48, Robert Kern <[EMAIL PROTECTED]> wrote: > Slaunger wrote: > > It is always good to ask yourself a question. > > I had forgooten about the reduce function > > > I guess this implementation > > > from numpy import * > > > def compl_ad

Re: How to "reduce" a numpy array using a costum binary function

2008-11-13 Thread Slaunger
It is always good to ask yourself a question. I had forgooten about the reduce function I guess this implementation from numpy import * def compl_add_uint16(a, b): c = a + b c += c >> 16 return c & 0x def compl_one_checksum(uint16s): return reduce(compl_add_uint16, uint16s,

How to "reduce" a numpy array using a costum binary function

2008-11-13 Thread Slaunger
I know there must be a simple method to do this. I have implemented this function for calculating a checksum based on a ones complement addition: def complement_ones_checksum(ints): """ Returns a complements one checksum based on a specified numpy.array of dtype=uint16 """ res

Re: Best practise implementation for equal by value objects

2008-08-08 Thread Slaunger
On 7 Aug., 21:19, Terry Reedy <[EMAIL PROTECTED]> wrote: > Slaunger wrote: > > On 6 Aug., 21:36, Terry Reedy <[EMAIL PROTECTED]> wrote: > > OK, the situation is more complicated than that then. In the case here > > though, > > the attributes would always be

Re: Best practise implementation for equal by value objects

2008-08-08 Thread Slaunger
On 7 Aug., 21:25, Paul Rubin wrote: > Terry Reedy <[EMAIL PROTECTED]> writes: > > So when the initializers for instances are all 'nice' (as for range), > > go for it (as in 'Age(10)').  And test it as you are by eval'ing the > > rep. Just accept that the eval will only wo

Re: Best practise implementation for equal by value objects

2008-08-06 Thread Slaunger
On 7 Aug., 04:34, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > On Wed, 06 Aug 2008 05:50:35 -0700, Slaunger wrote: > > Hi, > > > I am new here and relatively new to Python, so be gentle: > > > Is there a recommended generic implementatio

Re: Best practise implementation for equal by value objects

2008-08-06 Thread Slaunger
On 6 Aug., 21:46, John Krukoff <[EMAIL PROTECTED]> wrote: > On Wed, 2008-08-06 at 05:50 -0700, Slaunger wrote: > > Hi, > > > I am new here and relatively new to Python, so be gentle: > > > Is there a recommended generic implementation of __repr__ for objects >

Re: Best practise implementation for equal by value objects

2008-08-06 Thread Slaunger
On 6 Aug., 21:36, Terry Reedy <[EMAIL PROTECTED]> wrote: > Slaunger wrote: > > Hi, > > > I am new here and relatively new to Python, so be gentle: > > > Is there a recommended generic implementation of __repr__ for objects > > equal by value to assure that

Best practise implementation for equal by value objects

2008-08-06 Thread Slaunger
implementation of __repr__ which I can use instead? This is something I plan to reuse for many different Value classes, so I would like to get it robust. Thanks, Slaunger -- http://mail.python.org/mailman/listinfo/python-list