Iterator class to allow self-restarting generator expressions?

2009-03-01 Thread John O'Hagan
Inspired by some recent threads here about using classes to extend the behaviour of iterators, I'm trying to replace some some top-level functions aimed at doing such things with a class. So far it's got a test for emptiness, a non-consuming peek-ahead method, and an extended next() which can

Re: Iterator class to allow self-restarting generator expressions?

2009-03-01 Thread John O'Hagan
On Sun, 1 Mar 2009, Mark Tolonen wrote: John O'Hagan resea...@johnohagan.com wrote in message news:200903011520.29405.resea...@johnohagan.com... Inspired by some recent threads here about using classes to extend the behaviour of iterators, I'm trying to replace some some top-level

Re: Iterator class to allow self-restarting generator expressions?

2009-03-02 Thread John O'Hagan
On Sun, 1 Mar 2009, Terry Reedy wrote: John O'Hagan wrote: Inspired by some recent threads here about using classes to extend the behaviour of iterators, I'm trying to replace some some top-level functions aimed at doing such things with a class. So far it's got a test for emptiness

A better way to timeout a class method?

2009-03-09 Thread John O'Hagan
Is there a concise Pythonic way to write a method with a timeout? I did this: class Eg(object): def get_value(self, timeout): from threading import Timer self.flag = True def flag_off(): self.flag = False timer = Timer(timeout, flag_off)

Re: A better way to timeout a class method?

2009-03-09 Thread John O'Hagan
On Mon, 9 Mar 2009, Marco Mariani wrote: John O'Hagan wrote: Is there a concise Pythonic way to write a method with a timeout? No need for threading. Just define a signal handler and call signal.alarm(). Thanks, that works well in general; but unfortunately the method in question (see

Re: A better way to timeout a class method?

2009-03-10 Thread John O'Hagan
On Mon, 9 Mar 2009, Nick Craig-Wood wrote: John O'Hagan resea...@johnohagan.com wrote: Is there a concise Pythonic way to write a method with a timeout? I did this: class Eg(object): def get_value(self, timeout): from threading import Timer self.flag

Re: argument problem in optparse

2009-03-20 Thread John O'Hagan
On Fri, 20 Mar 2009, Qian Xu wrote: Hi All, I have a problem with OptParse. I want to define such an arugument. It can accept additional value or no value. myscript.py --unittest File1,File2 myscript.py --unittest Is it possible in OptParse? I have tried several combination. But ...

Re: numpy array sorting weirdness

2009-03-28 Thread John O'Hagan
On Sun, 29 Mar 2009, Daniel Fetchinson wrote: [...] The fact that the following two outputs are not the same is a bug or a feature of numpy? # I would have thought the two array outputs would be the same ## import numpy a = [ [ 0, 0 ], [ 1, 0 ], [ 1, 1 ] ] pythonarray = a

Re: python for loop

2009-04-01 Thread John O'Hagan
On Wed, 1 Apr 2009, Steven D'Aprano wrote: On Wed, 01 Apr 2009 04:39:26 +0100, Rhodri James wrote: Dragging this back to the original topic, you clearly find starting list indices from zero unintuitive. To me, with a mathematical background, it's not just intuitive, it's correct. All

Re: python for loop

