Re: [Tutor] How to stop a specific thread in Python 2.7?

2024-10-03 Thread Cameron Simpson via Python-list
On 03Oct2024 22:12, Dan Ciprus (dciprus) wrote: I'd be interested too :-). Untested sketch: def make_thread(target, *a, E=None, **kw): ''' Make a new Event E and Thread T, pass `[E,*a]` as the target positional arguments. A shared preexisting Event may be

Re: [Tutor] How to stop a specific thread in Python 2.7?

2024-10-03 Thread Dan Ciprus (dciprus) via Python-list
I'd be interested too :-). On Thu, Sep 26, 2024 at 03:34:05AM GMT, marc nicole via Python-list wrote: Could you show a python code example of this? On Thu, 26 Sept 2024, 03:08 Cameron Simpson, wrote: On 25Sep2024 22:56, marc nicole wrote: >How to create a per-thread event in Python 2.7? E

Re: How to stop a specific thread in Python 2.7?

2024-09-26 Thread Left Right via Python-list
That's one of the "disadvantages" of threads: you cannot safely stop a thread. Of course you could try, but that's never a good idea. The reason for this is that threads share memory. They might be holding locks that, if killed, will never be unlocked. They might (partiall

Re: [Tutor] How to stop a specific thread in Python 2.7?

2024-09-25 Thread marc nicole via Python-list
Could you show a python code example of this? On Thu, 26 Sept 2024, 03:08 Cameron Simpson, wrote: > On 25Sep2024 22:56, marc nicole wrote: > >How to create a per-thread event in Python 2.7? > > Every time you make a Thread, make an Event. Pass it to the thread > worker function and keep it to

Re: How to stop a specific thread in Python 2.7?

2024-09-25 Thread Cameron Simpson via Python-list
On 25Sep2024 22:56, marc nicole wrote: How to create a per-thread event in Python 2.7? Every time you make a Thread, make an Event. Pass it to the thread worker function and keep it to hand for your use outside the thread. -- https://mail.python.org/mailman/listinfo/python-list

Re: How to stop a specific thread in Python 2.7?

2024-09-25 Thread marc nicole via Python-list
How to create a per-thread event in Python 2.7? On Wed, 25 Sept 2024, 22:47 Cameron Simpson via Python-list, < python-list@python.org> wrote: > On 25Sep2024 19:24, marc nicole wrote: > >I want to know how to kill a specific running thread (say by its id) > > > >for now I run and kill a thread li

Re: How to stop a specific thread in Python 2.7?

2024-09-25 Thread Cameron Simpson via Python-list
On 25Sep2024 19:24, marc nicole wrote: I want to know how to kill a specific running thread (say by its id) for now I run and kill a thread like the following: # start thread thread1 = threading.Thread(target= self.some_func(), args=( ...,), ) thread1.start() # kill the thread event_thread1 = t

How to stop a specific thread in Python 2.7?

2024-09-25 Thread marc nicole via Python-list
Hello guys, I want to know how to kill a specific running thread (say by its id) for now I run and kill a thread like the following: # start thread thread1 = threading.Thread(target= self.some_func(), args=( ...,), ) thread1.start() # kill the thread event_thread1 = threading.Event() event_thread

RE: XXX XXX should stop sending me rude email messages.

2023-02-27 Thread avi.e.gross
rated. And I mean especially in this case where we have no idea what "he" was writing but it was a private message not intended for the group. Just kidding BTW. But since YOU are Michael Torrie, I guess you can broadcast a request to stop mailing yourself if that pleases. I will just no lo

Re: Rob Cliffe should stop sending me rude email messages.

2023-02-27 Thread Michael Torrie
On 2/27/23 09:17, Grant Edwards wrote: > On 2023-02-27, Michael Torrie wrote: > >> I've been putting off sending this message for days, but the list noise >> level is now to the point that it has to be said. > > Ah, I've finially realized why some of those threads have seemed so > disjointed to

Re: Rob Cliffe should stop sending me rude email messages.

2023-02-27 Thread Grant Edwards
On 2023-02-27, Michael Torrie wrote: > I've been putting off sending this message for days, but the list noise > level is now to the point that it has to be said. Ah, I've finially realized why some of those threads have seemed so disjointed to me. Years ago, I plonked all posts which are (like

Re: Rob Cliffe should stop sending me rude email messages.

2023-02-27 Thread Michael Torrie
n Python into LISP! :) Do you understand why your posts have been causing frustration? This is an existing community that you've chosen to join. Many of the people you've insulted here, including dn have been participating and helpfully contributing to this list for many years. Please s

Re: Rob Cliffe should stop sending me rude email messages.

2023-02-26 Thread Larry Martell
On Sun, Feb 26, 2023 at 3:49 PM Hen Hanna wrote: > > Rob Cliffe should stop sending me rude email messages. You should stop spamming this lists with with meaningless posts. -- https://mail.python.org/mailman/listinfo/python-list

Re: Rob Cliffe should stop sending me rude email messages.

2023-02-26 Thread Hen Hanna
didn't get through, apparently) were among the few that were relevant. On Sunday, February 26, 2023 at 10:10:09 AM UTC-8, Hen Hanna wrote: > Rob Cliffe should stop sending me rude email messages. > > > At the very least, Rob Cliffe should s

Rob Cliffe should stop sending me rude email messages.

2023-02-26 Thread Hen Hanna
Rob Cliffe should stop sending me rude email messages. At the very least, Rob Cliffe should stop sending me ANY email messages, if he doesn't intend to an email i've sent him. -- https://mail.python.org/mailman/listinfo/python-list

Re: Python script seems to stop running when handling very large dataset

2021-10-30 Thread Shaozhong SHI
On Saturday, 30 October 2021, Dieter Maurer wrote: > Shaozhong SHI wrote at 2021-10-29 23:42 +0100: > >Python script works well, but seems to stop running at a certain point > when > >handling very large dataset. > > > >Can anyone shed light on this? > > Som

Re: Python script seems to stop running when handling very large dataset

2021-10-30 Thread Dieter Maurer
Shaozhong SHI wrote at 2021-10-29 23:42 +0100: >Python script works well, but seems to stop running at a certain point when >handling very large dataset. > >Can anyone shed light on this? Some algorithms have non linear runtime. For example, it is quite easy to write code with quadr

Re: Python script seems to stop running when handling very large dataset

2021-10-29 Thread Grant Edwards
On 2021-10-29, Shaozhong SHI wrote: > Python script works well, but seems to stop running at a certain point when > handling very large dataset. > > Can anyone shed light on this? No. Nobody can help you with the amount of information you have provided. -- Grant -- https://mai

Re: Python script seems to stop running when handling very large dataset

2021-10-29 Thread Paul Bryan
) to see how much memory is consumed? On Fri, 2021-10-29 at 23:42 +0100, Shaozhong SHI wrote: > Python script works well, but seems to stop running at a certain > point when > handling very large dataset. > > Can anyone shed light on this? > > Regards, David -- https://ma

