Re: while expression feature proposal

2012-10-25 Thread Thomas Rachel
Am 25.10.2012 01:39 schrieb Ian Kelly: On Wed, Oct 24, 2012 at 5:08 PM, Paul Rubin wrote: from itertools import dropwhile j = dropwhile(lambda j: j in selected, iter(lambda: int(random() * n), object())) .next() kind of ugly, makes me wish for a few more iterto

Re: [OT] Re: turn list of letters into an array of integers

2012-10-25 Thread Steven D'Aprano
On Thu, 25 Oct 2012 07:47:48 +0200, Peter Otten wrote: > Wasn't there a Monty Python sketch where a man carrying a parrot in a > cage comes into a shop full of stuffed animals and complains: No, I > don't admire the taxidermist for making that parrot look like it were > alive -- that beast bit me!

Re: [OT] Re: turn list of letters into an array of integers

2012-10-25 Thread Peter Otten
Steven D'Aprano wrote: > On Thu, 25 Oct 2012 07:47:48 +0200, Peter Otten wrote: > >> Wasn't there a Monty Python sketch where a man carrying a parrot in a >> cage comes into a shop full of stuffed animals and complains: No, I >> don't admire the taxidermist for making that parrot look like it wer

Re: [OT] Re: turn list of letters into an array of integers

2012-10-25 Thread Mark Lawrence
On 25/10/2012 09:25, Peter Otten wrote: Steven D'Aprano wrote: On Thu, 25 Oct 2012 07:47:48 +0200, Peter Otten wrote: Wasn't there a Monty Python sketch where a man carrying a parrot in a cage comes into a shop full of stuffed animals and complains: No, I don't admire the taxidermist for maki

Re: Fast forward-backward (write-read)