2009-04-02 Thread John O'Hagan
On Thu, 2 Apr 2009, Steven D'Aprano wrote: On Thu, 02 Apr 2009 04:23:32 +, John O'Hagan wrote: Beyond being part of a conventionally-ordered set of keys, what can an ordinality of zero actually mean? (That's a sincere question.) [snip erudite definition of cardinality] For non

Re: simple iterator question

2009-04-02 Thread John O'Hagan
On Thu, 2 Apr 2009, Neal Becker wrote: How do I interleave 2 sequences into a single sequence? How do I interleave N sequences into a single sequence? Here's one way: def interleave(*args): for n in range(min(len(i) for i in args)) : for i in args: yield i[n] HTH,

any(), all() and empty iterable

2009-04-11 Thread John O'Hagan
Hi, I was getting some surprising false positives as a result of not expecting this: all(element in item for item in iterable) to return True when 'iterable' is empty. I guess it goes into hairy Boolean territory trying to decide if an element is in an item that doesn't exist (if that's

Re: any(), all() and empty iterable

2009-04-12 Thread John O'Hagan
On Sun, 12 Apr 2009, Paul Rubin wrote: Tim Chase python.l...@tim.thechases.com writes: Return True if all elements of the iterable are true. ... Then I'd say the comment is misleading. An empty list has no item that is true (or false), yet it returns true. The

Re: any(), all() and empty iterable

2009-04-12 Thread John O'Hagan
On Sun, 12 Apr 2009, Chris Rebert wrote: On Sat, Apr 11, 2009 at 9:00 PM, John O'Hagan m...@johnohagan.com wrote: Hi, I was getting some surprising false positives as a result of not expecting this: all(element in item for item in iterable) to return True when 'iterable' is empty

Re: any(), all() and empty iterable

2009-04-14 Thread John O'Hagan
On Tue, 14 Apr 2009, Carl Banks wrote: On Apr 12, 10:45 am, Tim Chase python.l...@tim.thechases.com wrote: That's why you ask Do you have any books called 'Robinson Crusoe'? rather than Are all your books called 'Robinson Crusoe'?. Mu.  If I don't have any books...Have you stopped

Re: any(), all() and empty iterable

2009-04-14 Thread John O'Hagan
On Tue, 14 Apr 2009, Mark Dickinson wrote: On Apr 14, 7:21 pm, Luis Alberto Zarrabeitia Gomez ky...@uh.cu wrote: It's more than that. Python's following the rules here. Maybe it could be documented better, for those without a background in logic/discrete mathematics, but not changed.

Use of generators and efficiency

2008-09-17 Thread John O'Hagan
in turn? Any explanations, comments or advice? Thanks, John O'Hagan -- http://mail.python.org/mailman/listinfo/python-list

How best to pass arbitrary parameters from one function to another

2008-09-30 Thread John O'Hagan
tedious because there are very many of them but only a few are used in any given execution of the program. Is there a better way to do it? Or have I simply made an error? Regards and thanks, John O'Hagan -- http://mail.python.org/mailman/listinfo/python-list

Re: How best to pass arbitrary parameters from one function to another

2008-09-30 Thread John O'Hagan
On Tue Sep 30 11:32:41 CEST 2008, Steven D'Aprano On Tue, 30 Sep 2008 08:58:15 +, John O'Hagan wrote: Hi Pythonistas, I'm looking for the best way to pass an arbitrary number and type of variables created by one function to another. They can't be global because they may have

Optparse object containing generators: only seem to work if given particular names?

2008-10-31 Thread John O'Hagan
in figuring out why this is happening. Thanks, John O'Hagan Here's the code: import sys from optparse import OptionParser def my_callback(option, opt_str, value, parser): rargs = parser.rargs if rargs[0] == CTRL: : setattr(parser.values

Re: Optparse object containing generators: only seem to work if given particular names?

2008-10-31 Thread John O'Hagan
On Fri, 31 Oct 2008, Peter Otten wrote: John O'Hagan wrote: Here's a strange one for you: I have a generator function which produces lists of numbers and takes options which influence the output. The generator contains a loop, and to enable the options to have a different value on each

Is this optparse object abuse?

2008-11-16 Thread John O'Hagan
a truck to deliver a ping-pong ball. My question is: is this horribly inefficient or otherwise wrong? Thanks, John O'Hagan -- http://mail.python.org/mailman/listinfo/python-list

Re: Is this optparse object abuse?

2008-11-16 Thread John O'Hagan
On Sun, 16 Nov 2008, Diez B. Roggisch wrote: In other words, using the optparse object to hold as attributes everything needed by all the functions and methods in the module, and simply passing it holus bolus to all them and just pulling out what's actually needed inside the function, even

Re: Is this optparse object abuse?

2008-11-16 Thread John O'Hagan
On Sun, 16 Nov 2008, Bruno Desthuilliers wrote: John O'Hagan a écrit : [...] In other words, using the optparse object to hold as attributes everything needed by all the functions and methods in the module, and simply passing it holus bolus to all them and just pulling out what's

Re: Is this optparse object abuse?

2008-11-16 Thread John O'Hagan
On Sun, 16 Nov 2008, Diez B. Roggisch wrote: John O'Hagan wrote: On Sun, 16 Nov 2008, Diez B. Roggisch wrote: In other words, using the optparse object to hold as attributes everything needed by all the functions and methods in the module, and simply passing it holus bolus to all them

Instance attributes vs method arguments

2008-11-24 Thread John O'Hagan
= args.d return c + d ? Assuming we don't need access to the args from outside the class, is there anything to be gained (or lost) by not initialising attributes that won't be used unless particular methods are called? Thanks, John O'Hagan -- http://mail.python.org/mailman

Re: Instance attributes vs method arguments

2008-11-25 Thread John O'Hagan
On Tue, 25 Nov 2008, Marc 'BlackJack' Rintsch wrote: On Tue, 25 Nov 2008 07:27:41 +, John O'Hagan wrote: Is it better to do this: class Class_a(): def __init__(self, args): self.a = args.a self.b = args.b self.c = args.c

Re: Instance attributes vs method arguments

2008-11-25 Thread John O'Hagan
On Tue, 25 Nov 2008, Rafe wrote: On Nov 25, 5:48 pm, John O'Hagan [EMAIL PROTECTED] wrote: On Tue, 25 Nov 2008, Marc 'BlackJack' Rintsch wrote: On Tue, 25 Nov 2008 07:27:41 +, John O'Hagan wrote: Is it better to do this: class Class_a():       def __init__(self, args

Re: Instance attributes vs method arguments

2008-11-25 Thread John O'Hagan
On Wed, 26 Nov 2008, Ben Finney wrote: John O'Hagan [EMAIL PROTECTED] writes: insofar as one is only interested in accessing methods, is there an difference in efficiency (for large enough number of methods and arguments) between a) passing all arguments to __init__() and accessing them

Confused about class relationships

2008-11-26 Thread John O'Hagan
? Or is it fine as is? I'm hoping this is a common trap I've fallen into; I just haven't been able to get my head around it. (I'm a musician...) John O'Hagan -- http://mail.python.org/mailman/listinfo/python-list

Re: Confused about class relationships

2008-11-30 Thread John O'Hagan
On Sat, 29 Nov 2008, Carl Banks wrote: On Nov 26, 11:20 pm, John O'Hagan [EMAIL PROTECTED] wrote: [...] class Bar(list):         def __init__(self, a_bar, args, engine):                 list.__init__ (self, a_bar)                 self[:] = a_bar                         self.args

Re: Python music sequencer timing problems

2008-12-10 Thread John O'Hagan
On Wed, 10 Dec 2008, badmuthahubbard wrote: I've been trying to get the timing right for a music sequencer using Tkinter. First I just loaded the Csound API module and ran a Csound engine in its own performance thread. The score timing was good, being controlled internally by Csound, but any

Re: Python music sequencer timing problems

2008-12-14 Thread John O'Hagan
On Sun, 14 Dec 2008, Bad Mutha Hubbard wrote: John O'Hagan wrote: On Wed, 10 Dec 2008, badmuthahubbard wrote: [...] from time import time, sleep start = time() for event in music: duration=len(event) #Really, the length of the event play(event) while 1: timer

Re: Python music sequencer timing problems

2008-12-16 Thread John O'Hagan
On Mon, 15 Dec 2008, John O'Hagan wrote: On Sun, 14 Dec 2008, Bad Mutha Hubbard wrote: John O'Hagan wrote: On Wed, 10 Dec 2008, badmuthahubbard wrote: [...] from time import time, sleep start = time() for event in music: duration=len(event) #Really, the length

Namespaces, multiple assignments, and exec()

2008-12-19 Thread John O'Hagan
I have a lot of repetitive assignments to make, within a generator, that use a function outside the generator: var1 = func(var1, args) var2 = func(var2, args) var3 = func(var3, args) etc... In each case the args are identical, but the first argument is a string of the name being assigned. It

Re: Namespaces, multiple assignments, and exec()

2008-12-20 Thread John O'Hagan
On Sat, 20 Dec 2008, Arnaud Delobelle wrote: John O'Hagan resea...@johnohagan.com writes: I have a lot of repetitive assignments to make, within a generator, that use a function outside the generator: var1 = func(var1, args) var2 = func(var2, args) var3 = func(var3, args) etc

Re: Namespaces, multiple assignments, and exec()

2008-12-20 Thread John O'Hagan
On Sat, 20 Dec 2008, Steven D'Aprano wrote: On Sat, 20 Dec 2008 02:53:16 +, MRAB wrote: If you're sure you want to use the current namespace then: for name in namelist: vars()[name] = func(name, args) Doesn't work inside a function: def parrot(): ... for name

Re: Namespaces, multiple assignments, and exec()

2008-12-20 Thread John O'Hagan
On Sat, 20 Dec 2008, Terry Reedy wrote: John O'Hagan wrote: I have a lot of repetitive assignments to make, within a generator, that use a function outside the generator: var1 = func(var1, args) var2 = func(var2, args) var3 = func(var3, args) etc... In each case the args

Re: Namespaces, multiple assignments, and exec()

2008-12-21 Thread John O'Hagan
On Sat, 20 Dec 2008, John O'Hagan wrote: On Sat, 20 Dec 2008, Terry Reedy wrote: John O'Hagan wrote: I have a lot of repetitive assignments to make, within a generator, that use a function outside the generator: var1 = func(var1, args) var2 = func(var2, args) var3 = func(var3

Re: why cannot assign to function call

2008-12-30 Thread John O'Hagan
On Tue, 30 Dec 2008, Aaron Brady wrote: [...] On a technicality, to avert a flaming, change the value of 'b' is an ambiguous phrase. There are two interpretations of change what 'b' refers to and change what 'b' refers to. Even in spoken language, I don't think that emphasis can resolve them

Re: why cannot assign to function call

2009-01-03 Thread John O'Hagan
On Tue, 30th Dec 2008, Aaron Brady wrote: Accepting that, I'll adopt the terms John proposed, 'change' vs. 'exchange', the former when the material configuration changes, the latter when the communication axioms change. b= [2, 3] b= [3, 4] 'b' has exchanged. (Somewhat ungrammatical.) b= [2,

Re: self-aware list of objects able to sense constituent member alterations?

2009-01-28 Thread John O'Hagan
On Tue, 27 Jan 2009, Reckoner wrote: I'm not sure this is possible, but I would like to have a list of objects A=[a,b,c,d,...,z] where, in the midst of a lot of processing I might do something like, A[0].do_something_which_changes_the_properties() which alter the properties of the

Re: self-aware list of objects able to sense constituent member alterations?

2009-02-08 Thread John O'Hagan
On Fri, 6 Feb 2009, greyw...@gmail.com wrote: On Jan 28, 4:37 am, John O'Hagan m...@johnohagan.com wrote: On Tue, 27 Jan 2009, Reckoner wrote: I'm not sure this is possible, but I would like to have a list of  objects A=[a,b,c,d,...,z] where,  in the midst of a lot

Small socket problem

2009-02-09 Thread John O'Hagan
happens. I am a long way from being a networking guru and am at a loss as to how to debug this. Maybe someone can point out some flaw in my use of socket. Thanks, John O'Hagan -- http://mail.python.org/mailman/listinfo/python-list

Re: Small socket problem

2009-02-09 Thread John O'Hagan
On Mon, 9 Feb 2009, Gabriel Genellina wrote: En Mon, 09 Feb 2009 07:43:36 -0200, John O'Hagan resea...@johnohagan.com escribió: I'm using the socket module (python 2.5) like this (where 'options' refers to an optparse object) to connect to the Fluidsynth program: host

Re: generator object or 'send' method?

2009-02-09 Thread John O'Hagan
On Mon, 9 Feb 2009, Aaron Brady wrote: Hello, I am writing a generator to return a sequence of numbers with some variation. The parameters of the variation can be changed by the caller, even after the generator is started. [...] I would love to see a simple code example of this if you have

Re: playing mp3

2009-10-27 Thread John O'Hagan
On Mon, 26 Oct 2009, Jabba Laci wrote: Hi, What do you suggest for playing mp3 files with Python? I found a simple module (http://code.google.com/p/mp3play/) but it only works with Windows. I'd need Linux support too. [...] If it doesn't need to be pure python, you could use a

Writing to function arguments during execution

2009-10-11 Thread John O'Hagan
I'm writing a (music-generating) program incorporating a generator function which takes dictionaries as its arguments. I want to be able to change the values of the arguments while the program is running. I have it working as in this toy example (python 2.5): from sys import argv from

Re: Writing to function arguments during execution

2009-10-13 Thread John O'Hagan
On Mon, 12 Oct 2009, Rhodri James wrote: On Sun, 11 Oct 2009 14:18:25 +0100, John O'Hagan resea...@johnohagan.com wrote: Now I can change the output of the work function while it's running via raw_input(). However it's very crude, not least because the terminal echo of the new options

Raw_input with readline in a daemon thread makes terminal text disappear

2009-10-15 Thread John O'Hagan
I'm getting input for a program while it's running by using raw_input in a loop in separate thread. This works except for the inconvenience of not having a command history or the use of backspace etc. That can be solved by loading the readline module; however, it results in a loss of visible

Re: a splitting headache

2009-10-15 Thread John O'Hagan
On Fri, 16 Oct 2009, Mensanator wrote: All I wanted to do is split a binary number into two lists, a list of blocks of consecutive ones and another list of blocks of consecutive zeroes. [...] That means I can use re to solve my problem after all. c = '001110' re.sub('0','

Re: Raw_input with readline in a daemon thread makes terminal text disappear

2009-10-20 Thread John O'Hagan
On Mon, 19 Oct 2009, Aahz wrote: In article mailman.1448.1255618675.2807.python-l...@python.org, John O'Hagan resea...@johnohagan.com wrote: I'm getting input for a program while it's running by using raw_input in a loop in separate thread. This works except for the inconvenience

Socket logic problem

2009-10-24 Thread John O'Hagan
I have several instances of the same generator function running simultaneously, some within the same process, others in separate processes. I want them to be able to share data (the dictionaries passed to them as arguments), in such a way that instances designated as leaders send their

Re: Socket logic problem

2009-10-26 Thread John O'Hagan
On Sun, 25 Oct 2009, Gabriel Genellina wrote: En Sat, 24 Oct 2009 06:40:08 -0300, John O'Hagan resea...@johnohagan.com escribió: I have several instances of the same generator function running simultaneously, some within the same process, others in separate processes. I want them

Surprising timeit result

2009-10-26 Thread John O'Hagan
I sometimes use timeit to see if it's better to check if something needs doing, or to just do it anyway. This result was surprising: setup = 'd1 = {a:0, b:0}; d2 = {a:0, b:1}' Timer('d1.update(d2)', setup).timeit() 2.6499271392822266 Timer('if d1 != d2: d1.update(d2)', setup).timeit()

Re: Surprising timeit result

2009-10-26 Thread John O'Hagan
On Tue, 27 Oct 2009, Paul Rubin wrote: John O'Hagan resea...@johnohagan.com writes: Timer('d1.update(d2)', setup).timeit() 2.6499271392822266 Timer('if d1 != d2: d1.update(d2)', setup).timeit() 1.0235211849212646 In other words, in this case it's substantially quicker to check

Re: tough-to-explain Python

2009-07-11 Thread John O'Hagan
On Fri, 10 Jul 2009, Hendrik van Rooyen wrote: Steven D'Aprano st...@remove-this-cye.com.au wrote: On Wed, 08 Jul 2009 22:05:57 -0700, Simon Forman wrote: [...] Programming is not like any other human activity. In practice? In principle? Programming in principle is not the same as it

Re: question on input function

2009-07-19 Thread John O'Hagan
On Mon, 20 Jul 2009, Richel Satumbaga wrote: I am just learning python then I encountered an certain point in terms of using the input function of python. the source code: eq = input(enter an equation:); print the result is : ; the output seen

Re: type(d) != type(d.copy()) when type(d).issubclass(dict)

2010-12-25 Thread John O'Hagan
On Sat, 25 Dec 2010, Steven D'Aprano wrote: On Sat, 25 Dec 2010 15:58:35 +, Duncan Booth wrote: kj no.em...@please.post wrote: Watch this: class neodict(dict): pass ... d = neodict() type(d) class '__main__.neodict' type(d.copy()) type 'dict' Bug? Feature?

Re: Sending changed parameters into nested generators

2011-01-21 Thread John O'Hagan
On Fri, 21 Jan 2011, cbrown wrote: On Nov 12, 10:52 pm, John O'Hagan resea... at johnohagan.com wrote: On Sat, 13 Nov 2010, Steven D'Aprano wrote: On Fri, 12 Nov 2010 09:47:26 +, John O'Hagan wrote: I have a generator function which takes as arguments another generator

Re: how to read the last line of a huge file???

2011-01-27 Thread John O'Hagan
On Wed, 26 Jan 2011, Xavier Heruacles wrote: I have do some log processing which is usually huge. The length of each line is variable. How can I get the last line?? Don't tell me to use readlines or something like linecache... file.seek takes an optional 'whence' argument which is 2 for the

Algorithm for generating pitch-class sets in prime form

2011-01-28 Thread John O'Hagan
I'm looking for some help coming up with an algorithm to produce lists which meet the following criterion (you don't need to know music to get this): In musical pitch-class set theory, prime form is defined as the most tightly- packed-to-the-left rotation of a set's interval structure. Prime

Re: how to read the last line of a huge file???

2011-01-29 Thread John O'Hagan
On Sat, 29 Jan 2011, Aahz wrote: In article mailman.1412.1296196161.6505.python-l...@python.org, John O'Hagan resea...@johnohagan.com wrote: [...] def lastline(filename): offset = 0 line = '' with open(filename) as f: while True: offset -= 1

Reassign or discard Popen().stdout from a server process

2011-02-01 Thread John O'Hagan
I'm starting a server process as a subprocess. Startup is slow and unpredictable (around 3-10 sec), so I'm reading from its stdout until I get a line that tells me it's ready before proceeding, in simplified form: import subprocess proc = subprocess.Popen(['server', 'args'],

Re: Reassign or discard Popen().stdout from a server process

2011-02-01 Thread John O'Hagan
On Tue, 1 Feb 2011, Chris Rebert wrote: On Tue, Feb 1, 2011 at 12:30 AM, John O'Hagan m...@johnohagan.com wrote: I'm starting a server process as a subprocess. Startup is slow and unpredictable (around 3-10 sec), so I'm reading from its stdout until I get a line that tells me it's ready

Re: Reassign or discard Popen().stdout from a server process

2011-02-01 Thread John O'Hagan
On Tue, 1 Feb 2011, John O'Hagan wrote: So far my best bet seems to be closing stdin, which doesn't seem very clean, but it does what I want and seems to be just as fast as using stdin=open(os.devnull) in the Popen call in the first place. ...and both references to stdin above should have

Re: Reassign or discard Popen().stdout from a server process

2011-02-04 Thread John O'Hagan
On Thu, 3 Feb 2011, Nobody wrote: On Tue, 01 Feb 2011 08:30:19 +, John O'Hagan wrote: I can't keep reading because that will block - there won't be any more output until I send some input, and I don't want it in any case. To try to fix this I added: proc.stdout = os.path.devnull

Re: Reassign or discard Popen().stdout from a server process

2011-02-10 Thread John O'Hagan
On Wed, 9 Feb 2011, Nobody wrote: On Fri, 04 Feb 2011 15:48:55 +, John O'Hagan wrote: But I'm still a little curious as to why even unsuccessfully attempting to reassign stdout seems to stop the pipe buffer from filling up. It doesn't. If the server continues to run, then it's ignoring

Re: Algorithm for generating pitch-class sets in prime form

2011-02-10 Thread John O'Hagan
On Sat, 5 Feb 2011, Charles Turner wrote: Hi- Do you knowof Christopher Ariza's AthenaCL? http://www.flexatone.net/athenaInfo.html#athenaFeatAnalytic HTH, Charles Wow. That looks like a much more complete and elaborate version of what I'm doing, although from what I can tell I don't

Re: Reassign or discard Popen().stdout from a server process

2011-02-11 Thread John O'Hagan
On Fri, 11 Feb 2011, Nobody wrote: On Thu, 10 Feb 2011 08:35:24 +, John O'Hagan wrote: But I'm still a little curious as to why even unsuccessfully attempting to reassign stdout seems to stop the pipe buffer from filling up. It doesn't. If the server continues to run, then it's

Re: any(), all() and empty iterable

2009-04-20 Thread John O'Hagan
On Mon, 20 Apr 2009, Antoon Pardon wrote: On 2009-04-15, John O'Hagan m...@johnohagan.com wrote: On Tue, 14 Apr 2009, Mark Dickinson wrote: [...] I'd like to guess that in 93.7% of cases, when a programmer has used all(seq) without having thought in advance about what the right thing

Re: returning values of a particular key from a dictionary

2009-05-01 Thread John O'Hagan
On Fri, 1 May 2009, Saurabh wrote: arr = ({'x':'1', 'y':'a'}, {'x':'2', 'y':'b'}, {'x':'3', 'y':'c'}) print foo(arr, 'y') ['a','b','c'] I can write the function foo to return ['a','b','c']. Is there some 'automatic'/built-in way to get this in Python ? List comprehension: [i['y'] for i in

Re: object query assigned variable name?

2009-05-01 Thread John O'Hagan
On Fri, 1 May 2009, warpcat wrote: I've passed this around some other groups, and I'm being told probably not possible. But I thought I'd try here as well :) I *did* search first, and found several similar threads, but they quickly tangented into other specifics of the language that were a

Re: debian apt somehow created python hell! - help

2009-05-01 Thread John O'Hagan
On Sat, 2 May 2009, watermod wrote: I was doing one of those auto apt-get gui things with update manager in Debian and not watching the error log so I don't know where it started. It involves only Python stuff. I don't know Python but apps use it. The current apt state is that python apps

Re: object query assigned variable name?

2009-05-03 Thread John O'Hagan
On Sat, 2 May 2009, John O'Hagan wrote: On Fri, 1 May 2009, warpcat wrote: [...] Given an object: class Spam(object): def __init__(self): # stuff I'd like it to print, when instanced, something like this: s = Spam() I’m assigned to s! If you just want

Re: find sublist inside list

2009-05-04 Thread John O'Hagan
On Mon, 4 May 2009, Matthias Gallé wrote: Hi. My problem is to replace all occurrences of a sublist with a new element. Example: Given ['a','c','a','c','c','g','a','c'] I want to replace all occurrences of ['a','c'] by 6 (result [6,6,'c','g',6]). li=['a', 'c', 'a', 'c', 'c', 'g', 'a',

Re: find sublist inside list

2009-05-04 Thread John O'Hagan
On Mon, 4 May 2009, Francesco Guerrieri wrote: On Mon, May 4, 2009 at 3:01 PM, John O'Hagan m...@johnohagan.com wrote: On Mon, 4 May 2009, Matthias Gallé wrote: Hi. My problem is to replace all occurrences of a sublist with a new element. Example: Given ['a','c','a','c','c

Re: object query assigned variable name?

2009-05-05 Thread John O'Hagan
On Tue, 5 May 2009, Sion Arrowsmith wrote: John O'Hagan resea...@johnohagan.com wrote: I can see that it's tantalizing, though, because _somebody_ must know about the assignment; after all, we just executed it! Except we haven't, if we're talking about reporting from the object's __init__

Re: slice iterator?

2009-05-08 Thread John O'Hagan
On Sat, 9 May 2009, Ross wrote: lists. Let's say I had a list a = [1,2,3,4,5,6,7,8,9,10,11,12] and I wanted to split it into groups of 2 or groups of 3 or 4, etc. Is there a way to do this without explicitly defining new lists? If the above problem were to be split into groups of 3, I've tried

Re: slice iterator?

2009-05-08 Thread John O'Hagan
On Sat, 9 May 2009, John O'Hagan wrote: On Sat, 9 May 2009, Ross wrote: lists. Let's say I had a list a = [1,2,3,4,5,6,7,8,9,10,11,12] and I wanted to split it into groups of 2 or groups of 3 or 4, etc. Is there a way to do this without explicitly defining new lists? If the above problem

Re: Can I get a value's name

2009-05-11 Thread John O'Hagan
On Mon, 11 May 2009, jalanb3 wrote: [...] def replace_line(pattern,replacement): errors = '\n' in pattern and [ 'pattern' ] or [] errors += '\n' in replacement and [ 'replacement' ] or [] values = [ locals()[e] for e in errors ] # etc, etc, and eventually: print

Re: Generating Tones With Python

2009-05-18 Thread John O'Hagan
On Mon, 18 May 2009, Adam Gaskins wrote: I am pretty sure this shouldn't be as hard as I'm making it to be, but how does one go about generating tones of specific frequency, volume, and L/R pan? I've been digging around the internet for info, and found a few examples. One was with gstreamer,

Re: Prepackaged function args

2009-05-18 Thread John O'Hagan
On Mon, 18 May 2009, boblat...@googlemail.com wrote: Hello group, suppose I've got a function f() that takes N parameters, and a list (or tuple) arg[] with N elements that I'd like to pass as parameters. The straightforward function call looks like this: result = f(arg[0], arg[1], ...,

Re: Question about locals()

2009-05-18 Thread John O'Hagan
On Tue, 19 May 2009, Gökhan SEVER wrote: Hello, Could you please explain why locals() allow me to create variables that are not legal in Python syntax. Example: locals()['1abc'] = 55. Calling of 1abc results with a syntax error. Shouldn't it be better to raise an error during the variable

Re: Question about None

2009-06-13 Thread John O'Hagan
On Sat, 13 Jun 2009, John Yeung wrote: On Jun 13, 5:22 pm, Rhodri James rho...@wildebst.demon.co.uk wrote: Such an understanding would be clearly wrong in the context in which we were talking (and denotational semantics is a branch of category theory, which is not specific to computer

Recursive generator for combinations of a multiset?

2013-11-20 Thread John O'Hagan
Short story: the subject says it all, so if you have an answer already, fire away. Below is the long story of what I'm using it for, and why I think it needs to be recursive. It may even be of more general interest in terms of filtering the results of generators. I'm playing with an

Re: Recursive generator for combinations of a multiset?

2013-11-21 Thread John O'Hagan
On Thu, 21 Nov 2013 11:42:49 + Oscar Benjamin oscar.j.benja...@gmail.com wrote: On 21 November 2013 06:46, John O'Hagan resea...@johnohagan.com wrote: I found a verbal description of such an algorithm and came up with this: def multicombs(it, r): result = it[:r] yield

Re: Recursive generator for combinations of a multiset?

2013-11-22 Thread John O'Hagan
On Thu, 21 Nov 2013 12:59:26 -0800 Dan Stromberg drsali...@gmail.com wrote: On Wed, Nov 20, 2013 at 10:46 PM, John O'Hagan resea...@johnohagan.comwrote: Short story: the subject says it all, so if you have an answer already, fire away. Below is the long story of what I'm using

Re: Recursive generator for combinations of a multiset?

2013-11-22 Thread John O'Hagan
On Thu, 21 Nov 2013 18:14:41 -0800 (PST) James hslee...@yahoo.com wrote: On Thursday, November 21, 2013 5:01:15 AM UTC-8, John O'Hagan wrote: [...] On 21 November 2013 06:46, John O'Hagan wrote: [...] def multicombs(it, r): result = it[:r] yield

Re: Recursive generator for combinations of a multiset?

2013-11-23 Thread John O'Hagan
On Sat, 23 Nov 2013 04:23:42 + MRAB pyt...@mrabarnett.plus.com wrote: On 23/11/2013 00:58, John O'Hagan wrote: On Thu, 21 Nov 2013 12:59:26 -0800 Dan Stromberg drsali...@gmail.com wrote: On Wed, Nov 20, 2013 at 10:46 PM, John O'Hagan resea...@johnohagan.comwrote: Short

Re: Recursive generator for combinations of a multiset?

2013-11-23 Thread John O'Hagan
On Fri, 22 Nov 2013 22:33:29 -0800 Dan Stromberg drsali...@gmail.com wrote: On Fri, Nov 22, 2013 at 4:58 PM, John O'Hagan resea...@johnohagan.comwrote: On Thu, 21 Nov 2013 12:59:26 -0800 Dan Stromberg drsali...@gmail.com wrote: On Wed, Nov 20, 2013 at 10:46 PM, John O'Hagan resea

Re: Recursive generator for combinations of a multiset?

2013-11-25 Thread John O'Hagan
On Mon, 25 Nov 2013 12:15:15 + Oscar Benjamin oscar.j.benja...@gmail.com wrote: On 21 November 2013 13:01, John O'Hagan resea...@johnohagan.com wrote: In my use-case the first argument to multicombs is a tuple of words which may contain duplicates, and it produces all unique

Re: Recursive generator for combinations of a multiset?

2013-11-27 Thread John O'Hagan
On Tue, 26 Nov 2013 10:33:06 + Oscar Benjamin oscar.j.benja...@gmail.com wrote: On 26 November 2013 06:18, John O'Hagan resea...@johnohagan.com wrote: [...] def _multicombs(prepend, words, r, chkstr): chkstr is the string of remaining availalable characters if r == 0

Update image in same window with, say, PIL

2014-01-04 Thread John O'Hagan
I'm using something like the following to display an image and refresh it in the same window each time the image file is updated: import cv def display(filename): Display scores as they are created cv.NamedWindow(filename) while 1: ... #wait for signal that filename has been

Re: a question about list as an element in a tuple

2014-02-18 Thread John O'Hagan
On Mon, 16 Dec 2013 11:30:13 +0800 liuerfire Wang liuerf...@gmail.com wrote: Just like below: In [1]: a = ([], []) In [2]: a[0].append(1) In [3]: a Out[3]: ([1], []) In [4]: a[0] += [1] --- TypeError

Re: Run once while loop

2012-04-04 Thread John O'Hagan
On Tue, 3 Apr 2012 23:00:22 +0200 Anatoli Hristov toli...@gmail.com wrote: On 03 Apr 2012, at 22:45, Ian Kelly ian.g.ke...@gmail.com wrote: On Tue, Apr 3, 2012 at 2:36 PM, Anatoli Hristov toli...@gmail.com wrote: Hi, I'm trying to do a while loop with condition of time if time is

Re: Python Gotcha's?

2012-04-05 Thread John O'Hagan
On Thu, 05 Apr 2012 10:15:03 -0400 John Posner jjpos...@optimum.net wrote: On 4/4/2012 7:32 PM, Chris Angelico wrote: Don't know if it's what's meant on that page by the += operator, Yes, it is. a=([1],) a[0].append(2) # This is fine [In the following, I use the term name rather

Re: Reading Live Output from a Subprocess

2012-04-06 Thread John O'Hagan
On Fri, 6 Apr 2012 12:21:51 -0700 (PDT) Dubslow buns...@gmail.com wrote: On Friday, April 6, 2012 3:37:10 AM UTC-5, Nobody wrote: In all probability, this is because the child process (pypy) is buffering its stdout, meaning that the data doesn't get passed to the OS until either the

Re: ordering with duck typing in 3.1

2012-04-07 Thread John O'Hagan
On Sat, 7 Apr 2012 05:23:25 -0700 (PDT) andrew cooke and...@acooke.org wrote: hi, please, what am i doing wrong here? the docs say http://docs.python.org/release/3.1.3/library/stdtypes.html#comparisons in general, __lt__() and __eq__() are sufficient, if you want the conventional

Re: Deep merge two dicts?

2012-04-13 Thread John O'Hagan
On Thu, 12 Apr 2012 12:35:21 -0600 Ian Kelly ian.g.ke...@gmail.com wrote: On Thu, Apr 12, 2012 at 11:59 AM, John Nagle na...@animats.com wrote: On 4/12/2012 10:41 AM, Roy Smith wrote: Is there a simple way to deep merge two dicts?  I'm looking for Perl's Hash::Merge

  1   2   >