Re: Tuples and immutability

2014-03-11 Thread Steven D'Aprano
On Tue, 11 Mar 2014 23:25:19 -0400, Terry Reedy wrote: > On 3/11/2014 10:01 PM, Rick Johnson wrote: >> >> On Thursday, February 27, 2014 4:18:01 PM UTC-6, Ian wrote: >>> x += y is meant to be equivalent, except possibly in-place and more >>> efficient, than x = x + y. > > The manual actually says

Re: unittest weirdness

2014-03-11 Thread Terry Reedy
On 3/11/2014 6:13 PM, John Gordon wrote: In Ethan Furman writes: if missing: raise ValueError('invoices %r missing from batch' % missing) It's been a while since I wrote test cases, but I recall using the assert* methods (assertEqual, assertTrue, etc.) instead of ra

Re: Tuples and immutability

2014-03-11 Thread Terry Reedy
On 3/11/2014 10:01 PM, Rick Johnson wrote: On Thursday, February 27, 2014 4:18:01 PM UTC-6, Ian wrote: x += y is meant to be equivalent, except possibly in-place and more efficient, than x = x + y. The manual actually says "An augmented assignment expression like x += 1 can be rewritten as x

Re: beautiful soup get class info

2014-03-11 Thread Christopher Welborn
On 03/06/2014 02:22 PM, teddyb...@gmail.com wrote: I am using beautifulsoup to get the title and date of the website. title is working fine but I am not able to pull the date. Here is the code in the url: October 22, 2011 In Python, I am using the following code: date1 = soup.span.text data=

Re: Tuples and immutability

2014-03-11 Thread Rick Johnson
On Thursday, February 27, 2014 4:18:01 PM UTC-6, Ian wrote: > x += y is meant to be equivalent, except possibly in-place and more > efficient, than x = x + y. In an ideal world, the speed of these two codes should be the same, of course i'm "assuming" that most competent language designers wou

Re: Tuples and immutability

2014-03-11 Thread Chris Angelico
On Wed, Mar 12, 2014 at 1:01 PM, Rick Johnson wrote: > On Thursday, February 27, 2014 4:18:01 PM UTC-6, Ian wrote: >> x += y is meant to be equivalent, except possibly in-place and more >> efficient, than x = x + y. > > In an ideal world, the speed of these two codes should be the same, of course

Re: which async framework?

2014-03-11 Thread Chris Angelico
On Wed, Mar 12, 2014 at 10:18 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> What corner cases are there with threads that you don't have with >> anything else? > > There are numerous. Here's one example: deadlocks due to two threads > taking locks in a different order. The problem crops up nat

Re: Balanced trees

2014-03-11 Thread alex23
On 11/03/2014 8:12 PM, Marko Rauhamaa wrote: Python should let skilled professionals do their work. Thankfully, for the most part, it does. Skilled professionals don't solely rely on the standard library, either. If you know you need a balanced tree, you'll also know where to find an implemen

Re: Balanced trees

2014-03-11 Thread Rhodri James
On Tue, 11 Mar 2014 04:28:25 -, Chris Angelico wrote: On Tue, Mar 11, 2014 at 2:38 PM, Ian Kelly wrote: On Mon, Mar 10, 2014 at 7:45 PM, Chris Angelico wrote: No no, I could make this so much better by using the 80x86 "REP MOVSW" command (or commands, depending on your point of view)

Re: How to create an instance of a python class from C++

2014-03-11 Thread Barry Scott
On 5 Mar 2014, at 00:14, Bill wrote: > Hello: > > I can't figure out how to create an instance > of a python class from 'C++': > Why not use pycxx from http://sourceforge.net/projects/cxx/? This lib does all the heavy lifting for you for both python2 and python3. Has docs and examples. Barry

Re: which async framework?

2014-03-11 Thread Marko Rauhamaa
Chris Angelico : > Yep. Now how is that not a problem when you use some other model, like > an event loop? The standard methods of avoiding deadlocks (like > acquiring locks in strict order) work exactly the same for all models, > and are just as necessary. I was simply saying that if you can wor

Re: which async framework?

2014-03-11 Thread Marko Rauhamaa
Chris Angelico : > What corner cases are there with threads that you don't have with > anything else? There are numerous. Here's one example: deadlocks due to two threads taking locks in a different order. The problem crops up naturally with two intercommunicating classes. It can sometimes be ver