Re: Python script seems to stop running when handling very large dataset

2021-10-29 Thread Dan Stromberg
On Fri, Oct 29, 2021 at 4:04 PM dn via Python-list wrote: > On 30/10/2021 11.42, Shaozhong SHI wrote: > > Python script works well, but seems to stop running at a certain point > when > > handling very large dataset. > > > > Can anyone shed light on this? > >

Re: Python script seems to stop running when handling very large dataset

2021-10-29 Thread dn via Python-list
On 30/10/2021 11.42, Shaozhong SHI wrote: > Python script works well, but seems to stop running at a certain point when > handling very large dataset. > > Can anyone shed light on this? Storage space? Taking time to load/format/process data-set? -- Regards, =dn -- https://mai

Python script seems to stop running when handling very large dataset

2021-10-29 Thread Shaozhong SHI
Python script works well, but seems to stop running at a certain point when handling very large dataset. Can anyone shed light on this? Regards, David -- https://mail.python.org/mailman/listinfo/python-list

Re: How do I get datetime to stop showing seconds?

2020-10-16 Thread Cameron Simpson
On 16Oct2020 22:07, Albert-Jan Roskam wrote: > I was using datetime.now().isoformat('T', 'seconds') > Not 100% sure, but the strings seemed to be 2hrs off. Could it be that > this Linux server was using the wrong time zone? Maybe. This is why timezones are such a nightmare, and programmes

Re: How do I get datetime to stop showing seconds?

2020-10-16 Thread sjeik_appie
I get datetime to stop showing seconds? > > On 2020-10-16 9:42 AM, Steve wrote: >> d2 =  datetime.datetime.now() #Time Right now >>  I was using datetime.now().isoformat('T', 'seconds') Not 100% sure, but the strings seemed to be 2

