Re: find overlapping lines & output times observed

2013-05-06 Thread Oscar Benjamin
On 6 May 2013 19:39, Linsey Raaijmakers wrote: > I have a file like this: > action startend > 50 53215321 > 7 53235347 > 12 53395351 > 45 53735373 > 45 54205420 > 25 54255425 [snip] your code below suggests

Re: object.enable() anti-pattern

2013-05-09 Thread Oscar Benjamin
On 9 May 2013 14:07, Roy Smith wrote: > In article <518b32ef$0$11120$c3e8...@news.astraweb.com>, > Steven D'Aprano wrote: > >> There is no sensible use-case for creating a file without opening it. > > Sure there is. Sometimes just creating the name in the file system is > all you want to do. T

Re: object.enable() anti-pattern

2013-05-10 Thread Oscar Benjamin
On 10 May 2013 15:01, Roy Smith wrote: > In article , > Robert Kern wrote: > >> I'd be curious to see in-the-wild instances of the anti-pattern that >> you are talking about, then. I think everyone agrees that entirely >> unmotivated "enable" methods should be avoided, but I have my doubts >> th

Re: Python 2.7.x - problem with obejct.__init__() not accepting *args and **kwargs

2013-05-15 Thread Oscar Benjamin
On 15 May 2013 12:18, wzab wrote: > I had to implement in Python 2.7.x a system which heavily relies on > multiple inheritance. > Working on that, I have came to very simplistic code which isolates > the problem: > (The essential thing is that each base class receives all arguments > and uses only

Re: Determine actually given command line arguments

2013-05-15 Thread Oscar Benjamin
On 15 May 2013 13:52, Henry Leyh wrote: > On 15.05.2013 14:24, Roy Smith wrote: >> >> In article , >> Henry Leyh wrote: >> >>> Is there a simple way to determine which >>> command line arguments were actually given on the commandline, i.e. does >>> argparse.ArgumentParser() know which of its na

Re: Python 2.7.x - problem with obejct.__init__() not accepting *args and **kwargs

2013-05-16 Thread Oscar Benjamin
On 16 May 2013 03:06, Steven D'Aprano wrote: > On Wed, 15 May 2013 13:16:09 +0100, Oscar Benjamin wrote: > > >> I don't generally use super() > > Then you should, especially in Python 3. > > If you're not using super in single-inheritance classes, then y

Re: Harmonic distortion of a input signal

2013-05-19 Thread Oscar Benjamin
On 19 May 2013 23:25, wrote: > How can i at least find a peek in FFT spectrum of a square wave ? > From there i could easily build formula. Sorry for bothering but i am new to > Python. Are you the same person who posted the original question? You probably want to use numpy for this. I'm not s

Re: Harmonic distortion of a input signal

2013-05-21 Thread Oscar Benjamin
On 20 May 2013 18:23, jmfauth wrote: > Non sense. > > The discrete fft algorithm is valid only if the number of data > points you transform does correspond to a power of 2 (2**n). As with many of your comments about Python's unicode implementation you are confusing performance with validity. The

Re: file I/O and arithmetic calculation

2013-05-22 Thread Oscar Benjamin
On 22 May 2013 22:05, Carlos Nepomuceno wrote: > > filenames = ['1.txt', '2.txt', '3.txt', '4.txt', '5.txt'] > contents = [[[int(z) for z in y.split(',')] for y in open(x).read().split()] > for x in filenames] > s1c = [sum([r[0] for r in f]) for f in contents] > a1r = [sum(f[0])/float(len(f[0]

Re: PEP 378: Format Specifier for Thousands Separator

2013-05-22 Thread Oscar Benjamin
On 22 May 2013 23:31, Carlos Nepomuceno wrote: > > I still don't understand why % benefits from literals optimization > ("'%d'%12345") while '{:d}'.format(12345) doesn't. There's no reason why that optimisation can't happen in principle. However no one has written a patch for it. Why don't you l

Re: file I/O and arithmetic calculation

2013-05-22 Thread Oscar Benjamin
On 23 May 2013 00:49, Carlos Nepomuceno wrote: > > The code is pretty obvious to me, I mean there's no obfuscation at all. I honestly can't tell if you're joking. -- http://mail.python.org/mailman/listinfo/python-list

Re: file I/O and arithmetic calculation

2013-05-23 Thread Oscar Benjamin
On 23 May 2013 04:15, Carlos Nepomuceno wrote: > The last line of my noob piece can be improved. So this is it: Most of it can be improved. > filenames = ['1.txt', '2.txt', '3.txt', '4.txt', '5.txt'] > contents = [[[int(z) for z in y.split(',')] for y in open(x).read().split()] > for x in file

Re: Fatal Python error

2013-05-29 Thread Oscar Benjamin
On 29 May 2013 12:48, Joshua Landau wrote: > Hello all, again. Instead of revising like I'm meant to be, I've been > delving into a bit of Python and I've come up with this code: Here's a simpler example that gives similar results: $ py -3.3 Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:03:

Re: Fatal Python error

2013-05-29 Thread Oscar Benjamin
On 29 May 2013 14:02, Dave Angel wrote: > On 05/29/2013 08:45 AM, Oscar Benjamin wrote: > > More likely a bug in the 2.x interpreter. Once inside an exception handler, > that frame must be held somehow. If not on the stack, then in some separate > list. So the logic will presuma

Re: Harmonic distortion of a input signal

2013-06-12 Thread Oscar Benjamin
On 20 May 2013 00:36, wrote: > One more question. Function np.argmax returns max of non-complex numbers ? > Because FFT array of my signal is complex. Use abs() like in my example. This will give the absolute value of the complex numbers: >>> z = 1+1j >>> z (1+1j) >>> abs(z) 1.4142135623730951

Re: Short-circuit Logic

2013-06-12 Thread Oscar Benjamin
On 30 May 2013 22:03, Carlos Nepomuceno wrote: >> Here's another way, mathematically equivalent (although not necessarily >> equivalent using floating point computations!) which avoids the divide-by- >> zero problem: >> >> abs(a - b) < epsilon*a > > That's wrong! If abs(a) < abs(a-b)/epsilon you w

Re: Split a list into two parts based on a filter?

2013-06-13 Thread Oscar Benjamin
On 12 June 2013 19:47, Terry Reedy wrote: > The proper loop statement > > for s in songs: > (new_songs if s.is_new() else old_songs).append(s) I think I would just end up rewriting this as for s in songs: if s.is_new(): new_songs.append(s) else: old_songs.append(s) b

Re: Don't feed the troll...

2013-06-17 Thread Oscar Benjamin
On 17 June 2013 17:35, D'Arcy J.M. Cain wrote: > On Mon, 17 Jun 2013 14:39:56 + (UTC) > Grant Edwards wrote: >> I don't want _any_ copies from from Mailman. I don't subscribe to >> whatever mailing list you're talking about. I'm reading this via an >> NNTP server. Keep replies in the group

Re: Python Liscensing

2013-06-18 Thread Oscar Benjamin
On 18 June 2013 09:56, Steven Hern wrote: > > We are an educational establishment which wishes to use Python 3.3.2 – Does > the license cover multi-users in a classroom environment? Yes, absolutely. Many educational institutions universities, schools, etc. use Python in classroom environments (th

Re: Beginner Question: 3D Models

2013-06-19 Thread Oscar Benjamin
On 19 June 2013 12:13, wrote: > > I've seen some information on Blender. Is it possible to have the entire > program contained within a single exe (or exe and some other files) so that > it can be passed around and used by others without having to install blender? I don't know if Blender woul

Re: Beginner Question: 3D Models

2013-06-19 Thread Oscar Benjamin
On 19 June 2013 14:14, wrote: > This sounds similar to what I might want. So you know of any online tutorials > for this? It's hard to tell what you're referring to since you haven't included any quoted context in your message (like I have above). I'll assume you're referring to what Fábio said

Re: Problem with the "for" loop syntax

2013-06-20 Thread Oscar Benjamin
On 20 June 2013 04:11, Cameron Simpson wrote: > I use vi/vim and it both shows the matching bracket when the cursor > is on one and also have a keystroke to bounce the curser between > this bracket and the matching one. > > If you suspect you failed to close a bracket, one approach is to > go _bel

Re: Why is the argparse module so inflexible?

2013-06-27 Thread Oscar Benjamin
On 27 June 2013 22:30, Jason Swails wrote: > > An alternative is, of course, to simply subclass ArgumentParser and copy > over all of the code that catches an ArgumentError to eliminate the internal > exception handling and instead allow them to propagate the call stack. I would think it easier t

Re: python adds an extra half space when reading from a string or list

2013-07-03 Thread Oscar Benjamin
On 4 July 2013 01:53, Ben Finney wrote: > rusi writes: > >> As a good Christian I believe that Chris tried more than anyone else >> on this list to help Nikos before talking recourse to another gem of >> biblical wisdom: > >> He that spareth his rod hateth his son: but he that loveth him >> chast

Re: Coping with cyclic imports

2013-07-04 Thread Oscar Benjamin
On 4 July 2013 13:48, wrote: > On Tuesday, April 8, 2008 10:06:46 PM UTC+2, Torsten Bronger wrote: [snip] > > If you do "import foo" inside bar and "import bar" inside foo, it will work > fine. By the time anything actually runs, both modules will be fully loaded > and will have references to e

Re: Coping with cyclic imports

2013-07-05 Thread Oscar Benjamin
On 5 July 2013 02:24, Cameron Simpson wrote: > On 04Jul2013 16:03, Oscar Benjamin wrote: > | > | Is there some reason you're responding to a post from 5 years ago? > > Is there some reason not to, if no newer solutions are available? No, I was genuinely curious. My way of

Re: How to make this faster

2013-07-05 Thread Oscar Benjamin
On 5 July 2013 09:22, Helmut Jarausch wrote: > Hi, > > I have coded a simple algorithm to solve a Sudoku (probably not the first > one). > Unfortunately, it takes 13 seconds for a difficult problem which is more than > 75 times slower > than the same algorithm coded in C++. > Is this to be expec

Re: How to make this faster

2013-07-05 Thread Oscar Benjamin
On 5 July 2013 11:53, Helmut Jarausch wrote: > I even tried to use dictionaries instead of Numpy arrays. This version is a > bit > slower then the lists of lists version (7.2 seconds instead of 6 second) but > still > much faster than the Numpy array solution. When you switched to dictionaries

Re: How to make this faster

2013-07-05 Thread Oscar Benjamin
On 5 July 2013 15:28, Helmut Jarausch wrote: > On Fri, 05 Jul 2013 14:41:23 +0100, Oscar Benjamin wrote: > >> On 5 July 2013 11:53, Helmut Jarausch wrote: >>> I even tried to use dictionaries instead of Numpy arrays. This version is a >>> bit >>> slow

Re: How to make this faster

2013-07-05 Thread Oscar Benjamin
On 5 July 2013 15:48, Helmut Jarausch wrote: > On Fri, 05 Jul 2013 12:02:21 +, Steven D'Aprano wrote: > >> On Fri, 05 Jul 2013 10:53:35 +, Helmut Jarausch wrote: >> >>> Since I don't do any numerical stuff with the arrays, Numpy doesn't seem >>> to be a good choice. I think this is an argu

Re: How to make this faster

2013-07-05 Thread Oscar Benjamin
On 5 July 2013 16:17, Helmut Jarausch wrote: > > I've tried the following version > > def find_good_cell() : > Best= None > minPoss= 10 > for r,c in Grid : > if Grid[(r,c)] > 0 : continue Sorry, I think what I meant was that you should have a structure called e.g. Remaining which is th

Re: xslice idea | a generator slice

2013-07-11 Thread Oscar Benjamin
On 11 July 2013 15:54, Russel Walker wrote: > ...oh and here is the class I made for it. > > class xslice(object): > ''' > xslice(seq, start, stop, step) -> generator slice > ''' > > def __init__(self, seq, *stop): Wouldn't it be better if it has the same signature(s) as itertools

Re: xslice idea | a generator slice

2013-07-11 Thread Oscar Benjamin
On 11 July 2013 17:21, Russel Walker wrote: > To confess, this is the second time I've made the mistake of trying to > implement generator like functionality of a builtin when there already is on > in itertools. Need to start studying that module abit more I think. I'm > looking at the docs now

Re: Python 3: dict & dict.keys()

2013-07-24 Thread Oscar Benjamin
On Jul 24, 2013 7:25 AM, "Peter Otten" <__pete...@web.de> wrote: > > Ethan Furman wrote: > > > So, my question boils down to: in Python 3 how is dict.keys() different > > from dict? What are the use cases? > > I just grepped through /usr/lib/python3, and could not identify a single > line where s

Re: Python 3: dict & dict.keys()

2013-07-24 Thread Oscar Benjamin
On Jul 24, 2013 2:27 PM, "Peter Otten" <__pete...@web.de> wrote: > > Oscar Benjamin wrote: > > > On Jul 24, 2013 7:25 AM, "Peter Otten" <__pete...@web.de> wrote: > >> > >> Ethan Furman wrote: > >> > >> > So, m

Unexpected results comparing float to Fraction

2013-07-30 Thread Oscar Benjamin
On 29 July 2013 17:09, MRAB wrote: > On 29/07/2013 16:43, Steven D'Aprano wrote: >> >> Comparing floats to Fractions gives unexpected results: You may not have expected these results but as someone who regularly uses the fractions module I do expect them. >> # Python 3.3 >> py> from fractions im

Re: Read STDIN as bytes rather than a string

2012-06-19 Thread Oscar Benjamin
On 19 June 2012 00:53, Jason Friedman wrote: > Which leads me to another question ... how can I debug these things? > > $ echo 'hello' | python3 -m pdb ~/my-input.py > > /home/jason/my-input.py(2)() > -> import sys > (Pdb) *** NameError: name 'hello' is not defined > -- > http://mail.python.org/m

Re: Faster way to map numpy arrays

2012-06-25 Thread Oscar Benjamin
On 25 June 2012 08:24, Stefan Behnel wrote: > Saurabh Kabra, 25.06.2012 05:37: > > I have written a script to map a 2D numpy array(A) onto another array(B) > of > > different dimension. more than one element (of array A) are summed and > > mapped to each element of array B. To achieve this I cre

Re: Faster way to map numpy arrays

2012-06-26 Thread Oscar Benjamin
On 26 June 2012 04:20, Saurabh Kabra wrote: > Thanks guys > > I implemented a numpy array with fancy indices and got rid of the list and > the loops. The time to do the mapping improved ~10x. As a matter of fact, > the number of elements in array A to be summed and mapped was different for > each

Re: Opening multiple Files in Different Encoding

2012-07-11 Thread Oscar Benjamin
On 11 July 2012 19:15, wrote: > On Tuesday, July 10, 2012 11:16:08 PM UTC+5:30, Subhabrata wrote: > > Dear Group, > > > > I kept a good number of files in a folder. Now I want to read all of > > them. They are in different formats and different encoding. Using > > listdir/glob.glob I am able to f

Re: properly catch SIGTERM

2012-07-20 Thread Oscar Benjamin
What about Kushal's suggestion above? Does the following work for you? signal.signal(signal.SIGTERM, my_SIGTERM_handler) signal.siginterrupt(signal.SIGTERM, flag=False) According to the siginterrupt docs ( http://docs.python.org/library/signal.html) """ Change system call restart behaviour: if fl

Re: default repr?

2012-07-22 Thread Oscar Benjamin
On 22 July 2012 23:48, Dan Stromberg wrote: > > If a class has defined its own __repr__ method, is there a way of getting > the default repr output for that class anyway? > For new style classes you can just call object.__repr__ e.g.: In [1]: class A(object): ...: pass ...: In [2]: c

Re: default repr?

2012-07-23 Thread Oscar Benjamin
On 23 July 2012 01:24, Steven D'Aprano wrote: > On Mon, 23 Jul 2012 08:54:00 +1000, Chris Angelico wrote: > > > On Mon, Jul 23, 2012 at 8:48 AM, Dan Stromberg > > wrote: > >> If a class has defined its own __repr__ method, is there a way of > >> getting the default repr output for that class any

Re: argparse limitations

2012-07-27 Thread Oscar Benjamin
On 27 July 2012 15:26, Benoist Laurent wrote: > Hi, > > I'm impletting a tool in Python. > I'd like this tool to behave like a standard unix tool, as grep for > exemple. > I chose to use the argparse module to parse the command line and I think > I'm getting into several limitations of this modul

Re: argparse limitations

2012-07-31 Thread Oscar Benjamin
On Jul 31, 2012 10:32 AM, "Benoist Laurent" wrote: > > Well sorry about that but it seems I was wrong. > It was Friday evening and I guess I've not been careful. > > Actually when you specify nargs="?", the doc says "One argument will be consumed from the command line if possible, and produced as

Re: argparse limitations

2012-07-31 Thread Oscar Benjamin
type=int, default=10) > > # create the parser for the "bar" command > sum_parser = subparsers.add_parser("bar", help="bar help") > > return parser > > > if __name__ == '__main__': > args = define_options(

Re: profiling and optimizing

2012-07-31 Thread Oscar Benjamin
On 31 July 2012 13:13, Rita wrote: > hello, > > I recently inherented a large python process and everything is lovely. As > a learning experience I would like to optimize the code so I ran it thru > the profiler > > python -m cProfile myscript.py > > It seems majority of the time is taking in the

Re: argparse limitations

2012-07-31 Thread Oscar Benjamin
On 31 July 2012 13:51, Benoist Laurent wrote: > > Le Jul 31, 2012 à 1:45 PM, Oscar Benjamin a écrit : > > > > On 31 July 2012 12:03, Benoist Laurent wrote: > >> Finally. >> >> The code I proposed doesn't work in this case: if you add any positional &g

Re: looking for a neat solution to a nested loop problem

2012-08-06 Thread Oscar Benjamin
Are you familiar with the itertools module? itertools.product is designed for this purpose: http://docs.python.org/library/itertools#itertools.product Oscar. On 6 August 2012 16:52, Tom P wrote: > consider a nested loop algorithm - > > for i in range(100): > for j in range(100): >

Re: looking for a neat solution to a nested loop problem

2012-08-06 Thread Oscar Benjamin
On 6 August 2012 16:52, Tom P wrote: > consider a nested loop algorithm - > > for i in range(100): > for j in range(100): > do_something(i,j) > > Now, suppose I don't want to use i = 0 and j = 0 as initial values, but > some other values i = N and j = M, and I want to iterate through

Re: looking for a neat solution to a nested loop problem

2012-08-06 Thread Oscar Benjamin
On 6 August 2012 18:14, Tom P wrote: > On 08/06/2012 06:18 PM, Nobody wrote: > >> On Mon, 06 Aug 2012 17:52:31 +0200, Tom P wrote: >> >> consider a nested loop algorithm - >>> >>> for i in range(100): >>> for j in range(100): >>> do_something(i,j) >>> >>> Now, suppose I don't wan

Re: Pickle file and send via socket

2012-08-08 Thread Oscar Benjamin
On 8 August 2012 16:07, lipska the kat wrote: > On 08/08/12 14:50, S.B wrote: > >> On Wednesday, August 8, 2012 3:48:43 PM UTC+3, lipska the kat wrote: >> >>> On 06/08/12 14:32, S.B wrote: >>> >>> > [snip] > > > Thank you so much ! >> The examples are very helpful. >> What happens if I have a re

Re: save dictionary to a file without brackets.

2012-08-09 Thread Oscar Benjamin
On Aug 9, 2012 9:17 PM, wrote: > > Hi, > I have a dict() unique > like this > {(4, 5): 1, (5, 4): 1, (4, 4): 2, (2, 3): 1, (4, 3): 2} > and i want to print to a file without the brackets comas and semicolon in order to obtain something like this? > 4 5 1 > 5 4 1 > 4 4 2 > 2 3 1 > 4 3 2 > Any ideas

Re: save dictionary to a file without brackets.

2012-08-09 Thread Oscar Benjamin
> What do you think? is there a way to speed up the process? > Thanks > Giuseppe Which part is slow? How slow is it? A simple test to find the slow part of your code is to print messages between the commands so that you can see how long it takes between each message. Oscar. -- http://mail.pytho

Re: save dictionary to a file without brackets.

2012-08-09 Thread Oscar Benjamin
On Aug 10, 2012 12:34 AM, "Giuseppe Amatulli" wrote: > > Ciao, > is 12 minutes for 5000x5000 pixel image. half of the time is for > reading the arrays. > and the other half for making the loop. > I will try again to incorporate the mask action in the loop > and > read the image line by line. > Tha

Re: New internal string format in 3.3

2012-08-19 Thread Oscar Benjamin
On 19 August 2012 15:09, wrote: > I can not give you more numbers than those I gave. > As a end user, I noticed and experimented my random tests > are always slower in Py3.3 than in Py3.2 on my Windows platform. > Do the problems have a significant impact on any real application (rather than ran

Re: New internal string format in 3.3

2012-08-19 Thread Oscar Benjamin
On Aug 19, 2012 5:22 PM, wrote > > Py 3.2.3 > >>> timeit.timeit("('aœ€'*100).replace('a', 'œ€é')") > 4.99396356635981 > > Py 3.3b2 > >>> timeit.timeit("('aœ€'*100).replace('a', 'œ€é')") > 7.560455708007855 > > Maybe, not so demonstative. It shows at least, we > are far away from the 10-30% "annouc

Re: Abuse of Big Oh notation

2012-08-20 Thread Oscar Benjamin
On Sun, 19 Aug 2012 16:42:03 -0700, Paul Rubin wrote: Steven D'Aprano writes: > Of course *if* k is constant, O(k) is constant too, but k is not > constant. In context we are talking about string indexing and slicing. > There is no value of k, say, k = 2, for which you can say "People will

Re: Abuse of Big Oh notation

2012-08-20 Thread Oscar Benjamin
On 20 August 2012 17:01, Paul Rubin wrote: > Oscar Benjamin writes: > > No it doen't. It is still O(k). The point of big O notation is to > > understand the asymptotic behaviour of one variable as it becomes > > large because of changes in other variables. > >

Re: Class.__class__ magic trick help

2012-08-21 Thread Oscar Benjamin
On Mon, 20 Aug 2012 21:17:15 -0700 (PDT), Massimo Di Pierro wrote: Consider this code: class SlowStorage(dict): def __getattr__(self,key): return self[key] def __setattr__(self,key): self[key]=value class FastStorage(dict): def __init__(self, __d__=None, *

Re: Class.__class__ magic trick help

2012-08-21 Thread Oscar Benjamin
On 21 August 2012 13:52, Massimo Di Pierro wrote: > On Aug 21, 2:40 am, Oscar Benjamin wrote: > > On Mon, 20 Aug 2012 21:17:15 -0700 (PDT), Massimo Di Pierro > > > > > > > > > > > > > > > > > > > > wrote: > > > Con

Re: Class.__class__ magic trick help

2012-08-21 Thread Oscar Benjamin
On 21 August 2012 14:50, Massimo Di Pierro wrote: > Hello Oscar, > > thanks for your help but your proposal of adding: > > def __setitem__(self,key,value): >self.__dict__[key] = value >dict.__setitem__(self, key, value) > > does not help me. > > What I have today is a class that works like

Class.__class__ magic trick help

2012-08-21 Thread Oscar Benjamin
On 21 August 2012 16:19, Oscar Benjamin wrote: > > On Aug 21, 2012 3:42 PM, "Massimo DiPierro" > wrote: > > > > Thanks again Oscar. I cannot do that. I have tight constraints. I am not > at liberty to modify the code that uses the class. The exposed API cannot &

Re: Guarding arithmetic

2012-08-23 Thread Oscar Benjamin
On 23 August 2012 10:05, Mark Carter wrote: > Suppose I want to define a function "safe", which returns the argument > passed if there is no error, and 42 if there is one. So the setup is > something like: > > def safe(x): ># WHAT WOULD DEFINE HERE? > > print safe(666) # prints 666 > print sa

Re: What do I do to read html files on my pc?

2012-08-28 Thread Oscar Benjamin
On Tue, 28 Aug 2012 03:09:11 -0700 (PDT), mikcec82 wrote: f = open(fileorig, 'r') nomefile = f.read() for x in nomefile: if '' in nomefile: print 'NOK' else : print 'OK' You don't need the for loop. Just do: nomefile = f.read() if '' in nomefile: print('

Re: class object's attribute is also the instance's attribute?

2012-08-30 Thread Oscar Benjamin
On Thu, 30 Aug 2012 05:34:51 -0700 (PDT), Marco Nawijn wrote: If you want attributes to be local to the instance, you have to define them in the __init__ section of the class like this: class A(object): def __init__(self): d = 'my attribute' Except that in this case you'd need to

Re: Beginners question

2012-08-30 Thread Oscar Benjamin
On Thu, 30 Aug 2012 09:23:03 -0400, Dave Angel wrote: I haven't discovered why sometimes the type output shows type instead of class. There are other ways of defining classes, however, and perhaps this is using one of them. Still, it is a class, and stat() is returning an instance of that

Re: class object's attribute is also the instance's attribute?

2012-08-30 Thread Oscar Benjamin
On 30 August 2012 15:11, Marco Nawijn wrote: > > > Learned my lesson today. Don't assume you know something. Test it first > ;). I have done quite some programming in Python, but did not know that > class attributes are still local to the instances. It is also a little > surprising I must say. I a

Re: simple client data base

2012-09-03 Thread Oscar Benjamin
On 3 September 2012 15:12, Mark R Rivet wrote: > Hello all, I am learning to program in python. I have a need to make a > program that can store, retrieve, add, and delete client data such as > name, address, social, telephone number and similar information. This > would be a small client databas

Re: Comparing strings from the back?

2012-09-04 Thread Oscar Benjamin
On 4 September 2012 19:07, Steven D'Aprano < steve+comp.lang.pyt...@pearwood.info> wrote: > On Tue, 04 Sep 2012 18:32:57 +0200, Johannes Bauer wrote: > > > On 04.09.2012 04:17, Steven D'Aprano wrote: > > > >> On average, string equality needs to check half the characters in the > >> string. > > >

Re: Comparing strings from the back?

2012-09-04 Thread Oscar Benjamin
On 4 September 2012 22:59, Chris Angelico wrote: > On Wed, Sep 5, 2012 at 2:32 AM, Johannes Bauer > wrote: > > How do you arrive at that conclusion? When comparing two random strings, > > I just derived > > > > n = (256 / 255) * (1 - 256 ^ (-c)) > > > > where n is the average number of character

Re: Comparing strings from the back?

2012-09-05 Thread Oscar Benjamin
On 5 September 2012 10:48, Peter Otten <__pete...@web.de> wrote: > Chris Angelico wrote: > > > On Wed, Sep 5, 2012 at 6:29 PM, Peter Otten <__pete...@web.de> wrote: > >> comparing every pair in a sample of 1000 8-char words > >> taken from '/usr/share/dict/words' > >> > >> head > >> 1: 477222

Re: Comparing strings from the back?

2012-09-05 Thread Oscar Benjamin
In news.gmane.comp.python.general, you wrote: > On Wed, 05 Sep 2012 16:51:10 +0200, Johannes Bauer wrote: > [...] >>> You are making unjustified assumptions about the distribution of >>> letters in the words. This might be a list of long chemical compounds >>> where the words typically differ only

Re: Comparing strings from the back?

2012-09-06 Thread Oscar Benjamin
On Thu, 06 Sep 2012 06:07:38 -0400, Dave Angel wrote: For random strings (as defined below), the average compare time is effectively unrelated to the size of the string, once the size passes some point. Define random string as being a selection from a set of characters, with replacement.

Re: Comparing strings from the back?

2012-09-07 Thread Oscar Benjamin
On 2012-09-07, Steven D'Aprano wrote: > > > After further thought, and giving consideration to the arguments given by > people here, I'm now satisfied to say that for equal-length strings, > string equality is best described as O(N). > > 1) If the strings are equal, a == b will always compare a

Re: Comparing strings from the back?

2012-09-07 Thread Oscar Benjamin
On 2012-09-07, Oscar Benjamin wrote: > On 2012-09-07, Steven D'Aprano wrote: >> > > Since string comparison is only useful if the strings can be equal or unequal, > the average case depends on how often they are equal/unequal as well as the > average complexity of bo

Re: Comparing strings from the back?

2012-09-08 Thread Oscar Benjamin
On 2012-09-08, Steven D'Aprano wrote: > On Fri, 07 Sep 2012 19:10:16 +0000, Oscar Benjamin wrote: > >> On 2012-09-07, Steven D'Aprano >> wrote: >> >> >> Would you say, then, that dict insertion is O(N)? > > Pedantically, yes. >

Re: Standard Asynchronous Python

2012-09-10 Thread Oscar Benjamin
On 2012-09-10, Dennis Lee Bieber wrote: > On Sun, 9 Sep 2012 20:07:51 -0400, "Dustin J. Mitchell" > declaimed the following in > gmane.comp.python.general: > >> >> My proposal met with near-silence, and I didn't pursue it. Instead, I >> did what any self-respecting hacker would do - I wrote up a

Re: Comparing strings from the back?

2012-09-10 Thread Oscar Benjamin
On 2012-09-10, Steven D'Aprano wrote: > On Mon, 10 Sep 2012 08:59:37 +, Duncan Booth wrote: > >> Gelonida N wrote: >> >> so at the expense of a single dictionary >> insertion when the string is created you can get guaranteed O(1) on all >> the comparisons. > > What interning buys you is that

Re: Comparing strings from the back?

2012-09-10 Thread Oscar Benjamin
On 2012-09-10, Chris Angelico wrote: > On Tue, Sep 11, 2012 at 12:06 AM, Oscar Benjamin > wrote: >> On 2012-09-10, Steven D'Aprano wrote: >>> What interning buys you is that "s == t" is an O(1) pointer compare if >>> they are equal. But if s an

Re: Comparing strings from the back?

2012-09-10 Thread Oscar Benjamin
On 2012-09-10, Oscar Benjamin wrote: > On 2012-09-10, Chris Angelico wrote: >> On Tue, Sep 11, 2012 at 12:06 AM, Oscar Benjamin >> wrote: >>> On 2012-09-10, Steven D'Aprano wrote: >>>> What interning buys you is that "s == t" is an O(1) poi

Re: Comparing strings from the back?

2012-09-10 Thread Oscar Benjamin
On 2012-09-10, Dan Goodman wrote: > On 04/09/2012 03:54, Roy Smith wrote: >> Let's assume you're testing two strings for equality. You've already >> done the obvious quick tests (i.e they're the same length), and you're >> down to the O(n) part of comparing every character. >> >> I'm wondering if

Re: Comparing strings from the back?

2012-09-10 Thread Oscar Benjamin
On 2012-09-10, Dan Goodman wrote: > On 10/09/2012 18:07, Dan Goodman wrote: >> On 04/09/2012 03:54, Roy Smith wrote: >>> Let's assume you're testing two strings for equality. You've already >>> done the obvious quick tests (i.e they're the same length), and you're >>> down to the O(n) part of com

Re: Comparing strings from the back?

2012-09-11 Thread Oscar Benjamin
On 11 September 2012 10:51, Duncan Booth wrote: > Oscar Benjamin wrote: > > >> What interning buys you is that "s == t" is an O(1) pointer compare > >> if they are equal. But if s and t differ in the last character, > >> __eq__ will still inspe

Re: submit jobs on multi-core

2012-09-11 Thread Oscar Benjamin
On 2012-09-11, Dhananjay wrote: > --===0316394162== > Content-Type: multipart/alternative; boundary=20cf30776bd309ffd004c96557e2 > > --20cf30776bd309ffd004c96557e2 > Content-Type: text/plain; charset=ISO-8859-1 > > Dear all, > > I have a python script in which I have a list of files to

Re: generators as decorators simple issue

2012-09-12 Thread Oscar Benjamin
On Wed, 12 Sep 2012 03:22:31 -0700 (PDT), pyjoshsys wrote: The output is still not what I want. Now runtime error free, however the output is not what I desire. def setname(cls): '''this is the proposed generator to call SetName on the object''' try: cls.SetName(cls.__name

Re: Boolean function on variable-length lists

2012-09-12 Thread Oscar Benjamin
On 12 September 2012 14:25, Libra wrote: > On Wednesday, September 12, 2012 3:11:42 PM UTC+2, Steven D'Aprano wrote: > > On Wed, 12 Sep 2012 05:48:09 -0700, Libra wrote: > > > > I need to implement a function that returns 1 only if all the values in > > > a list satisfy given constraints (at leas

Re: using subprocess.Popen does not suppress terminal window on Windows

2012-09-13 Thread Oscar Benjamin
On Thu, 13 Sep 2012 00:27:10 -0700 (PDT), janis.judvai...@gmail.com wrote: I'm making a little embedded system programming IDE so I need to run .exe(windows only), make commands, perl & python scripts etc(multiplatform). I'm using subprocess.Popen for all of them and it works fine except that

Re: Re: using subprocess.Popen does not suppress terminal window on Windows

2012-09-13 Thread Oscar Benjamin
On 13 September 2012 10:22, Oscar Benjamin wrote: > On Thu, 13 Sep 2012 00:27:10 -0700 (PDT), janis.judvai...@gmail.com wrote: > >> I'm making a little embedded system programming IDE so I need to >> > run .exe(windows only), make commands, perl & python scripts &g

Re: using subprocess.Popen does not suppress terminal window on Windows

2012-09-13 Thread Oscar Benjamin
On 13 September 2012 13:33, wrote: > It looks like normal terminal to me, could You define normal? > > Looks like it appears only when target script prints something, but it > shouldn't cus I'm using pipes on stdout and stderr. > > If anyone is interested I'm using function doPopen from here: > h

Re: gc.get_objects()

2012-09-17 Thread Oscar Benjamin
On 2012-09-17, Matteo Boscolo wrote: > from my gc.get_object() > I extract the sub system of the object that I would like to delete: > > this is the object: > Class name > win32com.gen_py.F4503A16-F637-11D2-BD55-00500400405Bx0x1x0.ITDProperty.ITDProperty > that is traked and the reference are: >

Re: Using dict as object

2012-09-19 Thread Oscar Benjamin
On 2012-09-19, Dave Angel wrote: > On 09/19/2012 06:24 AM, Pierre Tardy wrote: >> All implementation I tried are much slower than a pure native dict access. >> Each implementation have bench results in commit comment. All of them >> are 20+x slower than plain dict! > > Assuming you're talking ab

Re: Using dict as object

2012-09-19 Thread Oscar Benjamin
On 2012-09-19, Pierre Tardy wrote: > --===1362296571== > Content-Type: multipart/alternative; boundary=bcaec554d3229e814204ca105e50 > > --bcaec554d3229e814204ca105e50 > Content-Type: text/plain; charset=ISO-8859-1 > >> >> This has been proposed and discussed and even implemented many

For Counter Variable

2012-09-23 Thread Oscar Benjamin
On Sep 23, 2012 5:42 PM, "jimbo1qaz" wrote: > > Am I missing something obvious, or do I have to manually put in a counter in the for loops? That's a very basic request, but I couldn't find anything in the documentation. Have you seen the enumerate function? Oscar -- http://mail.python.org/mailm

Re: For Counter Variable

2012-09-23 Thread Oscar Benjamin
On Sep 23, 2012 6:52 PM, "jimbo1qaz" wrote: > > On Sunday, September 23, 2012 9:36:19 AM UTC-7, jimbo1qaz wrote: > > Am I missing something obvious, or do I have to manually put in a counter in the for loops? That's a very basic request, but I couldn't find anything in the documentation. > > Ya, t

Re: Anyone able to help on installing packages?

2012-09-23 Thread Oscar Benjamin
On Sep 23, 2012 6:56 PM, "John Mordecai Dildy" wrote: > > Hello everyone out there. Ive been trying to install packages like distribute, nose, and virturalenv and believe me it is a hard process to do. I tried everything I could think of to install. > > I have done the following: > > pip install

Re: Anyone able to help on installing packages?

2012-09-23 Thread Oscar Benjamin
Please send your reply to the mailing list (python-list@python.org) rather than privately to me. On 23 September 2012 20:57, John Dildy wrote: > When I give input at the start of terminal using the command pip install > virtualenv: > > Downloading/unpacking virtualenv > Running setup.py egg_i

Re: List Problem

2012-09-23 Thread Oscar Benjamin
On 23 September 2012 22:31, jimbo1qaz wrote: > I have a nested list. Whenever I make a copy of the list, changes in one > affect the other, even when I use list(orig) or even copy the sublists one > by one. I have to manually copy each cell over for it to work. > Link to broken code: http://jimbo

Re: Editing Inkscape SVG files with Python?

2012-09-23 Thread Oscar Benjamin
On 23 September 2012 23:53, Steven D'Aprano < steve+comp.lang.pyt...@pearwood.info> wrote: > I have some SVG files generated with Inkscape containing many text blocks > (over 100). I wish to programmatically modify those text blocks using > Python. Is there a library I should be using, or any othe

Re: Java singletonMap in Python

2012-09-23 Thread Oscar Benjamin
On 24 September 2012 00:14, Mark Lawrence wrote: > Purely for fun I've been porting some code to Python and came across the > singletonMap[1]. I'm aware that there are loads of recipes on the web for > both singletons e.g.[2] and immutable dictionaries e.g.[3]. I was > wondering how to combine

  1   2   3   4   5   6   7   >