Re: Tuples and immutability

2014-03-11 Thread Ian Kelly
On Tue, Mar 11, 2014 at 10:46 AM, Steven D'Aprano wrote: >> There are a number of possible solutions. One possibility would be to >> copy the Circle as an Ellipse and return the new object instead of >> mutating it. Then you have the situation where, given a mutable object >> x that satisfies isi

Re: unittest weirdness

2014-03-11 Thread Ethan Furman
On 03/11/2014 03:13 PM, John Gordon wrote: Ethan Furman writes: if missing: raise ValueError('invoices %r missing from batch' % missing) It's been a while since I wrote test cases, but I recall using the assert* methods (assertEqual, assertTrue, etc.) instead of raisin

Re: which async framework?

2014-03-11 Thread Chris Angelico
On Wed, Mar 12, 2014 at 9:28 AM, Marko Rauhamaa wrote: > If you can't write your own event loop, you probably can't be trusted > with any multithreaded code, which has much more baffling corner cases. I'm not sure about that. Threads are generally easier to handle, because each one just does some

Re: unittest weirdness

2014-03-11 Thread Ethan Furman
On 03/11/2014 01:58 PM, Ethan Furman wrote: Anybody have any ideas? I suspect the O/S is killing the process. If I manually select the other class to run (which has all successful tests, so no traceback baggage), it runs normally. -- ~Ethan~ -- https://mail.python.org/mailman/listinfo/pyth

Re: which async framework?

2014-03-11 Thread Marko Rauhamaa
Antoine Pitrou : > This is the usual assumption that high-level libraries are made of > useless cruft piled up by careless programmers. But there are actual > reasons why these frameworks have a significant amount of code, and > people who decide to ignore those reasons are simply bound to > reimp

Re: which async framework?

2014-03-11 Thread Marko Rauhamaa
Gregory Ewing : > It's not "epoll function calls" that the coroutine style is intended > to replace, it's complex systems of chained callbacks. They're > supposed to make that kind of logic *easier* to follow. If you haven't > had that experience, it may be because you've only dealt with simple >

Re: unittest weirdness

2014-03-11 Thread John Gordon
In Ethan Furman writes: > if missing: > raise ValueError('invoices %r missing from batch' % missing) It's been a while since I wrote test cases, but I recall using the assert* methods (assertEqual, assertTrue, etc.) instead of raising exceptions. Perhaps that's the issue?

Re: which async framework?

2014-03-11 Thread Gregory Ewing
Sturla Molden wrote: Another thing is that co-routines and "yield from" statements just makes it hard to follow the logic of the program. I still have to convince myself that a library for transforming epoll function calls into co-routines is actually useful. It's not "epoll function calls" tha

Re: Tuples and immutability

2014-03-11 Thread Gregory Ewing
Steven D'Aprano wrote: On Tue, 11 Mar 2014 04:39:39 -0600, Ian Kelly wrote: On Mon, Mar 10, 2014 at 11:03 PM, Gregory Ewing > What's the obvious way to spell in-place set intersection, for example? I would expect it to be &=, That's my point -- once you know the binary operator for an op

unittest weirdness

2014-03-11 Thread Ethan Furman
So I finally got enough data and enough of an understanding to write some unit tests for my code. These aren't the first unit tests I've written, but the behavior I'm getting is baffling. I'm using 2.7.4 and I'm testing some routines which attempt to interpret data from a flat file and create

Re: which async framework?

2014-03-11 Thread Sturla Molden
Antoine Pitrou wrote: > This is the usual assumption that high-level libraries are made of useless > cruft piled up by careless programmers. It often is the case, particularly in network programming. But in this case the programmer is Guido, so it doesn't apply. :) > What irks me with your r

Re: golang OO removal, benefits. over python?

2014-03-11 Thread Ian Kelly
On Mon, Mar 10, 2014 at 2:38 AM, Marko Rauhamaa wrote: >> On the whole though I think that the language is not yet mature enough >> to be able to seriously compete with more established languages like >> Python or Java. > > Also, is there anything seriously lacking in Python, Java and C? > > I was

Re: which async framework?

2014-03-11 Thread Terry Reedy
On 3/11/2014 3:53 AM, Chris Withers wrote: On 10/03/2014 21:57, Terry Reedy wrote: I'd like to be able to serve the rest of the web api using a pyramid wsgi app if possible, and I'd like to be able to write the things that process requests in and validation out in a synchronous fashion, most lik