Re: How do I get datetime to stop showing seconds?

2020-10-16 Thread Cousin Stanley
Steve wrote: > d2 = datetime.datetime.now() #Time Right now > > Show this: 2020-10-16 02:53 > and not this: 2020-10-16 02:53:48.585865 > > > == > Footnote: > If you double major in psychology and reverse psychology, to they cancel > e

Re: How do I get datetime to stop showing seconds?

2020-10-16 Thread Eryk Sun
On 10/16/20, Steve wrote: > -Original Message- > From: Python-list On > Behalf Of Frank Millman > Sent: Friday, October 16, 2020 4:34 AM > To: python-list@python.org > Subject: Re: How do I get datetime to stop showing seconds? > > On 2020-10-16 9:4

RE: How do I get datetime to stop showing seconds?

2020-10-16 Thread Steve
Right on target, Many Thanks FootNote: If money does not grow on trees, then why do banks have branches? -Original Message- From: Python-list On Behalf Of Frank Millman Sent: Friday, October 16, 2020 4:34 AM To: python-list@python.org Subject: Re: How do I get datetime to stop

Re: How do I get datetime to stop showing seconds?

2020-10-16 Thread Marco Sulla
Another way is: '{:%Y-%m-%d %H:%M}'.format(d2) -- https://mail.python.org/mailman/listinfo/python-list

Re: How do I get datetime to stop showing seconds?

2020-10-16 Thread Frank Millman
On 2020-10-16 9:42 AM, Steve wrote: d2 = datetime.datetime.now() #Time Right now Show this: 2020-10-16 02:53 and not this: 2020-10-16 02:53:48.585865 >>> >>> str(d2) '2020-10-16 10:29:38.423371' >>> >>> d2.strftime('%Y-%m-%d %H:%M') '2020-10-16 10:29' >>> Frank Millman -- https://mail.pyt

How do I get datetime to stop showing seconds?

2020-10-16 Thread Steve
d2 = datetime.datetime.now() #Time Right now Show this: 2020-10-16 02:53 and not this: 2020-10-16 02:53:48.585865 == Footnote: If you double major in psychology and reverse psychology, to they cancel each other out? -- -- https://m

Re: How can i stop this Infinite While Loop - Python

2019-11-01 Thread DL Neil via Python-list
9 12:55 AM, ferzan saglam wrote: I have tried many ways to stop the infinite loop but my program doesn't seem to stop after 10 items! It keeps going...!) --- total = 0 while True: print('Cost of item') item = input() if item != -1: total += int(

Re: How can i stop this Infinite While Loop - Python

2019-10-30 Thread Peter Otten
ferzan saglam wrote: > On Wednesday, October 30, 2019 at 2:19:32 PM UTC, Matheus Saraiva wrote: >> rounds = 0 >> while rounds <= 10: ... > Thanks, it Works superbly. > To get the limit of 10 i wanted, i had to make a slight change: > while rounds <= 9 . That's the (in)famous "off by one"

Re: How can i stop this Infinite While Loop - Python

2019-10-30 Thread ferzan saglam
> > total += int(item) > > else: > > break > > > > print(total) > The program does not stop because its code does not contain any deals > that make the loop stop after 10 rounds. You can simply implement a > counter that counts the number of times the loo

Re: How can i stop this Infinite While Loop - Python

2019-10-30 Thread Irv Kalb
> On Oct 30, 2019, at 4:55 AM, ferzan saglam wrote: > > I have tried many ways to stop the infinite loop but my program doesn't seem > to stop after 10 items! It keeps going...!) > > --- > total = 0

Re: How can i stop this Infinite While Loop - Python

2019-10-30 Thread Gunnar Þór Magnússon
> item = input() > if item != -1: If you try this in the REPL, you'll see that 'item' is a string. You're trying to compare it to an integer, which will always fail. The cheapest way to fix this is probably: if item != '-1': Best, G -- https://

Re: How can i stop this Infinite While Loop - Python

2019-10-30 Thread Matheus Saraiva
m 30/10/2019 08:55, ferzan saglam escreveu: total = 0 while True: print('Cost of item') item = input() if item != -1: total += int(item) else: break print(total) The program does not stop because its code does not contain any deals that make the loop sto

Re: How can i stop this Infinite While Loop - Python

