Re: [Tutor] Replacement for __del__

2009-05-19 Thread A.T.Hofkamp
Strax-Haber, Matthew (LARC-D320) wrote: A folder is created during object instantiation. This is necessary because multiple other methods depend on the existence of that folder, and in the future things may be running in parallel so it has to be there for the entire life of the object. Before the

Re: [Tutor] performance loss -- profiling

2009-05-19 Thread spir
Le Mon, 18 May 2009 23:16:13 +0100, "Alan Gauld" s'exprima ainsi: > "spir" wrote > > > Also, it's the first time I really have to cope with machine-time; > > so I'm totally new to technics like using a profiler. > > Any hints on the topics heartfully welcome :-) > > Profilers are a bit like

[Tutor] clean text

2009-05-19 Thread spir
Hello, This is a follow the post on performance issues. Using a profiler, I realized that inside error message creation, most of the time was spent in a tool func used to clean up source text output. The issue is that when the source text holds control chars such as \n, then the error message is

Re: [Tutor] Replacement for __del__

2009-05-19 Thread spir
Le Tue, 19 May 2009 09:12:34 +0200, "A.T.Hofkamp" s'exprima ainsi: > A folder is created during object instantiation. Do you mean a filesytem directory? I may be wrong, bit it seems there is a bit of confusion between things and their representation as python objects. You shouldn't call __del_

Re: [Tutor] performance loss -- profiling

2009-05-19 Thread Kent Johnson
On Mon, May 18, 2009 at 2:49 PM, spir wrote: > Hello, > > I have an big performance problem with an app I'm currently working on. > It "suddenly" runs at least 5 times slower that it used to. The issue is, > beeing in a finalization phase, I'm all the time touching thingies here and > there. But

Re: [Tutor] clean text

2009-05-19 Thread spir
Le Tue, 19 May 2009 11:36:17 +0200, spir s'exprima ainsi: > Hello, > > This is a follow the post on performance issues. > Using a profiler, I realized that inside error message creation, most of > the time was spent in a tool func used to clean up source text output. The > issue is that when the

Re: [Tutor] clean text

2009-05-19 Thread Kent Johnson
On Tue, May 19, 2009 at 5:36 AM, spir wrote: > Hello, > > This is a follow the post on performance issues. > Using a profiler, I realized that inside error message creation, most of the > time was spent in a tool func used to clean up source text output. > The issue is that when the source text h

Re: [Tutor] clean text

2009-05-19 Thread A.T.Hofkamp
spir wrote: def _cleanRepr(text): ''' text with control chars replaced by repr() equivalent ''' chars = [] for char in text: n = ord(char) if (n < 32) or (n > 126 and n < 160): char = repr(char)[1:-1]

Re: [Tutor] performance loss -- profiling

2009-05-19 Thread Tim Golden
Kent Johnson wrote: The Python profiler is not hard to run. Interpreting the results is more difficult :-) See the docs to get started: http://docs.python.org/library/profile.html Also, it's quite useful to run it as a module: python -mcProfile You have a certain amount of configurability v

Re: [Tutor] clean text

2009-05-19 Thread Sander Sweers
2009/5/19 spir : > def _cleanRepr(text): >        ''' text with control chars replaced by repr() equivalent ''' >        result = "" >        for char in text: >                n = ord(char) >                if (n < 32) or (n > 126 and n < 160): >                        char = repr(char)[1:-1] >  

Re: [Tutor] clean text

2009-05-19 Thread Kent Johnson
By the way, the timeit module is very helpful for comparing the speed of different implementations of an algorithm such as are being presented in this thread. You can find examples in the list archives: http://search.gmane.org/?query=timeit&group=gmane.comp.python.tutor Kent __

[Tutor] odbc connection with python

2009-05-19 Thread mustafa akkoc
how can i make odbc connection language and i wanna make gui project after connecting database anyone has document ? -- Mustafa Akkoc ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] clean text

2009-05-19 Thread python
Denis, Untested idea: 1. Fill a dict with pre-calculated repr() values for chars you want to replace (replaceDict) 2. Create a set() of chars that you want to replace (replaceSet). 3. Replace if (n < 32) ... test with if char in replaceSet 4. Lookup the replacement via replaceDict[ char ] vs.

Re: [Tutor] odbc connection with python

2009-05-19 Thread Emile van Sebille
On 5/19/2009 5:47 AM mustafa akkoc said... how can i make odbc connection language and i wanna make gui project after connecting database anyone has document ? There's an odbc module in python. I'd start with the docs on that and then google 'python odbc example' for more info and examples.

Re: [Tutor] Replacement for __del__

2009-05-19 Thread David Stanek
On Tue, May 19, 2009 at 5:55 AM, spir wrote: > Le Tue, 19 May 2009 09:12:34 +0200, > "A.T.Hofkamp" s'exprima ainsi: > >> A folder is created during object instantiation. > > Do you mean a filesytem directory? I may be wrong, bit it seems there is a > bit of confusion between things and their rep

Re: [Tutor] clean text