2012-10-25 Thread Virgil Stokes
On 24-Oct-2012 17:11, rusi wrote: On Oct 23, 7:52 pm, Virgil Stokes wrote: I am working with some rather large data files (>100GB) that contain time series data. The data (t_k,y(t_k)), k = 0,1,...,N are stored in ASCII format. I perform various types of processing on these data (e.g. moving med

Re: can we append a list with another list in Python ?

2012-10-25 Thread inshu chauhan
Actually what I wanted to do is : suppose there are 3 lists : like for xample : clist = [] an empty list , alist = [1,2,3], blist = [4,5,6] and the I want the result is clist = [ [1,2,3], [4,5,6] ..] then I want to read all the lists in clist one by one like : for item in clist: print

Re: can we append a list with another list in Python ?

2012-10-25 Thread Dave Angel
On 10/25/2012 05:04 AM, inshu chauhan wrote: > Actually what I wanted to do is : > > suppose there are 3 lists : > > like for xample : > > clist = [] an empty list , alist = [1,2,3], blist = [4,5,6] > > and the I want the result is clist = [ [1,2,3], [4,5,6] ..] > > then I want to read all the list

Re: can we append a list with another list in Python ?

2012-10-25 Thread inshu chauhan
> > clist = alist, blist > This may work i guess becuase i want list within list [ [1,2,3] , [4,5,6]] > > or if the clist initial contents were relevant, perhaps you mean > > > clist += alist, blist > But not this because it will simply concatenate the list like [1,2,3,4,5,6] .. I dont want thi

Re: can we append a list with another list in Python ?

2012-10-25 Thread Dave Angel
On 10/25/2012 05:16 AM, Dave Angel wrote: > On 10/25/2012 05:04 AM, inshu chauhan wrote: >> Actually what I wanted to do is : >> >> suppose there are 3 lists : >> >> like for xample : >> >> clist = [] an empty list , alist = [1,2,3], blist = [4,5,6] >> >> and the I want the result is clist = [ [1,2

Re: can we append a list with another list in Python ?

2012-10-25 Thread Dave Angel
On 10/25/2012 05:21 AM, inshu chauhan wrote: >> >> or if the clist initial contents were relevant, perhaps you mean >> >>> clist += alist, blist >> > > But not this because it will simply concatenate the list like > [1,2,3,4,5,6] .. I dont want this actaully... > >> No, it won't. Try it to see

Re: while expression feature proposal

2012-10-25 Thread Paul Rudin
Paul Rubin writes: > kind of ugly, makes me wish for a few more itertools primitives JOOI, do you have specific primitives in mind? -- http://mail.python.org/mailman/listinfo/python-list

Re: can we append a list with another list in Python ?

2012-10-25 Thread inshu chauhan
>> > >> or if the clist initial contents were relevant, perhaps you mean > >> > >>> clist += alist, blist > >> > > > > But not this because it will simply concatenate the list like > > [1,2,3,4,5,6] .. I dont want this actaully... > > > >> > > No, it won't. Try it to see Ok but it should be cli

Re: can we append a list with another list in Python ?

2012-10-25 Thread David Hutto
On Thu, Oct 25, 2012 at 5:31 AM, Dave Angel wrote: > On 10/25/2012 05:21 AM, inshu chauhan wrote: >>> >>> or if the clist initial contents were relevant, perhaps you mean >>> clist += alist, blist >>> >> >> But not this because it will simply concatenate the list like >> [1,2,3,4,5,6] .. I d

Re: can we append a list with another list in Python ?

2012-10-25 Thread David Hutto
On Thu, Oct 25, 2012 at 5:44 AM, inshu chauhan wrote: > > >> >> >> >> or if the clist initial contents were relevant, perhaps you mean >> >> >> >>> clist += alist, blist >> >> >> > >> > But not this because it will simply concatenate the list like >> > [1,2,3,4,5,6] .. I dont want this actaully..

Re: can we append a list with another list in Python ?

2012-10-25 Thread inshu chauhan
> Is this what you mean: > > >>> list_1 = [i for i in range(0,5)] > >>> list_2 = [i for i in range(5,11)] > >>> for i in list_2: > ... list_1.append(i) > ... > >>> list_1 > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] > > > or would another example help you out more? > No but really sorry this is what I

Re: can we append a list with another list in Python ?

2012-10-25 Thread Dave Angel
On 10/25/2012 05:44 AM, inshu chauhan wrote: >>> or if the clist initial contents were relevant, perhaps you mean > clist += alist, blist >>> >>> But not this because it will simply concatenate the list like >>> [1,2,3,4,5,6] .. I dont want this actaully... >>> >> >> No, it

Re: while expression feature proposal

2012-10-25 Thread Thomas Rachel
Am 25.10.2012 00:26 schrieb Cameron Simpson: If I could write this as: if re_FUNKYPATTERN.match(test_string) as m: do stuff with the results of the match, using "m" then some cascading parse decisions would feel a bit cleaner. Where I current have this: m = re_CONSTRUCT1.match(line

Re: while expression feature proposal

2012-10-25 Thread Thomas Rachel
Am 25.10.2012 06:50 schrieb Terry Reedy: Keep in mind that any new syntax has to be a substantial improvement in some sense or make something new possible. There was no new syntax in 3.2 and very little in 3.3. I would consinder this at least as new substantial than yield_from it as oppo

Re: can we append a list with another list in Python ?

2012-10-25 Thread David Hutto
On Thu, Oct 25, 2012 at 5:51 AM, inshu chauhan wrote: > > >> >> Is this what you mean: >> list_0 = [] list_1 = [i for i in range(0,5)] list_2 = [i for i in range(5,11)] list_0.append(list_1) list_0.append(list_2) >> >>> for i in list_2: >> ... list_1.append(i) >> ... >> >>> list_1 >> [0, 1, 2,

Re: can we append a list with another list in Python ?

2012-10-25 Thread inshu chauhan
Yes Dave ..You are right and my problem is solved now.. Thanx to all... On Thu, Oct 25, 2012 at 11:55 AM, David Hutto wrote: > On Thu, Oct 25, 2012 at 5:51 AM, inshu chauhan > wrote: > > > > > >> > >> Is this what you mean: > >> > list_0 = [] > list_1 = [i for i in range(0,5)] > list_2 = [i for

Re: can we append a list with another list in Python ?

2012-10-25 Thread David Hutto
Also, >>> list_1 = [i for i in range(0,5)] >>> list_2 = [i for i in range(5,11)] >>> list_0 = [list_1,list_2] >>> list_0 [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9, 10]] -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com -- http://mail.python.org/mailman/listinfo/python-list

Re: can we append a list with another list in Python ?

2012-10-25 Thread David Hutto
On Thu, Oct 25, 2012 at 5:58 AM, inshu chauhan wrote: > Yes Dave ..You are right and my problem is solved now.. Thanx to all... > > > On Thu, Oct 25, 2012 at 11:55 AM, David Hutto > wrote: >> >> On Thu, Oct 25, 2012 at 5:51 AM, inshu chauhan >> wrote: >> > >> > >> >> >> >> Is this what you mean

Re: can we append a list with another list in Python ?

2012-10-25 Thread inshu chauhan
On Thu, Oct 25, 2012 at 12:04 PM, David Hutto wrote: > On Thu, Oct 25, 2012 at 5:58 AM, inshu chauhan > wrote: > > Yes Dave ..You are right and my problem is solved now.. Thanx to all... > > > > > > On Thu, Oct 25, 2012 at 11:55 AM, David Hutto > > wrote: > >> > >> On Thu, Oct 25, 2012 at 5:51

SSH Connection with Python

2012-10-25 Thread Schneider
Hi Folkz, how can i create a SSH-Connection with python? I have to send some commands to the remote host and parse their answers. greatz Johannes -- http://mail.python.org/mailman/listinfo/python-list

Re: can we append a list with another list in Python ?

2012-10-25 Thread David Hutto
On Thu, Oct 25, 2012 at 6:12 AM, inshu chauhan wrote: > > > On Thu, Oct 25, 2012 at 12:04 PM, David Hutto > wrote: >> >> On Thu, Oct 25, 2012 at 5:58 AM, inshu chauhan >> wrote: >> > Yes Dave ..You are right and my problem is solved now.. Thanx to all... >> > >> > >> > On Thu, Oct 25, 2012 at 1

Re: can we append a list with another list in Python ?

2012-10-25 Thread inshu chauhan
On Thu, Oct 25, 2012 at 12:17 PM, David Hutto wrote: > On Thu, Oct 25, 2012 at 6:12 AM, inshu chauhan > wrote: > > > > > > On Thu, Oct 25, 2012 at 12:04 PM, David Hutto > > wrote: > >> > >> On Thu, Oct 25, 2012 at 5:58 AM, inshu chauhan > >> wrote: > >> > Yes Dave ..You are right and my problem

Re: SSH Connection with Python

2012-10-25 Thread Laszlo Nagy
On 2012-10-25 12:16, Schneider wrote: Hi Folkz, how can i create a SSH-Connection with python? I have to send some commands to the remote host and parse their answers. greatz Johannes http://www.lag.net/paramiko/ Another solution would be to use subprocess and/or pexpect -- http://mail.pyth

Re: while expression feature proposal

2012-10-25 Thread Thomas Rachel
Am 25.10.2012 09:21 schrieb Thomas Rachel: I think # iterate ad inf., because partial never returns None: i1 = iter(partial(randrange, n), None) # take the next value, make it None for breaking: i2 = (j if j in selected else None for j in i1) # and now, break on None: i3 = iter(lambda: next(i2)

Re: SSH Connection with Python

2012-10-25 Thread Kamlesh Mutha
You can use paramiko module. Very easy to use. On Thu, Oct 25, 2012 at 4:04 PM, Laszlo Nagy wrote: > On 2012-10-25 12:16, Schneider wrote: > >> Hi Folkz, >> how can i create a SSH-Connection with python? I have to send some >> commands to the remote host and parse their answers. >> greatz Joha

Re: while expression feature proposal

2012-10-25 Thread Steven D'Aprano
On Thu, 25 Oct 2012 11:52:31 +0200, Thomas Rachel wrote: > Am 25.10.2012 06:50 schrieb Terry Reedy: > >> Keep in mind that any new syntax has to be a substantial improvement in >> some sense or make something new possible. There was no new syntax in >> 3.2 and very little in 3.3. > > I would con

How to set 250000 baud rate in pyserial ?

2012-10-25 Thread kurabas
I use Arduino 1280 and Arduino 2560 under Fedora 15. 1280 creates ttyUSB0 port and can be set at 250 successfully. 2560 creates ttyACM0 port and can be only set at speeds from list (no 25) in pyserial. How to set 25 to ttyACM0 port?? Need I patch kernel or python? -- http://mail.pyt

Re: while expression feature proposal

2012-10-25 Thread Antoon Pardon
On 25-10-12 06:50, Terry Reedy wrote: > On 10/24/2012 7:19 PM, Evan Driscoll wrote: >> On 10/24/2012 05:26 PM, Cameron Simpson wrote: >>> But I'm still -0 on it, because it supplants the glaringly obvious: >>> >>>m = ... >>> >>> assignment with the far less in your face: >>> >>>possibly-lon

Re: while expression feature proposal

2012-10-25 Thread Thomas Rachel
Am 25.10.2012 12:50 schrieb Steven D'Aprano: Then I think you have misunderstood the purpose of "yield from". Seems so. As I have not yet switched to 3.x, I haven't used it till now. [quote] However, if the subgenerator is to interact properly with the caller in the case of calls to send(),

Question about long-running web scripts

2012-10-25 Thread Gilles
Hello I'd like to check something about running Python web applications. Generally speaking, the reason scripts run faster when called through FastCGI or the mod_* modules, is because the interpreter is already up and running. But when running PHP scripts, this does nothing about fetching the fil

Re: Question about long-running web scripts

2012-10-25 Thread Tim Golden
On 25/10/2012 12:45, Gilles wrote: > I'd like to check something about running Python web applications. > > Generally speaking, the reason scripts run faster when called > through FastCGI or the mod_* modules, is because the interpreter is > already up and running. But when running PHP scripts, th

Re: SSH Connection with Python

2012-10-25 Thread Roy Smith
In article , Schneider wrote: > Hi Folkz, > how can i create a SSH-Connection with python? I have to send some > commands to the remote host and parse their answers. > greatz Johannes At a low level, you want to look at the paramiko library. Built on top of that, and adding hoards of neat fu

Re: Question about long-running web scripts

2012-10-25 Thread Gilles
On Thu, 25 Oct 2012 13:03:14 +0100, Tim Golden wrote: >(Your question is a little confused at the end. I'm choosing to >understand: why can't we just run Python one-shot, like CGI? The likely >alternative meaning is: why can't the incoming request be routed to an >already-running Python program --

Re: simple string format question

2012-10-25 Thread Neil Cerutti
On 2012-10-25, Piet van Oostrum wrote: > Adrien writes: > >> print "{:.3g}".format(2.356) # this rounds up > > But: > print "{:.3g}".format(12.356) > 12.4 print "{:.3g}".format(123.356) > 123 The precision is a decimal number indicating how many digits should be displayed after

Re: Question about long-running web scripts

2012-10-25 Thread David Hutto
On Thu, Oct 25, 2012 at 8:03 AM, Tim Golden wrote: > On 25/10/2012 12:45, Gilles wrote: >> I'd like to check something about running Python web applications. >> >> Generally speaking, the reason scripts run faster when called >> through FastCGI or the mod_* modules, is because the interpreter is >

Re: Question about long-running web scripts

2012-10-25 Thread Tim Golden
On 25/10/2012 13:40, Gilles wrote: > On Thu, 25 Oct 2012 13:03:14 +0100, Tim Golden > wrote: >> (Your question is a little confused at the end. I'm choosing to >> understand: why can't we just run Python one-shot, like CGI? The likely >> alternative meaning is: why can't the incoming request be ro

RE: Fastest web framework

2012-10-25 Thread Andriy Kornatskyy
Web content caching is the most effective type of cache. This way your python handler is not executed to determine a valid response to user, instead one returned from cache. Since the operation is that simple, it should be the maximum possible speed your `real world` application capable to prov

Re: SSH Connection with Python

2012-10-25 Thread Demian Brecht
On 2012-10-25, at 3:16 AM, Schneider wrote: > how can i create a SSH-Connection with python? I have to send some commands > to the remote host and parse their answers. I have yet to use it, but Fabric (http://docs.fabfile.org/en/1.4.3/) should have everything you're looking for. I've heard n

Re: while expression feature proposal

2012-10-25 Thread Grant Edwards
On 2012-10-24, Cameron Simpson wrote: >| I must say I really like the parity of Dan's >| while EXPR as VAR: >| BLOCK >| proposal with the "with" statement. > > Well, it's nice. But usually EXPR will be a boolean. I guess that depends on what sort of programs you write. In my experience,

Re: while expression feature proposal

2012-10-25 Thread Grant Edwards
On 2012-10-25, Terry Reedy wrote: > The op wondered if these proposals have been made before. They have > been, and have been rejected. Some of the discussion has been on > python-ideas list. But go ahead and brainstorm and discuss. > > Keep in mind that any new syntax has to be a substantial i

Re: resume execution after catching with an excepthook?

2012-10-25 Thread andrea crotti
2012/10/25 Steven D'Aprano : > On Wed, 24 Oct 2012 13:51:30 +0100, andrea crotti wrote: > >> So I would like to be able to ask for confirmation when I receive a C-c, >> and continue if the answer is "N/n". > > I don't think there is any way to do this directly. > > Without a try...except block, exe

Re: resume execution after catching with an excepthook?

2012-10-25 Thread Chris Angelico
On Thu, Oct 25, 2012 at 12:15 PM, Steven D'Aprano wrote: > I don't believe that there is any > way to jump back to the line of code that just failed (and why would you, > it will just fail again) There are several reasons to retry something after an exception, mainly if some external state gets c

bit count or bit set && Python3

2012-10-25 Thread Charles Hixson
In Python3 is there any good way to count the number of on bits in an integer (after an & operation)? Alternatively, is there any VERY light-weight implementation of a bit set? I'd prefer to use integers, as I'm probably going to need thousands of these, if the tests work out. But before I can

Re: bit count or bit set && Python3

2012-10-25 Thread MRAB
On 2012-10-25 15:47, Charles Hixson wrote: In Python3 is there any good way to count the number of on bits in an integer (after an & operation)? Alternatively, is there any VERY light-weight implementation of a bit set? I'd prefer to use integers, as I'm probably going to need thousands of these

Re: bit count or bit set && Python3

2012-10-25 Thread Christian Heimes
Am 25.10.2012 16:47, schrieb Charles Hixson: > In Python3 is there any good way to count the number of on bits in an > integer (after an & operation)? Simple, easy, faster than a Python loop but not very elegant: bin(number).count("1") Christian -- http://mail.python.org/mailman/listinfo/

Re: bit count or bit set && Python3

2012-10-25 Thread Chris Angelico
On Fri, Oct 26, 2012 at 2:25 AM, Christian Heimes wrote: > Simple, easy, faster than a Python loop but not very elegant: > >bin(number).count("1") Unlikely to be fast. What you may want is some sort of hybrid loop/lookup approach. Do you know what your highest bit number is going to be? For

Re: resume execution after catching with an excepthook?

2012-10-25 Thread Hans Mulder
On 24/10/12 14:51:30, andrea crotti wrote: > So I would like to be able to ask for confirmation when I receive a C-c, > and continue if the answer is "N/n". > > I'm already using an exception handler set with sys.excepthook, but I > can't make it work with the confirm_exit, because it's going to q

Re: resume execution after catching with an excepthook?

2012-10-25 Thread Steven D'Aprano
On Fri, 26 Oct 2012 01:51:43 +1100, Chris Angelico wrote: > On Thu, Oct 25, 2012 at 12:15 PM, Steven D'Aprano > wrote: >> I don't believe that there is any >> way to jump back to the line of code that just failed (and why would >> you, it will just fail again) > > There are several reasons to re

Re: bit count or bit set && Python3

2012-10-25 Thread Steven D'Aprano
On Fri, 26 Oct 2012 02:31:53 +1100, Chris Angelico wrote: > On Fri, Oct 26, 2012 at 2:25 AM, Christian Heimes > wrote: >> Simple, easy, faster than a Python loop but not very elegant: >> >>bin(number).count("1") > > Unlikely to be fast. Oh I don't know about that. Here's some timing results

Re: resume execution after catching with an excepthook?

2012-10-25 Thread Chris Angelico
On Fri, Oct 26, 2012 at 2:31 AM, Hans Mulder wrote: > This seems to work; I'm not sure how robust it is: > > import signal > > def handler(signum, frame): > while True: > q = raw_input("This will quit the program, are you sure? [y/N]") > if q[:1] in "yY": > raise Ke

Re: bit count or bit set && Python3

2012-10-25 Thread rusi
On Oct 25, 7:56 pm, Charles Hixson wrote: > In Python3 is there any good way to count the number of on bits in an > integer (after an & operation)? > Alternatively, is there any VERY light-weight implementation of a bit > set?  I'd prefer to use integers, as I'm probably going to need > thousands

Re: bit count or bit set && Python3

2012-10-25 Thread rusi
On Oct 25, 8:57 pm, Steven D'Aprano wrote: > On Fri, 26 Oct 2012 02:31:53 +1100, Chris Angelico wrote: > > On Fri, Oct 26, 2012 at 2:25 AM, Christian Heimes > > wrote: > >> Simple, easy, faster than a Python loop but not very elegant: > > >>    bin(number).count("1") > > > Unlikely to be fast. >

Re: bit count or bit set && Python3

2012-10-25 Thread Mark Lawrence
On 25/10/2012 15:47, Charles Hixson wrote: In Python3 is there any good way to count the number of on bits in an integer (after an & operation)? Alternatively, is there any VERY light-weight implementation of a bit set? I'd prefer to use integers, as I'm probably going to need thousands of these

Re: while expression feature proposal

2012-10-25 Thread Thomas Rachel
Am 25.10.2012 16:15 schrieb Grant Edwards: I guess that depends on what sort of programs you write. In my experience, EXPR is usually a read from a file/socket/pipe that returns '' on EOF. If VAR is not '', then you process, then you process it inside the loop. Right. The same as in if regex

Re: bit count or bit set && Python3

2012-10-25 Thread Chris Angelico
On Fri, Oct 26, 2012 at 3:17 AM, rusi wrote: > On Oct 25, 8:57 pm, Steven D'Aprano +comp.lang.pyt...@pearwood.info> wrote: >> py> min(t.repeat(number=1, repeat=7)) >> 0.6819710731506348 >> py> min(t.repeat(number=100, repeat=7)) >> 4.141788959503174 >> >> That makes the "inelegant" solution u

Re: bit count or bit set && Python3

2012-10-25 Thread Dan Stromberg
On Thu, Oct 25, 2012 at 9:24 AM, Mark Lawrence wrote: > On 25/10/2012 15:47, Charles Hixson wrote: > >> In Python3 is there any good way to count the number of on bits in an >> integer (after an & operation)? >> Alternatively, is there any VERY light-weight implementation of a bit >> set? I'd pre

Re: while expression feature proposal

2012-10-25 Thread Ian Kelly
On Thu, Oct 25, 2012 at 1:21 AM, Thomas Rachel wrote: >> j = next(j for j in iter(partial(randrange, n), None) if j not in >> selected) > > > This generator never ends. If it meets a non-matching value, it just skips > it and goes on. next() only returns one value. After it is returned, the gene

Re: bit count or bit set && Python3

2012-10-25 Thread Mark Lawrence
On 25/10/2012 17:29, Chris Angelico wrote: On Fri, Oct 26, 2012 at 3:17 AM, rusi wrote: On Oct 25, 8:57 pm, Steven D'Aprano wrote: py> min(t.repeat(number=1, repeat=7)) 0.6819710731506348 py> min(t.repeat(number=100, repeat=7)) 4.141788959503174 That makes the "inelegant" solution using

Re: bit count or bit set && Python3

2012-10-25 Thread rusi
On Oct 25, 9:30 pm, Chris Angelico wrote: > On Fri, Oct 26, 2012 at 3:17 AM, rusi wrote: > > On Oct 25, 8:57 pm, Steven D'Aprano > +comp.lang.pyt...@pearwood.info> wrote: > >> py> min(t.repeat(number=1, repeat=7)) > >> 0.6819710731506348 > >> py> min(t.repeat(number=100, repeat=7)) > >> 4.14

Re: while expression feature proposal

2012-10-25 Thread Ian Kelly
On Thu, Oct 25, 2012 at 3:52 AM, Thomas Rachel wrote: > Am 25.10.2012 06:50 schrieb Terry Reedy: > > >> Keep in mind that any new syntax has to be a substantial improvement in >> some sense or make something new possible. There was no new syntax in >> 3.2 and very little in 3.3. > > > I would cons

Re: while expression feature proposal

2012-10-25 Thread Ian Kelly
On Thu, Oct 25, 2012 at 10:36 AM, Ian Kelly wrote: > On Thu, Oct 25, 2012 at 1:21 AM, Thomas Rachel > > wrote: >>> j = next(j for j in iter(partial(randrange, n), None) if j not in >>> selected) >> >> >> This generator never ends. If it meets a non-matching value, it just skips >> it and goes on.

Re: SSH Connection with Python

2012-10-25 Thread Peter Pearson
On Thu, 25 Oct 2012 12:16:58 +0200, Schneider wrote: > how can i create a SSH-Connection with python? I have to send some > commands to the remote host and parse their answers. > greatz Johannes I've been using Twisted (twistedmatrix.com). It is especially convenient for the server end. Its or

Re: bit count or bit set && Python3

2012-10-25 Thread Steven D'Aprano
On Thu, 25 Oct 2012 09:17:40 -0700, rusi wrote: > On Oct 25, 8:57 pm, Steven D'Aprano +comp.lang.pyt...@pearwood.info> wrote: >> On Fri, 26 Oct 2012 02:31:53 +1100, Chris Angelico wrote: >> > On Fri, Oct 26, 2012 at 2:25 AM, Christian Heimes >> > wrote: >> >> Simple, easy, faster than a Python l

Re: bit count or bit set && Python3

2012-10-25 Thread Christian Gollwitzer
Am 25.10.12 16:47, schrieb Charles Hixson: In Python3 is there any good way to count the number of on bits in an integer (after an & operation)? Alternatively, is there any VERY light-weight implementation of a bit set? I'd prefer to use integers, as I'm probably going to need thousands of these

Re: bit count or bit set && Python3

2012-10-25 Thread Ian Kelly
On Thu, Oct 25, 2012 at 11:25 AM, Christian Gollwitzer wrote: > There is a very geeky algorithm with only a few integer operations. > > Checkout > http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSet64 > > for a C version. Maybe the same thing is equally fast when ported to Python. It

RE: Appending a list using list obtained from a class

2012-10-25 Thread Prasad, Ramit
Demian Brecht wrote: > On 2012-10-24, at 8:00 AM, inshu chauhan wrote: > > > Yes, a Class method returns a list. I am trying to append this in main() to > > make another list. > > But the list i am getting after appending i showing addresses like this > > '<__main__.Point object at > 0x0254FAB0

Re: bit count or bit set && Python3

2012-10-25 Thread Serhiy Storchaka
Chris Angelico's suggestion: >>> bitcount = bytes(bin(i).count("1") for i in range(256)) >>> t = Timer('sum(number.to_bytes((number.bit_length() + 7) // 8,' ... '"little").translate(bitcount))', ... setup='from __main__ import bitcount; number=2**10001-1') >>> min(t.repeat(number=1, repeat=7)

Re: bit count or bit set && Python3

2012-10-25 Thread Neil Cerutti
On 2012-10-25, Steven D'Aprano wrote: > On Fri, 26 Oct 2012 02:31:53 +1100, Chris Angelico wrote: >> On Fri, Oct 26, 2012 at 2:25 AM, Christian Heimes >> >> wrote: >>> Simple, easy, faster than a Python loop but not very elegant: >>> >>>bin(number).count("1") >> >> Unlikely to be fast. > > O

Re: bit count or bit set && Python3

2012-10-25 Thread Neil Cerutti
On 2012-10-25, Neil Cerutti wrote: > Try defeating the following with arithmetic: > > def is_palindrom(n): >s = str(n) >return s = s[::-1] Sorry for the typos. It should've been: def is_palindrome(n): s = str(n) return s == s[::-1] -- Neil Cerutti -- http://mail.python.org/mailm

Re: while expression feature proposal

2012-10-25 Thread Terry Reedy
On 10/25/2012 6:50 AM, Steven D'Aprano wrote: On Thu, 25 Oct 2012 11:52:31 +0200, Thomas Rachel wrote: Am 25.10.2012 06:50 schrieb Terry Reedy: Keep in mind that any new syntax has to be a substantial improvement in some sense or make something new possible. There was no new syntax in 3.2 and

Re: bit count or bit set && Python3

2012-10-25 Thread Terry Reedy
On 10/25/2012 12:13 PM, rusi wrote: On Oct 25, 7:56 pm, Charles Hixson wrote: In Python3 is there any good way to count the number of on bits in an integer (after an & operation)? Alternatively, is there any VERY light-weight implementation of a bit set? I'd prefer to use integers, as I'm prob

Re: bit count or bit set && Python3

2012-10-25 Thread Ian Kelly
On Thu, Oct 25, 2012 at 2:00 PM, Neil Cerutti wrote: > Yes indeed! Python string operations are fast enough and its > arithmetic slow enough that I no longer assume I can beat a neat > lexicographical solution. Try defeating the following with > arithmetic: > > def is_palindrom(n): >s = str(n)

bit count or bit set && Python3

2012-10-25 Thread Charles Hixson
In Python3 is there any good way to count the number of on bits in an integer (after an & operation)? Alternatively, is there any VERY light-weight implementation of a bit set? I'd prefer to use integers, as I'm probably going to need thousands of these, if the tests work out. But before I can

Re: while expression feature proposal

2012-10-25 Thread Thomas Rachel
Am 25.10.2012 18:36 schrieb Ian Kelly: On Thu, Oct 25, 2012 at 1:21 AM, Thomas Rachel wrote: j = next(j for j in iter(partial(randrange, n), None) if j not in selected) This generator never ends. If it meets a non-matching value, it just skips it and goes on. next() only returns one value.

RE: resume execution after catching with an excepthook?

2012-10-25 Thread Prasad, Ramit
andrea crotti wrote: > 2012/10/25 Steven D'Aprano : > > On Wed, 24 Oct 2012 13:51:30 +0100, andrea crotti wrote: > > [snip] > > Without a try...except block, execution will cease after an exception is > > caught, even when using sys.excepthook. I don't believe that there is any > > way to jump back

Quickie - Regexp for a string not at the beginning of the line

2012-10-25 Thread Rivka Miller
Hello Programmers, I am looking for a regexp for a string not at the beginning of the line. For example, I want to find $hello$ that does not occur at the beginning of the string, ie all $hello$ that exclude ^$hello$. In addition, if you have a more difficult problem along the same lines, I woul

Re: Quickie - Regexp for a string not at the beginning of the line

2012-10-25 Thread Janis Papanagnou
On 25.10.2012 22:53, Rivka Miller wrote: > Hello Programmers, > > I am looking for a regexp for a string not at the beginning of the > line. > > For example, I want to find $hello$ that does not occur at the > beginning of the string, ie all $hello$ that exclude ^$hello$. .hello The dot repr

Re: bit count or bit set && Python3

2012-10-25 Thread Charles Hixson
On 10/25/2012 08:57 AM, Steven D'Aprano wrote: On Fri, 26 Oct 2012 02:31:53 +1100, Chris Angelico wrote: On Fri, Oct 26, 2012 at 2:25 AM, Christian Heimes wrote: Simple, easy, faster than a Python loop but not very elegant: bin(number).count("1") Unlikely to be fast. Oh I don't know abo

Re: How to set 250000 baud rate in pyserial ?

2012-10-25 Thread Grant Edwards
On 2012-10-25, Dennis Lee Bieber wrote: > On Thu, 25 Oct 2012 04:09:56 -0700 (PDT), kura...@gmail.com wrote: > >> I use Arduino 1280 and Arduino 2560 under Fedora 15. 1280 creates >> ttyUSB0 port and can be set at 250 successfully. 2560 creates >> ttyACM0 port and can be only set at speeds fr

Re: Quickie - Regexp for a string not at the beginning of the line

2012-10-25 Thread Zero Piraeus
: On 25 October 2012 16:53, Rivka Miller wrote: > I am looking for a regexp for a string not at the beginning of the > line. There are probably quite a few ways to do this, but '(?>> pattern = re.compile(r"(?>> re.findall(pattern, "this is some text") ['is', 'some', 'text'] -[]z. -- http://ma

bit count or bit set && Python3

2012-10-25 Thread Charles Hixson
In Python3 is there any good way to count the number of on bits in an integer (after an & operation)? Alternatively, is there any VERY light-weight implementation of a bit set? I'd prefer to use integers, as I'm probably going to need thousands of these, if the tests work out. But before I can

RE: turn list of letters into an array of integers

2012-10-25 Thread Prasad, Ramit
David Hutto wrote: > On Wed, Oct 24, 2012 at 1:23 AM, seektime wrote: > > Here's some example code. The input is a list which is a "matrix" of > > letters: > >a b a > >b b a > > > > and I'd like to turn this into a Python array: > > > > 1 2 1 > > 2 2 1 > > > > so 1 replaces a, and

Re: bit count or bit set && Python3

2012-10-25 Thread Mark Lawrence
On 25/10/2012 17:08, Charles Hixson wrote: On 10/25/2012 08:57 AM, Steven D'Aprano wrote: On Fri, 26 Oct 2012 02:31:53 +1100, Chris Angelico wrote: On Fri, Oct 26, 2012 at 2:25 AM, Christian Heimes wrote: Simple, easy, faster than a Python loop but not very elegant: bin(number).count("1"

Re: SSH Connection with Python - Oops

2012-10-25 Thread Peter Pearson
On 25 Oct 2012 16:55:46 GMT, Peter Pearson wrote: > On Thu, 25 Oct 2012 12:16:58 +0200, Schneider wrote: >> how can i create a SSH-Connection with python? I have to send some >> commands to the remote host and parse their answers. >> greatz Johannes > > I've been using Twisted (twistedmatrix.com

Re: bit count or bit set && Python3

2012-10-25 Thread Steven D'Aprano
On Thu, 25 Oct 2012 14:20:00 -0600, Ian Kelly wrote: > On Thu, Oct 25, 2012 at 2:00 PM, Neil Cerutti wrote: >> Yes indeed! Python string operations are fast enough and its arithmetic >> slow enough that I no longer assume I can beat a neat lexicographical >> solution. Try defeating the following

Re: Quickie - Regexp for a string not at the beginning of the line

2012-10-25 Thread Rivka Miller
On Oct 25, 2:27 pm, Danny wrote: > Why you just don't give us the string/input, say a line or two, and what you > want off of it, so we can tell better what to suggest no one has really helped yet. I want to search and modify. I dont wanna be tied to a specific language etc so I just want a re

Re: Quickie - Regexp for a string not at the beginning of the line

2012-10-25 Thread Dave Angel
On 10/25/2012 09:08 PM, Rivka Miller wrote: > On Oct 25, 2:27 pm, Danny wrote: >> Why you just don't give us the string/input, say a line or two, and what you >> want off of it, so we can tell better what to suggest > no one has really helped yet. > > > > first non beginning of the line and I wi

a.index(float('nan')) fails

2012-10-25 Thread mamboknave
>>> a = [float('nan'), 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >>> a [nan, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >>> a.index(float('nan')) Traceback (most recent call last): File "", line 1, in ValueError: list.index(x): x not in list That means, the function .index() cannot detect nan values. It happens

Re: Quickie - Regexp for a string not at the beginning of the line

2012-10-25 Thread Ed Morton
On 10/25/2012 8:08 PM, Rivka Miller wrote: On Oct 25, 2:27 pm, Danny wrote: Why you just don't give us the string/input, say a line or two, and what you want off of it, so we can tell better what to suggest no one has really helped yet. Because there is no solution - there IS no _RE_ that

Re: a.index(float('nan')) fails

2012-10-25 Thread Terry Reedy
On 10/25/2012 9:46 PM, mambokn...@gmail.com wrote: a = [float('nan'), 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] a [nan, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] a.index(float('nan')) Traceback (most recent call last): File "", line 1, in ValueError: list.index(x): x not in list That means, the function

Re: Quickie - Regexp for a string not at the beginning of the line

2012-10-25 Thread MRAB
On 2012-10-26 02:08, Rivka Miller wrote: On Oct 25, 2:27 pm, Danny wrote: Why you just don't give us the string/input, say a line or two, and what you want off of it, so we can tell better what to suggest no one has really helped yet. I want to search and modify. I dont wanna be tied to a

Re: Quickie - Regexp for a string not at the beginning of the line

2012-10-25 Thread Ben Bacarisse
Rivka Miller writes: > On Oct 25, 2:27 pm, Danny wrote: >> Why you just don't give us the string/input, say a line or two, and >> what you want off of it, so we can tell better what to suggest > > no one has really helped yet. Really? I was going to reply but then I saw Janis had given you the

Re: a.index(float('nan')) fails

2012-10-25 Thread Cameron Simpson
On 25Oct2012 18:46, mambokn...@gmail.com wrote: | >>> a = [float('nan'), 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | >>> a | [nan, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | >>> a.index(float('nan')) | Traceback (most recent call last): | File "", line 1, in | ValueError: list.index(x): x not in list | | Tha

Re: a.index(float('nan')) fails

2012-10-25 Thread MRAB
On 2012-10-26 03:04, Terry Reedy wrote: On 10/25/2012 9:46 PM, mambokn...@gmail.com wrote: a = [float('nan'), 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] a [nan, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] a.index(float('nan')) Traceback (most recent call last): File "", line 1, in ValueError: list.index(x):

Re: a.index(float('nan')) fails

2012-10-25 Thread mamboknave
On Thursday, October 25, 2012 7:16:02 PM UTC-7, Cameron Simpson wrote: Of course!! How could I get into that trap?? Thanks to you & to Terry -- http://mail.python.org/mailman/listinfo/python-list

Re: Quickie - Regexp for a string not at the beginning of the line

2012-10-25 Thread Mark Lawrence
On 25/10/2012 21:53, Rivka Miller wrote: Hello Programmers, I am looking for a regexp for a string not at the beginning of the line. Why bother with a silly regex thingy when simple string methods will suffice e.g. 'yourstring'.find('xyz', 1) or 'yourstring'.index('xyz', 1) or 'xyz' in

  1   2   >