2019-10-30 Thread Eko palypse
you compare against an integer -> item != -1 This total += int(item) should be raised by one as you don't know what item actually is, it might be a text Eren Am Mi., 30. Okt. 2019 um 13:01 Uhr schrieb ferzan saglam < ferzan...@gmail.com>: > I have tried many ways to stop the

How can i stop this Infinite While Loop - Python

2019-10-30 Thread ferzan saglam
I have tried many ways to stop the infinite loop but my program doesn't seem to stop after 10 items! It keeps going...!) --- total = 0 while True: print('Co

Re: bottledaemon stop/start doesn't work if killed elsewhere

2018-11-20 Thread Adam Funk
stuff in a database. > >> I have a cron job to call 'stop' and 'start' on it daily, just in case > >> of problems. > >> > >> Occasionally the oom-killer runs overnight and kills the process using > >> bottledaemon; when this happens (

Re: bottledaemon stop/start doesn't work if killed elsewhere

2018-11-19 Thread Adam Funk
On 2018-11-19, Dennis Lee Bieber wrote: > On Sun, 18 Nov 2018 15:33:47 -0600, Dan Sommers ><2qdxy4rzwzuui...@potatochowder.com> declaimed the following: > >> >>What if the oom-killer kills the watchdog? >> > > Then you have TWO processes with out-of-control memory growth. > > The out-o

Re: bottledaemon stop/start doesn't work if killed elsewhere

2018-11-18 Thread Dan Sommers
On 11/18/18 1:21 PM, MRAB wrote:> On 2018-11-18 17:50, Adam Funk wrote: >> Hi, >> >> I'm using bottledaemon to run a little REST service on a Pi that takes >> input from other machines on the LAN and stores stuff in a database. >> I have a cron job to call &

Re: bottledaemon stop/start doesn't work if killed elsewhere

2018-11-18 Thread MRAB
On 2018-11-18 17:50, Adam Funk wrote: Hi, I'm using bottledaemon to run a little REST service on a Pi that takes input from other machines on the LAN and stores stuff in a database. I have a cron job to call 'stop' and 'start' on it daily, just in case of problems. Oc

bottledaemon stop/start doesn't work if killed elsewhere

2018-11-18 Thread Adam Funk
Hi, I'm using bottledaemon to run a little REST service on a Pi that takes input from other machines on the LAN and stores stuff in a database. I have a cron job to call 'stop' and 'start' on it daily, just in case of problems. Occasionally the oom-killer runs overni

Re: logging from time critical tasks -- QueueListener().stop() takes the whole CPU

2018-07-16 Thread Cameron Simpson
On 16Jul2018 08:33, Thomas Jollans wrote: On 16/07/18 08:24, Gerlando Falauto wrote: On Monday, July 16, 2018 at 8:13:46 AM UTC+2, Thomas Jollans wrote: On 16/07/18 07:39, Gerlando Falauto wrote: On Monday, July 16, 2018 at 6:56:19 AM UTC+2, dieter wrote: ... Why is the main thread taking up

Re: logging from time critical tasks -- QueueListener().stop() takes the whole CPU

2018-07-15 Thread Thomas Jollans
On 16/07/18 08:24, Gerlando Falauto wrote: > On Monday, July 16, 2018 at 8:13:46 AM UTC+2, Thomas Jollans wrote: >> On 16/07/18 07:39, Gerlando Falauto wrote: >>> On Monday, July 16, 2018 at 6:56:19 AM UTC+2, dieter wrote: > ... > Why is the main thread taking up so much CPU? > I believ

Re: logging from time critical tasks -- QueueListener().stop() takes the whole CPU

2018-07-15 Thread Gerlando Falauto
On Monday, July 16, 2018 at 8:13:46 AM UTC+2, Thomas Jollans wrote: > On 16/07/18 07:39, Gerlando Falauto wrote: > > On Monday, July 16, 2018 at 6:56:19 AM UTC+2, dieter wrote: > >>> ... > >>> Why is the main thread taking up so much CPU? > >>> I believe at this point listener.stop() should only be

Re: logging from time critical tasks -- QueueListener().stop() takes the whole CPU

2018-07-15 Thread Thomas Jollans
On 16/07/18 07:39, Gerlando Falauto wrote: > On Monday, July 16, 2018 at 6:56:19 AM UTC+2, dieter wrote: >>> ... >>> Why is the main thread taking up so much CPU? >>> I believe at this point listener.stop() should only be waiting for the >>> helper thread to terminate, which I reckon would be impl

Re: logging from time critical tasks -- QueueListener().stop() takes the whole CPU

2018-07-15 Thread Gerlando Falauto
On Monday, July 16, 2018 at 6:56:19 AM UTC+2, dieter wrote: > > ... > > Why is the main thread taking up so much CPU? > > I believe at this point listener.stop() should only be waiting for the > > helper thread to terminate, which I reckon would be implemented by waiting > > on a semaphore or som

Re: logging from time critical tasks -- QueueListener().stop() takes the whole CPU

2018-07-15 Thread dieter
Gerlando Falauto writes: > ... > Why is the main thread taking up so much CPU? > I believe at this point listener.stop() should only be waiting for the helper > thread to terminate, which I reckon would be implemented by waiting on a > semaphore or something (i.e. iowait i.e. 0% CPU). Maybe, yo

logging from time critical tasks -- QueueListener().stop() takes the whole CPU

2018-07-14 Thread Gerlando Falauto
Hi, I'm adding logging to a time critical task running resource-constrained hardware (Raspberry Pi). I read about the QueueListener/QueueHandler in: https://docs.python.org/3/howto/logging-cookbook.html#dealing-with-handlers-that-block and I'm trying to understand how it really works and what's

in multiprocessing pool map how to stop one process from executing ahead

2018-03-20 Thread Subramanian P V
I am excecting custom commands like shell on multiple linux hosts. and if in one host one of the commands fail. I want that process not to proceed. If the remote command throws an error i am logging it .. but the process goes to next command . but if i terminate the command, the process will t

Re: stop prohibition of comp.lang.python ! D'Oliveiro should wear this as a badge of honour.

2018-01-01 Thread breamoreboy
On Monday, January 1, 2018 at 11:06:30 PM UTC, P. timoriensis wrote: > >> stop prohibition of comp.lang.python ! > >> > >> it is childish to do this prohibition business ! > >> > >> don't you have spam filters ? > > > > The prohib

Re: stop prohibition of comp.lang.python !

2018-01-01 Thread breamoreboy
On Monday, January 1, 2018 at 3:00:19 PM UTC, S. I. wrote: > stop prohibition of comp.lang.python ! > > it is childish to do this prohibition business ! > > don't you have spam filters ? The prohibition part of the subject line is added by Lawrence D'Oliveiro when he

Re: exception should not stop program.

2017-10-07 Thread MRAB
On 2017-10-07 17:38, Prabu T.S. wrote: I would like to continue to second function invocation "checkServiceStatus('AdobeARMservice')" even if the first checkServiceStatus('Tomcat9') has any exception.Please advice.Second function invocation not getting executed if any exception occurs in

Re: exception should not stop program.

2017-10-07 Thread Grant Edwards
On 2017-10-07, Jorge Gimeno wrote: > Catching all exceptions in a try-except block is almost always a bad > idea. Catching it and ignoring it as the OP was doing (or assuming it's some particular exception) certainly is. If you know (or suspect) that stderr isn't going anywhere that it will be

Re: exception should not stop program.

2017-10-07 Thread Jorge Gimeno
Catching all exceptions in a try-except block is almost always a bad idea. You can't tell the difference between an exception that you are looking to handle and an exception that should cause your program to crash and burn (because something is wrong). It's best to catch a specific exception. What

Re: exception should not stop program.

2017-10-07 Thread Prabu T.S.
On Saturday, October 7, 2017 at 12:38:11 PM UTC-4, Prabu T.S. wrote: > I would like to continue to second function invocation > "checkServiceStatus('AdobeARMservice')" even if the first >checkServiceStatus('Tomcat9') has any exception.Please advice.Second > function invocation not getting e

exception should not stop program.

2017-10-07 Thread Prabu T.S.
I would like to continue to second function invocation "checkServiceStatus('AdobeARMservice')" even if the first checkServiceStatus('Tomcat9') has any exception.Please advice.Second function invocation not getting executed if any exception occurs in first.Please advice. import psutil def

Re: stop/start windows services -python command

2017-10-06 Thread Prabu T.S.
t 8:33:02 PM UTC-4, MRAB wrote: > >> >> On 2017-10-05 23:32, Prabu T.S. wrote: > >> >> > On Thursday, October 5, 2017 at 6:16:44 PM UTC-4, Prabu T.S. wrote: > >> >> >> hello all,what is the command to stop and start windows servi

Re: stop/start windows services -python command

2017-10-06 Thread alister via Python-list
On Thu, 05 Oct 2017 17:37:11 -0700, Prabu T.S. wrote: > On Thursday, October 5, 2017 at 8:33:02 PM UTC-4, MRAB wrote: >> On 2017-10-05 23:32, Prabu T.S. wrote: >> > On Thursday, October 5, 2017 at 6:16:44 PM UTC-4, Prabu T.S. wrote: >> >> hello all,what is the com

Re: stop/start windows services -python command

2017-10-06 Thread Paul Moore
>> >> > On Thursday, October 5, 2017 at 6:16:44 PM UTC-4, Prabu T.S. wrote: >> >> >> hello all,what is the command to stop and start windows services ? >> >> >> i can't install win32serviceutil bec am using latest python version. >> >

Re: stop/start windows services -python command

2017-10-05 Thread Prabu T.S.
:44 PM UTC-4, Prabu T.S. wrote: > >> >> hello all,what is the command to stop and start windows services ? > >> >> i can't install win32serviceutil bec am using latest python version. > >> > > >> > Please advice on this > >> > > >

Re: stop/start windows services -python command

2017-10-05 Thread MRAB
On 2017-10-06 01:37, Prabu T.S. wrote: On Thursday, October 5, 2017 at 8:33:02 PM UTC-4, MRAB wrote: On 2017-10-05 23:32, Prabu T.S. wrote: > On Thursday, October 5, 2017 at 6:16:44 PM UTC-4, Prabu T.S. wrote: >> hello all,what is the command to stop and start windows services ? &

Re: stop/start windows services -python command

2017-10-05 Thread Prabu T.S.
On Thursday, October 5, 2017 at 8:33:02 PM UTC-4, MRAB wrote: > On 2017-10-05 23:32, Prabu T.S. wrote: > > On Thursday, October 5, 2017 at 6:16:44 PM UTC-4, Prabu T.S. wrote: > >> hello all,what is the command to stop and start windows services ? > >> i can't insta

Re: stop/start windows services -python command

2017-10-05 Thread MRAB
On 2017-10-05 23:32, Prabu T.S. wrote: On Thursday, October 5, 2017 at 6:16:44 PM UTC-4, Prabu T.S. wrote: hello all,what is the command to stop and start windows services ? i can't install win32serviceutil bec am using latest python version. Please advice on this Ask Google: wi

Re: stop/start windows services -python command

2017-10-05 Thread Prabu T.S.
On Thursday, October 5, 2017 at 6:16:44 PM UTC-4, Prabu T.S. wrote: > hello all,what is the command to stop and start windows services ? > i can't install win32serviceutil bec am using latest python version. Please advice on this -- https://mail.python.org/mailman/listinfo/python-list

stop/start windows services -python command

2017-10-05 Thread prabu . ts
hello all,what is the command to stop and start windows services ? i can't install win32serviceutil bec am using latest python version. -- https://mail.python.org/mailman/listinfo/python-list

Re: Unable to apply stop words in Pandas dataframe

2017-06-26 Thread Miki Tebeka
Can you show us some of the code you tried? On Monday, June 26, 2017 at 10:19:46 AM UTC+3, Bhaskar Dhariyal wrote: > Hi everyone! > > I have a dataset which I want to make model trainable. I ahve been trying to > do some thing for past 2-3 days. > > Actually I wanted to clean 'desc' and 'keywo

Unable to apply stop words in Pandas dataframe

2017-06-26 Thread Bhaskar Dhariyal
Hi everyone! I have a dataset which I want to make model trainable. I ahve been trying to do some thing for past 2-3 days. Actually I wanted to clean 'desc' and 'keywords' column from the dataset. I am using NLTK to vectorize, than remove stopwords & alpha numeric values and do stemming. More

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-09 Thread Peter Otten
remaining values, but the builtin min() will continue. >> >> The solution is a minimum function that allows the user to specify a stop >> value: >> >> >>> from itertools import count, chain >> >>> stopmin(chain(reversed(range(10)), count()), ke

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-08 Thread Antonio Caminero Garcia
inue. > > The solution is a minimum function that allows the user to specify a stop > value: > > >>> from itertools import count, chain > >>> stopmin(chain(reversed(range(10)), count()), key=abs, stop=0) > 0 > > How would you implement stopmin

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-08 Thread Paul Rubin
Jussi Piitulainen writes: > It could still be added as an option, to both takewhile and iter(_, _). That's too messy, it really should be pervasive in iterators. -- https://mail.python.org/mailman/listinfo/python-list

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-08 Thread Paul Rubin
Peter Otten <__pete...@web.de> writes: > return min(take_until(), key=firstitem)[1] Actually, key=abs should work. I realized that after posting. -- https://mail.python.org/mailman/listinfo/python-list

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-08 Thread Jussi Piitulainen
Paul Rubin writes: > I think Python's version of iterators is actually buggy and at least > the first element of the rest of the sequence should be preserved. > There are ways to fake it but they're too messy for something like > this. It should be the default and might have been a good change fo

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-08 Thread Jussi Piitulainen
Paul Rubin writes: > Jussi Piitulainen writes: >> That would return 0 even when there is no 0 in xs at all. > > Doesn't look that way to me: > > >>> minabs([5,3,1,2,4]) > 1 Sorry about that. I honestly meant to say it would return 1 even when there was a single 0 at the very end. Somehow

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-08 Thread Peter Otten
min(z())[1] > > is the same thing but a little bit nicer. Yes, that's another variant of the decorate/undecorate approach combined with Wolfgang's local take_until(). The generalized form that cannot rely on the sequence items being orderable would be firstitem = operator.i

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-08 Thread Paul Rubin
Paul Rubin writes: > seems to work, but is ugly. Maybe there's something better. def minabs2(xs): def z(): for x in xs: yield abs(x), x if x==0: break return min(z())[1] is the same thing but a little bit nicer. -- https://mail.py

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-08 Thread Paul Rubin
Paul Rubin writes: > Doesn't look that way to me: > >>> minabs([5,3,1,2,4]) > 1 There's a different problem though: >>> minabs([1,2,3,0]) 1 I think Python's version of iterators is actually buggy and at least the first element of the rest of the sequence should be preserved. Th

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-08 Thread Paul Rubin
Jussi Piitulainen writes: > That would return 0 even when there is no 0 in xs at all. Doesn't look that way to me: >>> minabs([5,3,1,2,4]) 1 -- https://mail.python.org/mailman/listinfo/python-list

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-07 Thread Jussi Piitulainen
Pablo Lucena writes: > How about using the second usage of builtin iter()? > > In [92]: iter? > Docstring: > iter(iterable) -> iterator > iter(callable, sentinel) -> iterator Nice to learn about that. But it has the same problem as itertools.takewhile: > In [88]: numbers > Out[88]: [1, 9, 8, 11,

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-07 Thread Jussi Piitulainen
Paul Rubin writes: > Jussi Piitulainen writes: >>> Use itertools.takewhile >> How? It consumes the crucial stop element: > > Oh yucch, you're right, it takes it from both sides. How about this: > > from itertools import takewhile, islice > def mina

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-07 Thread Paul Rubin
Jussi Piitulainen writes: >> Use itertools.takewhile > How? It consumes the crucial stop element: Oh yucch, you're right, it takes it from both sides. How about this: from itertools import takewhile, islice def minabs(xs): a = iter(xs) m = min(map(abs,take

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-07 Thread Pablo Lucena
How about using the second usage of builtin iter()? In [92]: iter? Docstring: iter(iterable) -> iterator iter(callable, sentinel) -> iterator Get an iterator from an object. In the first form, the argument must supply its own iterator, or be a sequence. *In the second form, the callable is calle

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-07 Thread Jussi Piitulainen
Rustom Mody writes: > On a Saturday, Jussi Piitulainen wrote: [snip] >> You switched to a simpler operator. Would Haskell notice that >> >>def minabs(x, y): return min(x, y, key = abs) >> >> has a meaningful zero? Surely it has its limits somewhere and then >> the programmer needs to supply

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-07 Thread Rustom Mody
n()? > >> > > >> > Use itertools.takewhile > >> > >> How? It consumes the crucial stop element: > >> > >>it = iter('what?') > >>list(takewhile(str.isalpha, it)) # ==> ['w', 'h', 'a&#

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-07 Thread Peter Otten
tion that allows the user to specify a stop > value: Thanks everyone who contributed to this thread! For those interested here's my collection of stopmin() implementations so far. Remember, there should be one ... *obvious* way to do it (emphasis mine). $ cat stopmin_simple.py

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-07 Thread Peter Otten
ut the builtin min() will continue. >> >> The solution is a minimum function that allows the user to specify a stop >> value: >> >>>>> from itertools import count, chain >>>>> stopmin(chain(reversed(range(10)), count()), key=abs, stop=0) >

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-07 Thread Peter Otten
Paul Rubin wrote: > Peter Otten <__pete...@web.de> writes: >> How would you implement stopmin()? > > Use itertools.takewhile I should have mentioned that I had already run into that -- let's call it -- off-by-one bug. -- https://mail.python.org/mailman/listinfo/python-list

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-07 Thread Peter Otten
) will continue. >> >> The solution is a minimum function that allows the user to specify a stop >> value: >> >>>>> from itertools import count, chain >>>>> stopmin(chain(reversed(range(10)), count()), key=abs, stop=0) >> 0 >> &g

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-07 Thread Peter Otten
inue. >> >> The solution is a minimum function that allows the user to specify a stop >> value: >> >>>>> from itertools import count, chain >>>>> stopmin(chain(reversed(range(10)), count()), key=abs, stop=0) >> 0 >> >> How w

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-07 Thread Steve D'Aprano
On Sat, 7 Jan 2017 07:06 am, Wolfgang Maier wrote: > On 1/6/2017 15:04, Peter Otten wrote: [...] >> How would you implement stopmin()? >> > > How about: > > def stopmin (iterable, key, stop): > def take_until (): > for e in iterable: >

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-07 Thread Jussi Piitulainen
Chris Angelico writes: > On Sat, Jan 7, 2017 at 7:12 PM, Jussi Piitulainen wrote: >> You switched to a simpler operator. Would Haskell notice that >> >>def minabs(x, y): return min(x, y, key = abs) >> >> has a meaningful zero? Surely it has its limits somewhere and then >> the programmer need

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-07 Thread Chris Angelico
On Sat, Jan 7, 2017 at 7:12 PM, Jussi Piitulainen wrote: > You switched to a simpler operator. Would Haskell notice that > >def minabs(x, y): return min(x, y, key = abs) > > has a meaningful zero? Surely it has its limits somewhere and then the > programmer needs to supply the information. If

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-07 Thread Jussi Piitulainen
Rustom Mody writes: > On Saturday, Jussi Piitulainen wrote: >> Paul Rubin writes: >> >> > Peter Otten writes: >> >> How would you implement stopmin()? >> > >> > Use itertools.takewhile >> >> How? It consumes the crucial stop elem

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-07 Thread Steve D'Aprano
t; The solution is a minimum function that allows the user to specify a stop > value: > >>>> from itertools import count, chain >>>> stopmin(chain(reversed(range(10)), count()), key=abs, stop=0) > 0 > > How would you implement stopmin()? That depends on whether

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-06 Thread Rustom Mody
On Saturday, January 7, 2017 at 12:26:04 PM UTC+5:30, Jussi Piitulainen wrote: > Paul Rubin writes: > > > Peter Otten writes: > >> How would you implement stopmin()? > > > > Use itertools.takewhile > > How? It consumes the crucial stop element: > &

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-06 Thread Jussi Piitulainen
Paul Rubin writes: > Peter Otten writes: >> How would you implement stopmin()? > > Use itertools.takewhile How? It consumes the crucial stop element: it = iter('what?') list(takewhile(str.isalpha, it)) # ==> ['w', 'h', 'a', 't

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-06 Thread Paul Rubin
Peter Otten <__pete...@web.de> writes: > How would you implement stopmin()? Use itertools.takewhile -- https://mail.python.org/mailman/listinfo/python-list

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-06 Thread Wolfgang Maier
that allows the user to specify a stop value: from itertools import count, chain stopmin(chain(reversed(range(10)), count()), key=abs, stop=0) 0 How would you implement stopmin()? How about: def stopmin (iterable, key, stop): def take_until (): for e in iterable: yi

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-06 Thread Jussi Piitulainen
tion that allows the user to specify a stop > value: > >>>> from itertools import count, chain >>>> stopmin(chain(reversed(range(10)), count()), key=abs, stop=0) > 0 > > How would you implement stopmin()? Only let min see the data up to, but including, the sto

  1   2   3   4   5   6   >