Re: which async framework?

2014-03-11 Thread Chris Angelico
On Wed, Mar 12, 2014 at 5:43 AM, Antoine Pitrou wrote: > This is the usual assumption that high-level libraries are made of useless > cruft piled up by careless programmers. But there are actual reasons > why these frameworks have a significant amount of code, and people who > decide to ignore tho

Re: which async framework?

2014-03-11 Thread Antoine Pitrou
Sturla Molden gmail.com> writes: > > Antoine Pitrou pitrou.net> wrote: > > > Yes, why use a library when you can rewrite it all yourself? > > This assumes something equivalent to the library will have to be written. > But if it can be replaced with something very minimalistic it is just > bloa

Re: which async framework?

2014-03-11 Thread Sturla Molden
Antoine Pitrou wrote: > Yes, why use a library when you can rewrite it all yourself? This assumes something equivalent to the library will have to be written. But if it can be replaced with something very minimalistic it is just bloat. I would also like to respond that the select module and pywi

Re: querry on queue ( thread safe ) multithreading

2014-03-11 Thread Jim Gibson
In article , Jaiprakash Singh wrote: > hey i am working on scraping a site , so i am using multi-threading concept. > i wrote a code based on queue (thread safe) but still my code block out after > sometime, please help , i have searched a lot but unable to resolve it. > please help i stuck here

Re: which async framework?

2014-03-11 Thread Chris Angelico
On Wed, Mar 12, 2014 at 3:01 AM, Antoine Pitrou wrote: > Yes, why use a library when you can rewrite it all yourself? > Actually, you should probably issue system calls to the kernel directly, > the libc is overrated (as is portability, I suppose). It's a trade-off, of course. I am fluent in over

Re: which async framework?

2014-03-11 Thread jkn
Hi Grant On Tuesday, 11 March 2014 16:52:18 UTC, Grant Edwards wrote: [...] > > And don't bother with device drivers for the network adapters either. > Just map their PCI regions in to user-space and twiddle the reigisters > directly! ;) > > [I do that when testing PCI boards with C code, and

Re: Oddity using sorted with key

2014-03-11 Thread Josh English
On Tuesday, March 11, 2014 9:25:29 AM UTC-7, John Gordon wrote: > > > > > Why do you say that 'key=lambda x: x.name.lower' is the correct form? That > > returns the str.lower() function object, which is a silly thing to sort > > on. Surely you want to sort on the *result* of that function, w

Re: Oddity using sorted with key

2014-03-11 Thread Josh English
A comprehensive and educational answer, Peter. Thank you. Josh -- https://mail.python.org/mailman/listinfo/python-list

Re: which async framework?

2014-03-11 Thread Grant Edwards
On 2014-03-11, Antoine Pitrou wrote: > Sturla Molden gmail.com> writes: >> >> Chris Withers simplistix.co.uk> wrote: >> > Hi All, >> > >> > I see python now has a plethora of async frameworks and I need to try >> > and pick one to use from: >> > >> > - asyncio/tulip >> > - tornado >> > - twi

Re: Tuples and immutability

2014-03-11 Thread Steven D'Aprano
On Tue, 11 Mar 2014 04:39:39 -0600, Ian Kelly wrote: > On Mon, Mar 10, 2014 at 11:03 PM, Gregory Ewing > wrote: >> As far as observable effects are concerned, it's quite clear: mutable >> objects can *always* be updated in-place, and immutable objects can >> *never* be. > > Hm. Consider the circ

Re: Oddity using sorted with key

2014-03-11 Thread Peter Otten
Josh English wrote: > I am running into a strange behavior using the sorted function in Python > print list(sorted(all_the_stuff, key=lambda x: x.name.lower)) > print list(sorted(all_the_stuff, key=lambda x: x.name.lower())) Let's simplify your example some more: >>> items = ["B", "2", "a"] >>>

Re: Oddity using sorted with key

2014-03-11 Thread John Gordon
In <058a4a9e-7893-44ef-97c0-999a3589e...@googlegroups.com> Josh English writes: > print list(sorted(all_the_stuff, key=lambda x: x.name.lower)) > print list(sorted(all_the_stuff, key=lambda x: x.name.lower())) > # END > The output is: > [Thing d, Thing f, Thing 2, Thing a, Thing b, Thing C] >