2009-05-19 Thread Lie Ryan
spir wrote: Hello, This is a follow the post on performance issues. Using a profiler, I realized that inside error message creation, most of the time was spent in a tool func used to clean up source text output. The issue is that when the source text holds control chars such as \n, then the er

Re: [Tutor] clean text

2009-05-19 Thread spir
Le Tue, 19 May 2009 11:36:17 +0200, spir s'exprima ainsi: [...] Thank you Albert, Kent, Sanders, Lie, Malcolm. This time regex wins! Thought it wouldn't because of the additional func call (too bad we cannot pass a mapping to re.sub). Actually the diff. is very small ;-) The relevant change

Re: [Tutor] clean text

2009-05-19 Thread python
Denis, Thank you for sharing your detailed analysis with the list. I'm glad on didn't bet money on the winner :) ... I'm just as surprised as you that the regex solution was the fastest. Malcolm ___ Tutor maillist - Tutor@python.org http://mail.pyt

Re: [Tutor] clean text

2009-05-19 Thread Emile van Sebille
On 5/19/2009 10:19 AM spir said... Le Tue, 19 May 2009 11:36:17 +0200, spir s'exprima ainsi: [...] Thank you Albert, Kent, Sanders, Lie, Malcolm. This time regex wins! Thought it wouldn't because of the additional func call (too bad we cannot pass a mapping to re.sub). Actually the diff. is

Re: [Tutor] clean text

2009-05-19 Thread spir
Le Tue, 19 May 2009 10:49:15 -0700, Emile van Sebille s'exprima ainsi: > On 5/19/2009 10:19 AM spir said... > > Le Tue, 19 May 2009 11:36:17 +0200, > > spir s'exprima ainsi: > > > > [...] > > > > Thank you Albert, Kent, Sanders, Lie, Malcolm. > > > > This time regex wins! Thought it wouldn't

Re: [Tutor] Replacement for __del__

2009-05-19 Thread Alan Gauld
"David Stanek" wrote But I think (someone confirms/contradicts?) there is no harm in overloading a class's __del__ to accomplish additional tasks such as deleting temp disk space/dirs/files that need to exist only during object creation. Incorrect. Why? implementation. By the time it

Re: [Tutor] clean text

2009-05-19 Thread Kent Johnson
On Tue, May 19, 2009 at 1:19 PM, spir wrote: > Thank you Albert, Kent, Sanders, Lie, Malcolm. > > This time regex wins! Thought it wouldn't because of the additional func call > (too bad we cannot pass a mapping to re.sub). Actually the diff. is very > small ;-) The relevant  change is indeed us

Re: [Tutor] clean text

2009-05-19 Thread Alan Gauld
"spir" wrote def _cleanRepr(text): ''' text with control chars replaced by repr() equivalent ''' result = "" for char in text: n = ord(char) if (n < 32) or (n > 126 and n < 160): char = repr(char)[1:-1] result += char return result I haven't read the rest of the r

Re: [Tutor] clean text

2009-05-19 Thread Emile van Sebille
On 5/19/2009 11:22 AM spir said... I thought at this solution (having a dict for all chars). But I cannot use it because later I will extend the app to cope with unicode (~ 100_000 chars). So that I really need to filter which chars have to be converted. That seems somewhat of a premature op

Re: [Tutor] odbc connection with python

2009-05-19 Thread Alan Gauld
"mustafa akkoc" wrote how can i make odbc connection language and i wanna make gui project after connecting database anyone has document ? There are lots of GUI options for python but if you want to do a database centred GUI and have no previous knowledge to leverage then dabo is probably y

Re: [Tutor] Replacement for __del__

2009-05-19 Thread spir
Le Tue, 19 May 2009 19:27:16 +0100, "Alan Gauld" s'exprima ainsi: > > def __del__(self): > >try: > >self.f.close() > >except: > >pass > > This is, I agree, pointless. but very different to: > > def __ del__(self): > try: > os.remove(self.lockname) > e

Re: [Tutor] Allow only one instance of a process

2009-05-19 Thread Roger
On Sunday 17 May 2009 21:54:54 Kent Johnson wrote: > On Sat, May 16, 2009 at 10:26 PM, Sylvain Ste-Marie > > wrote: > > I'm currently writing a script to batch convert video for my psp > > > > It basically looks into a folder for video and launch ffmpeg: > > > > ffmpeg -i "videoname" -f psp -r 29.

Re: [Tutor] Allow only one instance of a process

2009-05-19 Thread spir
Le Tue, 19 May 2009 23:09:33 +0300, Roger s'exprima ainsi: > As a Java programmer just starting with Python, this answer surprised me. I > would've been googling for the Python equivalent of the Singleton pattern. > I guess it's going to take longer than I thought to get my head around the > dif

Re: [Tutor] Allow only one instance of a process

2009-05-19 Thread Kent Johnson
On Tue, May 19, 2009 at 4:09 PM, Roger wrote: > As a Java programmer just starting with Python, this answer surprised me. I > would've been googling for the Python equivalent of the Singleton pattern. > I guess it's going to take longer than I thought to get my head around the > differences. A S