Re: pthreads in C++ with embedded Python

2011-06-08 Thread Jason Tackaberry
On 11-06-07 07:29 PM, Tom Brown wrote: Any suggestions will be appreciated. Why are you calling PyEval_ReleaseLock() in the CmdThread constructor? This looks suspicious. Also, I don't see where CmdThread::lock() and CmdThread::unlock() are being invoked in your example. Relics from your

Re: pthreads in C++ with embedded Python

2011-06-08 Thread Jason Tackaberry
On 11-06-08 06:28 PM, Tom Brown wrote: I found that PyEval_ReleaseLock() was necessary to keep the program from hanging. The lock() and unlock() methods were used in a previous attempt to lock/unlock the GIL. I just tried your example code and indeed it segfaults as is, but works fine for me

Re: Beginner needs advice

2011-05-29 Thread Jason Tackaberry
On 11-05-29 04:06 AM, Ian Kelly wrote: I realize you are now asserting that compatibility is a boolean condition, and that totally incompatible is a redundant phrase that you tossed out as a joke. As a casual lurker reading this thread, I believe he is equating completely incompatible with not

Re: to pass self or not to pass self

2010-03-16 Thread Jason Tackaberry
On Tue, 2010-03-16 at 10:04 +0100, Bruno Desthuilliers wrote: Answer here: http://wiki.python.org/moin/FromFunctionToMethod I have a sense I used to know this once upon a time, but the question came to my mind (possibly again) and I couldn't think of an answer: Why not create the bound

Re: problem with variable and function

2010-03-14 Thread Jason Tackaberry
Hi Alex, On Sun, 2010-03-14 at 14:26 -0400, Alex Hall wrote: Reverse it, though: def myFunc(): myOtherVar=myVar myVar={ 1:myFunc } and the function myFunc does not see the dictionary. The code you provided works just fine (as one would expect). If you can provide an example

Re: Text mining in Python

2010-03-10 Thread Jason Tackaberry
On Wed, 2010-03-10 at 19:58 +0100, mk wrote: I need to do the following: [...] Is there some good open source engine out there that would be suitable to the task at hand? Anybody has experience with them? It sounds like a full text search engine might do a bit more than you need, but based on

Re: putchar(8)

2009-10-16 Thread Jason Tackaberry
On Fri, 2009-10-16 at 12:01 -0700, gervaz wrote: Hi all, is there in python the equivalent of the C function int putchar (int c)? I need to print putchar(8). print '\x08' or: print chr(8) -- http://mail.python.org/mailman/listinfo/python-list

Re: Most active coroutine library project?

2009-09-25 Thread Jason Tackaberry
On Fri, 2009-09-25 at 15:42 +, Grant Edwards wrote: You can't call a function that yields control back to the other coroutine(s). By jumping through some hoops you can get the same effect, but it's not very intuitive and it sort of feels wrong that the main routine has to know ahead of

Re: Most active coroutine library project?

2009-09-25 Thread Jason Tackaberry
On Fri, 2009-09-25 at 18:36 +, Grant Edwards wrote: That's not comletely transparently. The routine fetch_google() has to know a priori that s.connect() might want to yield and so has to invoke it with a yield statement. With my implementation, tasks that execute asynchronously (which may

Re: Most active coroutine library project?

2009-09-25 Thread Jason Tackaberry
On Fri, 2009-09-25 at 15:25 -0400, Simon Forman wrote: So Kaa is essentially implementing the trampoline function. Essentially, yeah. It doesn't require (or support, depending on your perspective) a coroutine to explicitly yield the next coroutine to be reentered, but otherwise I'd say it's the

Re: Most active coroutine library project?

2009-09-23 Thread Jason Tackaberry
On Wed, 2009-09-23 at 20:50 +, exar...@twistedmatrix.com wrote: immediately outside the generator. This means that you cannot use enhanced generators to implement an API like this one: def doSomeNetworkStuff(): s = corolib.socket() s.connect(('google.com', 80))

Re: Most active coroutine library project?