Re: Oddity using sorted with key

2014-03-11 Thread emile
On 03/11/2014 09:13 AM, Josh English wrote: I am running into a strange behavior using the sorted function in Python 2.7. The key parameter is not behaving as the docs say it does: Here is a snippet of code, simplified from my full program: #begin code class Thing(object): def __init__(se

Re: Oddity using sorted with key

2014-03-11 Thread Chris Kaynor
On Tue, Mar 11, 2014 at 9:13 AM, Josh English wrote: > print list(sorted(all_the_stuff, key=lambda x: x.name.lower)) > In this case, the key being sorted on is the function object x.name.lower, not the result of the call. It might make more sense if you break the lambda out into a separate def s

Re: which async framework?

2014-03-11 Thread Giampaolo Rodola'
On Tue, Mar 11, 2014 at 11:17 AM, Sturla Molden wrote: > Chris Withers wrote: > > Hi All, > > > > I see python now has a plethora of async frameworks and I need to try > > and pick one to use from: > > > > - asyncio/tulip > > - tornado > > - twisted > > Looking at Tornado's examples on the web I

Oddity using sorted with key

2014-03-11 Thread Josh English
I am running into a strange behavior using the sorted function in Python 2.7. The key parameter is not behaving as the docs say it does: Here is a snippet of code, simplified from my full program: #begin code class Thing(object): def __init__(self, name): self.name = name def __

Re: which async framework?

2014-03-11 Thread Antoine Pitrou
Sturla Molden gmail.com> writes: > > Chris Withers simplistix.co.uk> wrote: > > Hi All, > > > > I see python now has a plethora of async frameworks and I need to try > > and pick one to use from: > > > > - asyncio/tulip > > - tornado > > - twisted > > I'd go for using iocp, epoll and kqueue/

Re: which async framework?

2014-03-11 Thread Antoine Pitrou
Chris Withers simplistix.co.uk> writes: > > The protocols are all financial (do we really not have a pure-python FIX > library?!) but none are likely to have existing python implementations. If you are mostly writing protocol implementations (aka parsers and serializers), then you should consid

Re: golang OO removal, benefits. over python?

2014-03-11 Thread Neil Cerutti
On 2014-03-10, flebber wrote: > I was wondering if a better programmer than I could explain if > the removal of OO features in golang really does offer an great > benefit over python. > > An article I was reading ran through a brief overview of golang > in respect of OO features > http://areyoufuc

Re: Closure/method definition question for Python 2.7

2014-03-11 Thread Neil Cerutti
On 2014-03-10, Marko Rauhamaa wrote: > "Brunick, Gerard:(Constellation)" : > >> class Test(object): >> x = 10 >> >> def __init__(self): >> self.y = x >> >> t = Test() >> --- >> >> raises >> >> NameError: global name 'x' is not defined. > > In the snippet, x is neither local to __in

Re: which async framework?

2014-03-11 Thread Oscar Benjamin
On 11 March 2014 11:54, Marko Rauhamaa wrote: > Ian Kelly : > >> eventlet has 115k downloads from PyPI over the last month. gevent has >> 143k. Twisted has 147k. Tornado has 173k. >> >> I'd say that a lot of Python users are already doing non-blocking >> network I/O, in one form or another. > > Th

Re: which async framework?

2014-03-11 Thread Marko Rauhamaa
Ian Kelly : > eventlet has 115k downloads from PyPI over the last month. gevent has > 143k. Twisted has 147k. Tornado has 173k. > > I'd say that a lot of Python users are already doing non-blocking > network I/O, in one form or another. There aren't so many network developers in the world. That m

Re: which async framework?

2014-03-11 Thread Ian Kelly
On Tue, Mar 11, 2014 at 4:58 AM, Marko Rauhamaa wrote: > Sturla Molden : > >> I'd go for using iocp, epoll and kqueue/kevent directly. Why bother to >> learn a framework? You will find epoll and kqueue/kevent in the select >> module and iocp in pywin32. > > You beat me to it. > > However, I'm hopi

Re: which async framework?

2014-03-11 Thread Sturla Molden
Marko Rauhamaa wrote: > Now, I've taken a brief look at the new asyncio and it looks as if it > has everything one would hope for (and then some). You'd still need to > supply the protocol implementations yourself. Tulip (the new async module) is nice. But I am a bit confused as to how it combin

Re: which async framework?

2014-03-11 Thread Marko Rauhamaa
Sturla Molden : > I'd go for using iocp, epoll and kqueue/kevent directly. Why bother to > learn a framework? You will find epoll and kqueue/kevent in the select > module and iocp in pywin32. You beat me to it. However, I'm hoping asyncio will steer the Python faithful away from blocking threads

Re: which async framework?

2014-03-11 Thread Marko Rauhamaa
Sturla Molden : > Looking at Tornado's examples on the web I find this: > > [...] > > (1) This was written by some Java guys. I have written several Python async "frameworks" starting from select.epoll(). It's only a handful of lines of code (plus an AVL tree implementation for timers). Then, I'

Re: which async framework?

2014-03-11 Thread Sturla Molden
Chris Withers wrote: > Hi All, > > I see python now has a plethora of async frameworks and I need to try > and pick one to use from: > > - asyncio/tulip > - tornado > - twisted I'd go for using iocp, epoll and kqueue/kevent directly. Why bother to learn a framework? You will find epoll and kqu

Re: Tuples and immutability

2014-03-11 Thread Ian Kelly
On Mon, Mar 10, 2014 at 11:03 PM, Gregory Ewing wrote: > As far as observable effects are concerned, it's > quite clear: mutable objects can *always* be updated > in-place, and immutable objects can *never* be. Hm. Consider the circle-ellipse problem. Briefly, a circle is-an ellipse, so in an in

Re: which async framework?

2014-03-11 Thread Sturla Molden
Chris Withers wrote: > Hi All, > > I see python now has a plethora of async frameworks and I need to try > and pick one to use from: > > - asyncio/tulip > - tornado > - twisted Looking at Tornado's examples on the web I find this: tornado.ioloop.IOLoop.instance().start() This single line

Re: Balanced trees

2014-03-11 Thread Marko Rauhamaa
Steven D'Aprano : > On Mon, 10 Mar 2014 19:24:07 -0400, Roy Smith wrote: > >> In article <8761nmrnfk@elektro.pacujo.net>, >> Marko Rauhamaa wrote: >> >>> Anyway, this whole debate is rather unnecessary since every developer >>> is supposed to have both weapons in their arsenal. >> >> The p

Re: Balanced trees

2014-03-11 Thread Alister
On Mon, 10 Mar 2014 19:24:07 -0400, Roy Smith wrote: > In article <8761nmrnfk@elektro.pacujo.net>, > Marko Rauhamaa wrote: > >> Anyway, this whole debate is rather unnecessary since every developer >> is supposed to have both weapons in their arsenal. > > The problem with having a choice i

Re: Testing interactive code using raw_input

2014-03-11 Thread Steven D'Aprano
On Mon, 10 Mar 2014 17:57:19 +0100, Peter Otten wrote: > Steven D'Aprano wrote: >> what are my options for *automatically* supplying input to raw_input? > > https://pypi.python.org/pypi/mock > > In Python 3 this is part of the standard library: Nice! Thanks to everyone who responded. --

Re: which async framework?

2014-03-11 Thread Chris Withers
On 10/03/2014 21:57, Terry Reedy wrote: I'd like to be able to serve the rest of the web api using a pyramid wsgi app if possible, and I'd like to be able to write the things that process requests in and validation out in a synchronous fashion, most likely spinning off a thread for each one. If

Re: gdb unable to read python frame information

2014-03-11 Thread dieter
Wesley writes: > Now, I fixed the problem... > > Instead of python2.6.6, for python 2.7 it's OK.. > > Why? gdb does not support python 2.6.6? gdb supports python 2.6.6 as well (it is a C level debugger with very few dependencies on Python). Your reports seem to suggest that your Python 2.6.6 in

Re: gdb unable to read python frame information

2014-03-11 Thread dieter
Wesley writes: > ... > [root@localhost ~]# gdb python > GNU gdb (GDB) Red Hat Enterprise Linux (7.2-60.el6_4.1) > This GDB was configured as "x86_64-redhat-linux-gnu". > Reading symbols from /usr/bin/python...Reading symbols from > /usr/lib/debug/usr/bin/python2.6.debug...done. > done. > (gdb) ru