2009-09-23 Thread Jason Tackaberry
On Wed, 2009-09-23 at 21:53 +, exar...@twistedmatrix.com wrote: I specifically left out all yield statements in my version, since that's exactly the point here. :) With real coroutines, they're not necessary - coroutine calls look just like any other call. With Python's enhanced

Re: Most active coroutine library project?

2009-09-23 Thread Jason Tackaberry
On Wed, 2009-09-23 at 22:07 +, exar...@twistedmatrix.com wrote: Sure, no value judgement intended, except on the practice of taking words with well established meanings and re-using them for something else ;) I think it's the behaviour that's important, and not the specific syntax needed

Re: Non-deprecated equivalent of rfc822.AddressList

2009-09-21 Thread Jason Tackaberry
On Wed, 2009-09-16 at 14:49 -0400, Jason Tackaberry wrote: Since the rfc822 module was removed in Python 3, and is deprecated in 2.3, I am obviously trying to avoid using it. But I'm having a hard time finding an equivalent to rfc822.AddressList in the email module, which I want to use

Non-deprecated equivalent of rfc822.AddressList

2009-09-16 Thread Jason Tackaberry
Hi, Since the rfc822 module was removed in Python 3, and is deprecated in 2.3, I am obviously trying to avoid using it. But I'm having a hard time finding an equivalent to rfc822.AddressList in the email module, which I want to use to parse a _list_ of addresses: addrlist = 'John Doe

Re: unicode() vs. s.decode()

2009-08-06 Thread Jason Tackaberry
On Thu, 2009-08-06 at 01:31 +, John Machin wrote: Faster by an enormous margin; attributing this to the cost of attribute lookup seems implausible. Ok, fair point. I don't think the time difference fully registered when I composed that message. Testing a global access (LOAD_GLOBAL) versus

Re: intricated functions: how to share a variable

2009-08-05 Thread Jason Tackaberry
On Wed, 2009-08-05 at 12:39 +0200, Diez B. Roggisch wrote: Another often used trick is to have a mutable container-object, like this: def tutu(): a = [2] def toto(): a[0] = 4 toto() When you need a writable bound variable inside a closure, I prefer this idiom:

Re: unicode() vs. s.decode()

2009-08-05 Thread Jason Tackaberry
On Wed, 2009-08-05 at 16:43 +0200, Michael Ströder wrote: These both expressions are equivalent but which is faster or should be used for any reason? u = unicode(s,'utf-8') u = s.decode('utf-8') # looks nicer It is sometimes non-obvious which constructs are faster than others in Python. I

Re: Distinguishing active generators from exhausted ones

2009-07-25 Thread Jason Tackaberry
On Sat, 2009-07-25 at 11:30 -0700, Michal Kwiatkowski wrote: Is there a way to tell if a generator has been exhausted using pure Python code? I've looked at CPython sources and it seems that Upon a cursory look, after a generator 'gen' is exhausted (meaning gen.next() has raised StopIteration),

Re: generator expression works in shell, NameError in script

2009-06-17 Thread Jason Tackaberry
On Wed, 2009-06-17 at 15:38 -0700, Chris Rebert wrote: See what Emile said, but here's a nicer way to code it, IMHO: titles = ['Dr', 'Miss', 'Mr', 'Mrs', 'Ms'] title_choices = zip(range(len(titles)+1), ['']+titles) zip() to the rescue! How about: enumerate([''] + titles) --

Re: NameError function not found

2009-05-29 Thread Jason Tackaberry
On Fri, 2009-05-29 at 15:13 -0400, Cameron Pulsford wrote: def _determinant(m): return m[0][0] * m[1][1] - m[1][0] * m[0][1] Given that this has no self argument, I'm assuming this is not a class method. def cofactor(self): Returns the cofactor of a matrix. Given that this does, I

Re: How to get all named args in a dict?

2009-05-14 Thread Jason Tackaberry
On Thu, 2009-05-14 at 20:15 +, kj wrote: That problem is easily solved: just make x = locals() the first statement in the definition of foo. That doesn't solve the problem. You'd need locals().copy() Cheers, Jason. -- http://mail.python.org/mailman/listinfo/python-list