Re: Look free ID genertion (was: Is there a more efficient threading lock?)

2023-03-02 Thread Dennis Lee Bieber
On Thu, 2 Mar 2023 12:45:50 +1100, Chris Angelico declaimed the following: > >As have all CPUs since; it's the only way to implement locks (push the >locking all the way down to the CPU level). > Xerox Sigma (circa 1970): Modify and Test (byte/halfword/word) Granted, that was a

Re: Look free ID genertion (was: Is there a more efficient threading lock?)

2023-03-01 Thread Jon Ribbens via Python-list
On 2023-03-02, Chris Angelico wrote: > On Thu, 2 Mar 2023 at 08:01, <[email protected]> wrote: >> On 2023-03-01 at 14:35:35 -0500, >> [email protected] wrote: >> > What would have happened if all processors had been required to have >> > some low level instruction that effecti

Re: Look free ID genertion (was: Is there a more efficient threading lock?)

2023-03-01 Thread Chris Angelico
On Thu, 2 Mar 2023 at 13:02, Weatherby,Gerard wrote: > > So I guess we know what would have happened. > Yep. It's not what I was talking about, but it's also a very important concurrency management feature. ChrisA -- https://mail.python.org/mailman/listinfo/python-list

Re: Look free ID genertion (was: Is there a more efficient threading lock?)

2023-03-01 Thread Weatherby,Gerard
So I guess we know what would have happened. Get Outlook for iOS<https://aka.ms/o0ukef> From: Python-list on behalf of Chris Angelico Sent: Wednesday, March 1, 2023 8:45:50 PM To: [email protected] Subject: Re: Look free ID genertion (was: Is there

Re: Look free ID genertion (was: Is there a more efficient threading lock?)

2023-03-01 Thread Chris Angelico
On Thu, 2 Mar 2023 at 08:01, <[email protected]> wrote: > > On 2023-03-01 at 14:35:35 -0500, > [email protected] wrote: > > > What would have happened if all processors had been required to have > > some low level instruction that effectively did something in an atomic > > way

Re: Look free ID genertion (was: Is there a more efficient threading lock?)

2023-03-01 Thread 2QdxY4RzWzUUiLuE
On 2023-03-01 at 14:35:35 -0500, [email protected] wrote: > What would have happened if all processors had been required to have > some low level instruction that effectively did something in an atomic > way that allowed a way for anyone using any language running on that > machine a way to do

Re: Look free ID genertion (was: Is there a more efficient threading lock?)

2023-03-01 Thread Chris Angelico
On Thu, 2 Mar 2023 at 06:37, wrote: > > If a workaround like itertools.count.__next__() is used because it will not > be interrupted as it is implemented in C, then I have to ask if it would > make sense for Python to supply something similar in the standard library > for the sole purpose of a use

RE: Look free ID genertion (was: Is there a more efficient threading lock?)

2023-03-01 Thread avi.e.gross
very directly using the atomic operation directly. -Original Message- From: Python-list On Behalf Of Dieter Maurer Sent: Wednesday, March 1, 2023 1:43 PM To: Chris Angelico Cc: [email protected] Subject: Look free ID genertion (was: Is there a more efficient threading lock?) Chris

Look free ID genertion (was: Is there a more efficient threading lock?)

2023-03-01 Thread Dieter Maurer
Chris Angelico wrote at 2023-3-1 12:58 +1100: > ... > The >atomicity would be more useful in that context as it would give >lock-free ID generation, which doesn't work in Python. I have seen `itertools.count` for that. This works because its `__next__` is implemented in "C" and therefore will not

Re: Is there a more efficient threading lock?

2023-02-28 Thread Chris Angelico
On Wed, 1 Mar 2023 at 10:04, Barry wrote: > > > Though it's still probably not as useful as you might hope. In C, if I > > can do "int id = counter++;" atomically, it would guarantee me a new > > ID that no other thread could ever have. > > C does not have to do that atomically. In fact it is free

Re: Is there a more efficient threading lock?

2023-02-28 Thread Barry
> Though it's still probably not as useful as you might hope. In C, if I > can do "int id = counter++;" atomically, it would guarantee me a new > ID that no other thread could ever have. C does not have to do that atomically. In fact it is free to use lots of instructions to build the int value.

Re: Is there a more efficient threading lock?

2023-02-26 Thread Chris Angelico
On Mon, 27 Feb 2023 at 17:28, Michael Speer wrote: > > https://github.com/python/cpython/commit/4958f5d69dd2bf86866c43491caf72f774ddec97 > > it's a quirk of implementation. the scheduler currently only checks if it > needs to release the gil after the POP_JUMP_IF_FALSE, POP_JUMP_IF_TRUE, > JUMP_AB

Re: Is there a more efficient threading lock?

2023-02-26 Thread Michael Speer
https://stackoverflow.com/questions/69993959/python-threads-difference-for-3-10-and-others https://github.com/python/cpython/commit/4958f5d69dd2bf86866c43491caf72f774ddec97 it's a quirk of implementation. the scheduler currently only checks if it needs to release the gil after the POP_JUMP_IF_FAL

Re: Is there a more efficient threading lock?

2023-02-26 Thread Michael Speer
I wanted to provide an example that your claimed atomicity is simply wrong, but I found there is something different in the 3.10+ cpython implementations. I've tested the code at the bottom of this message using a few docker python images, and it appears there is a difference starting in 3.10.0 p

Re: Is there a more efficient threading lock?

2023-02-26 Thread Chris Angelico
On Mon, 27 Feb 2023 at 10:42, Jon Ribbens via Python-list wrote: > > On 2023-02-26, Chris Angelico wrote: > > On Sun, 26 Feb 2023 at 16:16, Jon Ribbens via Python-list > > wrote: > >> On 2023-02-25, Paul Rubin wrote: > >> > The GIL is an evil thing, but it has been around for so long that most >

Re: Is there a more efficient threading lock?

2023-02-26 Thread Skip Montanaro
> And yet, it appears that *something* changed between Python 2 and Python 3 such that it *is* atomic: I haven't looked, but something to check in the source is opcode prediction. It's possible that after the BINARY_OP executes, opcode prediction jumps straight to the STORE_FAST opcode, avoiding t

Re: Is there a more efficient threading lock?

2023-02-26 Thread Jon Ribbens via Python-list
On 2023-02-26, Chris Angelico wrote: > On Sun, 26 Feb 2023 at 16:16, Jon Ribbens via Python-list > wrote: >> On 2023-02-25, Paul Rubin wrote: >> > The GIL is an evil thing, but it has been around for so long that most >> > of us have gotten used to it, and some user code actually relies on it. >>

Re: Is there a more efficient threading lock?

2023-02-26 Thread Jon Ribbens via Python-list
On 2023-02-26, Barry Scott wrote: > On 25/02/2023 23:45, Jon Ribbens via Python-list wrote: >> I think it is the case that x += 1 is atomic but foo.x += 1 is not. > > No that is not true, and has never been true. > >:>>> def x(a): >:...    a += 1 >:... >:>>> >:>>> dis.dis(x) >  1   0 RESU

Re: Is there a more efficient threading lock?

2023-02-26 Thread Barry Scott
On 25/02/2023 23:45, Jon Ribbens via Python-list wrote: I think it is the case that x += 1 is atomic but foo.x += 1 is not. No that is not true, and has never been true. :>>> def x(a): :...    a += 1 :... :>>> :>>> dis.dis(x)  1   0 RESUME   0  2   2 LOAD_FAST

Re: Is there a more efficient threading lock?

2023-02-25 Thread Chris Angelico
On Sun, 26 Feb 2023 at 16:27, Dennis Lee Bieber wrote: > > On Sat, 25 Feb 2023 15:41:52 -0600, Skip Montanaro > declaimed the following: > > > >concurrent.futures.ThreadPoolExecutor() with the default number of workers ( > >os.cpu_count() * 1.5, or 12 threads on my system) to process each month,

Re: Is there a more efficient threading lock?

2023-02-25 Thread Chris Angelico
On Sun, 26 Feb 2023 at 16:16, Jon Ribbens via Python-list wrote: > > On 2023-02-25, Paul Rubin wrote: > > The GIL is an evil thing, but it has been around for so long that most > > of us have gotten used to it, and some user code actually relies on it. > > For example, with the GIL in place, a st

Re: Is there a more efficient threading lock?

2023-02-25 Thread Dennis Lee Bieber
On Sat, 25 Feb 2023 15:41:52 -0600, Skip Montanaro declaimed the following: >concurrent.futures.ThreadPoolExecutor() with the default number of workers ( >os.cpu_count() * 1.5, or 12 threads on my system) to process each month, so >12 active threads at a time. Given that the process is pretty mu

Re: Is there a more efficient threading lock?

2023-02-25 Thread Jon Ribbens via Python-list
On 2023-02-25, Paul Rubin wrote: > Jon Ribbens writes: >>> 1) you generally want to use RLock rather than Lock >> Why? > > So that a thread that tries to acquire it twice doesn't block itself, > etc. Look at the threading lib docs for more info. Yes, I know what the docs say, I was asking why y

Re: Is there a more efficient threading lock?

2023-02-25 Thread Jon Ribbens via Python-list
On 2023-02-25, Paul Rubin wrote: > Skip Montanaro writes: >> from threading import Lock > > 1) you generally want to use RLock rather than Lock Why? > 2) I have generally felt that using locks at the app level at all is an > antipattern. The main way I've stayed sane in multi-threaded Python >

Re: Is there a more efficient threading lock?

2023-02-25 Thread Barry
Re sqlite and threads. The C API can be compiled to be thread safe from my Reading if the sqlite docs. What I have not checked is how python’s bundled sqlite is compiled. There are claims python’s sqlite is not thread safe. Barry -- https://mail.python.org/mailman/listinfo/python-list

Re: Is there a more efficient threading lock?

2023-02-25 Thread Thomas Passin
On 2/25/2023 4:41 PM, Skip Montanaro wrote: Thanks for the responses. Peter wrote: Which OS is this? MacOS Ventura 13.1, M1 MacBook Pro (eight cores). Thomas wrote: > I'm no expert on locks, but you don't usually want to keep a lock while > some long-running computation goes on.  You wan

Re: Is there a more efficient threading lock?

2023-02-25 Thread Weatherby,Gerard
“I'm no expert on locks, but you don't usually want to keep a lock while some long-running computation goes on. You want the computation to be done by a separate thread, put its results somewhere, and then notify the choreographing thread that the result is ready.” Maybe. There are so many poss

Re: Is there a more efficient threading lock?

2023-02-25 Thread Skip Montanaro
Thanks for the responses. Peter wrote: > Which OS is this? MacOS Ventura 13.1, M1 MacBook Pro (eight cores). Thomas wrote: > I'm no expert on locks, but you don't usually want to keep a lock while > some long-running computation goes on. You want the computation to be > done by a separate thr

Re: Is there a more efficient threading lock?

2023-02-25 Thread Peter J. Holzer
On 2023-02-25 09:52:15 -0600, Skip Montanaro wrote: > BLOB_LOCK = Lock() > > def get_terms(text): > with BLOB_LOCK: > phrases = TextBlob(text, np_extractor=EXTRACTOR).noun_phrases > for phrase in phrases: > yield phrase > > When I monitor the application using py-spy, that

Re: Is there a more efficient threading lock?

2023-02-25 Thread Thomas Passin
On 2/25/2023 10:52 AM, Skip Montanaro wrote: I have a multi-threaded program which calls out to a non-thread-safe library (not mine) in a couple places. I guard against multiple threads executing code there using threading.Lock. The code is straightforward: from threading import Lock # Somethin

Re: Is there a more efficient threading lock?

2023-02-25 Thread Peter J. Holzer
On 2023-02-25 09:52:15 -0600, Skip Montanaro wrote: > I have a multi-threaded program which calls out to a non-thread-safe > library (not mine) in a couple places. I guard against multiple > threads executing code there using threading.Lock. The code is > straightforward: > > from threading import

Is there a more efficient threading lock?

2023-02-25 Thread Skip Montanaro
I have a multi-threaded program which calls out to a non-thread-safe library (not mine) in a couple places. I guard against multiple threads executing code there using threading.Lock. The code is straightforward: from threading import Lock # Something in textblob and/or nltk doesn't play nice wit

Re: A more

2019-11-14 Thread Terry Reedy
On 11/14/2019 10:24 AM, James Lu wrote: Where do I go to find a more complete specification for Python? The Cpython code, the tests, and its actual behavior. I want to learn about common semi-internal language features used by popular libraries, because I am reimplementing Python. The

A more

2019-11-14 Thread James Lu
Where do I go to find a more complete specification for Python? I want to learn about common semi-internal language features used by popular libraries, because I am reimplementing Python. The reference guide says: > While I am trying to be as precise as possible, I chose to use English >

Re: a more precise distance algorithm

2015-05-27 Thread Oscar Benjamin
On 27 May 2015 at 19:00, Brian Blais wrote: > On Mon, May 25, 2015 at 11:11 PM, Steven D'Aprano wrote: >> >> Let's compare three methods. >> >> def naive(a, b): >> return math.sqrt(a**2 + b**2) >> >> def alternate(a, b): >> a, b = min(a, b), max(a, b) >> if a == 0: return b >> if

Re: a more precise distance algorithm

2015-05-27 Thread Brian Blais
On Mon, May 25, 2015 at 11:11 PM, Steven D'Aprano wrote: > > Let's compare three methods. > > def naive(a, b): > return math.sqrt(a**2 + b**2) > > def alternate(a, b): > a, b = min(a, b), max(a, b) > if a == 0: return b > if b == 0: return a > return a * math.sqrt(1 + b**2 /

Re: a more precise distance algorithm

2015-05-27 Thread Robin Becker
A minor point is that if you just need to compare distances you don't need to compute the hypotenuse, its square will do so no subtractions etc etc. -- Robin Becker -- https://mail.python.org/mailman/listinfo/python-list

Re: a more precise distance algorithm

2015-05-26 Thread random832
On Tue, May 26, 2015, at 09:40, [email protected] wrote: > On Mon, May 25, 2015, at 15:21, ravas wrote: > > Is this valid? Does it apply to python? > > Any other thoughts? :D > > The math.hypot function uses the C library's function which should deal > with such concerns internally. There is a

Re: a more precise distance algorithm

2015-05-26 Thread random832
On Mon, May 25, 2015, at 15:21, ravas wrote: > Is this valid? Does it apply to python? > Any other thoughts? :D The math.hypot function uses the C library's function which should deal with such concerns internally. There is a fallback version in case the C library does not have this function, in P

Re: a more precise distance algorithm

2015-05-25 Thread ravas
On Monday, May 25, 2015 at 10:16:02 PM UTC-7, Gary Herron wrote: > It's probably not the square root that's causing the inaccuracies. In > many other cases, and probably here also, it's the summing of two > numbers that have vastly different values that loses precision. A > demonstration: > >

Re: a more precise distance algorithm

2015-05-25 Thread Christian Gollwitzer
Am 26.05.15 um 05:11 schrieb Steven D'Aprano: mismatch after 3 trials naive: 767.3916150255787 alternate: 767.3916150255789 hypot: 767.3916150255787 which shows that: (1) It's not hard to find mismatches; (2) It's not obvious which of the three methods is more accurate. The main problem is

Re: a more precise distance algorithm

2015-05-25 Thread Gary Herron
On 05/25/2015 09:13 PM, ravas wrote: On Monday, May 25, 2015 at 8:11:25 PM UTC-7, Steven D'Aprano wrote: Let's compare three methods. ... which shows that: (1) It's not hard to find mismatches; (2) It's not obvious which of the three methods is more accurate. Thank you; that is very helpful!

Re: a more precise distance algorithm

2015-05-25 Thread ravas
Oh ya... true >_< Thanks :D On Monday, May 25, 2015 at 9:43:47 PM UTC-7, Ian wrote: > > def distance(A, B): > > """ > > A & B are objects with x and y attributes > > :return: the distance between A and B > > """ > > dx = B.x - A.x > > dy = B.y - A.y > > a = min(dx, dy)

Re: a more precise distance algorithm

2015-05-25 Thread Ian Kelly
a^2 + b^2) you will suffer from the lose of half of your > available precision because the square root operation is last. A more > accurate calculation is c = a * sqrt(1 + b^2 / a^2). If a is less than b, you > should swap them and of course handle the special case of a = 0. > "&

Re: a more precise distance algorithm

2015-05-25 Thread ravas
On Monday, May 25, 2015 at 8:11:25 PM UTC-7, Steven D'Aprano wrote: > Let's compare three methods. > ... > which shows that: > > (1) It's not hard to find mismatches; > (2) It's not obvious which of the three methods is more accurate. Thank you; that is very helpful! I'm curious: what about the

Re: a more precise distance algorithm

2015-05-25 Thread Steven D'Aprano
+ b^2) you will suffer from the lose of half of > your available precision because the square root operation is last. A more > accurate calculation is c = a * sqrt(1 + b^2 / a^2). If a is less than b, > you should swap them and of course handle the special case of a = 0. """

Re: a more precise distance algorithm

2015-05-25 Thread ravas
On Monday, May 25, 2015 at 1:27:43 PM UTC-7, Gary Herron wrote: > This is a statement about floating point numeric calculations on a > computer,. As such, it does apply to Python which uses the underlying > hardware for floating point calculations. > > Validity is another matter. Where did yo

Re: a more precise distance algorithm

2015-05-25 Thread ravas
On Monday, May 25, 2015 at 1:27:24 PM UTC-7, Christian Gollwitzer wrote: > Wrong. Just use the built-in function Math.hypot() - it should handle > these cases and also overflow, infinity etc. in the best possible way. > > Apfelkiste:~ chris$ python > Python 2.7.2 (default, Oct 11 2012, 20:14:37)

Re: a more precise distance algorithm

2015-05-25 Thread Christian Gollwitzer
the lose of half of your available precision because the square root operation is last. A more accurate calculation is c = a * sqrt(1 + b^2 / a^2). If a is less than b, you should swap them and of course handle the special case of a = 0. """ Is this valid? Yes. Valid for floating

Re: a more precise distance algorithm

2015-05-25 Thread Gary Herron
the lose of half of your available precision because the square root operation is last. A more accurate calculation is c = a * sqrt(1 + b^2 / a^2). If a is less than b, you should swap them and of course handle the special case of a = 0. """ Is this valid? Does it apply to pyth

Re: a more precise distance algorithm

2015-05-25 Thread felix
the lose of half of your available precision because the square root operation is last. A more accurate calculation is c = a * sqrt(1 + b^2 / a^2). If a is less than b, you should swap them and of course handle the special case of a = 0. """ Is this valid? Does it apply to python? An

a more precise distance algorithm

2015-05-25 Thread ravas
cision because the square root operation is last. A more accurate calculation is c = a * sqrt(1 + b^2 / a^2). If a is less than b, you should swap them and of course handle the special case of a = 0. """ Is this valid? Does it apply to python? Any other thoughts? :D My imagining

Re: Is there a more elegant way to spell this?

2015-01-28 Thread Mario Figueiredo
In article , [email protected] says... > > More accurately (and as acknowledged in that guide), a single underscore > *is* a common name for a ?don't care? name, but is better avoided for > that purpose because it's also commonly used for other purposes. > > In other words: That guide i

Re: Is there a more elegant way to spell this?

2015-01-27 Thread Steven D'Aprano
Mario Figueiredo wrote: > In article <[email protected]>, > [email protected] says... >> (3) _ is also commonly used as a "don't care" variable name: >> >> a, _, b, _ = get_four_items() # but I only care about two of them >> > > According to

Re: Is there a more elegant way to spell this?

2015-01-27 Thread Ben Finney
Mario Figueiredo writes: > In article <[email protected]>, > [email protected] says... > > (3) _ is also commonly used as a "don't care" variable name: > > > > a, _, b, _ = get_four_items() # but I only care about two of them > > > > Accord

Re: Is there a more elegant way to spell this?

2015-01-27 Thread Mario Figueiredo
In article <[email protected]>, [email protected] says... > (3) _ is also commonly used as a "don't care" variable name: > > a, _, b, _ = get_four_items() # but I only care about two of them > According to the following link, it is actually

Re: Is there a more elegant way to spell this?

2015-01-27 Thread Steven D'Aprano
Neal Becker wrote: > Is there a more elegant way to spell this? > > for x in [_ for _ in seq if some_predicate]: Don't use _ as the loop variable here. There are three common conventions for _ and this is none of them: (1) n the interactive interpreter _ is used for the resu

Re: Is there a more elegant way to spell this?

2015-01-27 Thread Emile van Sebille
On 1/27/2015 9:49 AM, Rob Gaddi wrote: Or the somewhat less indenty for x in seq: if not some_predicate: continue do_something_to(x) ... or shorter and equally less indenty for x in seq: if some_predicate: do_something_to(x) -- https://mail.python.org/mailman/listinfo/python

Re: Is there a more elegant way to spell this?

2015-01-27 Thread Neal Becker
Jussi Piitulainen wrote: > Neal Becker writes: > >> Is there a more elegant way to spell this? >> >> for x in [_ for _ in seq if some_predicate]: > > If you mean some_predicate(_), then possibly this. > > for x in filter(some_predicate, seq): >

Re: Is there a more elegant way to spell this?

2015-01-27 Thread random832
On Tue, Jan 27, 2015, at 13:05, Mario Figueiredo wrote: > In article , > [email protected] says... > > > > If you mean literally some_predicate, then perhaps this. > > > > if some_predicate: > >for x in seq: > > handle(x) > > > > Careful. See Chris Warrick answer for the corr

Re: Is there a more elegant way to spell this?

2015-01-27 Thread Mario Figueiredo
In article , [email protected] says... > > If you mean literally some_predicate, then perhaps this. > > if some_predicate: >for x in seq: > handle(x) > Careful. See Chris Warrick answer for the correct position of the 'if' statement. -- https://mail.python.org/mailman/listi

Re: Is there a more elegant way to spell this?

2015-01-27 Thread Rob Gaddi
On Tue, 27 Jan 2015 14:20:10 +0100 Chris Warrick wrote: > On Jan 27, 2015 2:16 PM, "Neal Becker" wrote: > > > > Is there a more elegant way to spell this? > > > > for x in [_ for _ in seq if some_predicate]: > > for x in seq: >

Re: Is there a more elegant way to spell this?

2015-01-27 Thread Jussi Piitulainen
Neal Becker writes: > Jussi Piitulainen wrote: > > Neal Becker writes: > > > >> Is there a more elegant way to spell this? > >> > >> for x in [_ for _ in seq if some_predicate]: > > > > If you mean some_predicate(_), then possi

Re: Is there a more elegant way to spell this?

2015-01-27 Thread Neal Becker
Jussi Piitulainen wrote: > Neal Becker writes: > >> Is there a more elegant way to spell this? >> >> for x in [_ for _ in seq if some_predicate]: > > If you mean some_predicate(_), then possibly this. > > for x in filter(some_predicate, seq): >

Re: Is there a more elegant way to spell this?

2015-01-27 Thread Jussi Piitulainen
Neal Becker writes: > Is there a more elegant way to spell this? > > for x in [_ for _ in seq if some_predicate]: If you mean some_predicate(_), then possibly this. for x in filter(some_predicate, seq): handle(x) If you mean literally some_predicate, then perhaps this. if some_

Re: Is there a more elegant way to spell this?

2015-01-27 Thread Rustom Mody
On Tuesday, January 27, 2015 at 6:45:41 PM UTC+5:30, Neal Becker wrote: > Is there a more elegant way to spell this? > > for x in [_ for _ in seq if some_predicate]: Depends on what follows the ':' In the trivial case all thats outside the comprehension can be dropped: >&

Re: Is there a more elegant way to spell this?

2015-01-27 Thread Jean-Michel Pichavant
- Original Message - > From: "Neal Becker" > To: [email protected] > Sent: Tuesday, 27 January, 2015 2:15:12 PM > Subject: Is there a more elegant way to spell this? > > Is there a more elegant way to spell this? > > for x in [_ for _ in seq if

Re: Is there a more elegant way to spell this?

2015-01-27 Thread Chris Warrick
On Jan 27, 2015 2:16 PM, "Neal Becker" wrote: > > Is there a more elegant way to spell this? > > for x in [_ for _ in seq if some_predicate]: for x in seq: if some_predicate: do_something_to(x) -- Chris Warrick <https://chriswarrick.com/> Sent

Is there a more elegant way to spell this?

2015-01-27 Thread Neal Becker
Is there a more elegant way to spell this? for x in [_ for _ in seq if some_predicate]: -- -- Those who don't understand recursion are doomed to repeat it -- https://mail.python.org/mailman/listinfo/python-list

Re: string processing - some problems whenever I have to parse a more complex string

2014-10-21 Thread Terry Reedy
On 10/21/2014 10:32 AM, CWr wrote: Hello together, currently I have to parse a string in an atomic way. Normally - in this case too - I have a counter variable to keep the current position inside the string. So far, I think this is the most flexible solution to do some lookaround's inside th

Re: string processing - some problems whenever I have to parse a more complex string

2014-10-21 Thread Ned Batchelder
On 10/21/14 10:32 AM, CWr wrote: Is there any implementation like C++ StringPiece class? Or something like the following behavior: >>>s = StringSlice('abcdef') >>>s StringSlice('abcdef') at xxx >>>s[0] 'a' >>>s.chop(1) # chop the first item >>>s[0] # 'b' is the new first item 'b' >>>s[:

string processing - some problems whenever I have to parse a more complex string

2014-10-21 Thread CWr
Hello together, currently I have to parse a string in an atomic way. Normally - in this case too - I have a counter variable to keep the current position inside the string. So far, I think this is the most flexible solution to do some lookaround's inside the string if necessary. Subroutines wi

Re: using urllib on a more complex site

2013-02-24 Thread Adam W.
On Sunday, February 24, 2013 7:27:54 PM UTC-5, Chris Rebert wrote: > On Sunday, February 24, 2013, Adam W. wrote: > I'm trying to write a simple script to scrape > http://www.vudu.com/movies/#tag/99centOfTheDay/99c%20Rental%20of%20the%20day > > > > > in order to send myself an email every day

Re: using urllib on a more complex site

2013-02-24 Thread Adam W.
On Sunday, February 24, 2013 7:30:00 PM UTC-5, Dave Angel wrote: > On 02/24/2013 07:02 PM, Adam W. wrote: > > > I'm trying to write a simple script to scrape > > http://www.vudu.com/movies/#tag/99centOfTheDay/99c%20Rental%20of%20the%20day > > > > > > in order to send myself an email every day o

Re: using urllib on a more complex site

2013-02-24 Thread Dave Angel
On 02/24/2013 07:02 PM, Adam W. wrote: I'm trying to write a simple script to scrape http://www.vudu.com/movies/#tag/99centOfTheDay/99c%20Rental%20of%20the%20day in order to send myself an email every day of the 99c movie of the day. However, using a simple command like (in Python 3.0): urllib

Re: using urllib on a more complex site

2013-02-24 Thread Chris Rebert
On Sunday, February 24, 2013, Adam W. wrote: > I'm trying to write a simple script to scrape > http://www.vudu.com/movies/#tag/99centOfTheDay/99c%20Rental%20of%20the%20day > > in order to send myself an email every day of the 99c movie of the day. > > However, using a simple command like (in Pytho

using urllib on a more complex site

2013-02-24 Thread Adam W.
I'm trying to write a simple script to scrape http://www.vudu.com/movies/#tag/99centOfTheDay/99c%20Rental%20of%20the%20day in order to send myself an email every day of the 99c movie of the day. However, using a simple command like (in Python 3.0): urllib.request.urlopen('http://www.vudu.com/mo

Re: Is there a more elegant way to handle determing fail status?

2013-01-15 Thread Steven D'Aprano
On Tue, 15 Jan 2013 18:24:44 -0500, J wrote: > The problem is that my exit determination looks like this: > > if fail_priority == fail_levels['FAILED_CRITICAL']: > if critical_fails: > return 1 > if fail_priority == fail_levels['FAILED_HIGH']: > if critical_fa

Re: Is there a more elegant way to handle determing fail status?

2013-01-15 Thread Ian Kelly
On Tue, Jan 15, 2013 at 4:24 PM, J wrote: > The exit code determination above works, but it just feels inelegant. > It feels like there's a better way of implementing that, but I can't > come up with one that still honors the fail level properly (e.g. other > solutions will fail on medium, but won

Re: Is there a more elegant way to handle determing fail status?

2013-01-15 Thread Oscar Benjamin
On 15 January 2013 23:24, J wrote: > Ok, so I have a diagnostic tool, written by someone else. That tool > runs a series of small tests defined by the user and can simplified > summary output that can be one of the following: > > FAILED_CRITICAL > FAILED_HIGH > FAILED_MEDIUM > FAILED_LOW > PASSED

Re: Is there a more elegant way to handle determing fail status?

2013-01-15 Thread donarb
On Tuesday, January 15, 2013 3:24:44 PM UTC-8, J wrote: > Ok, so I have a diagnostic tool, written by someone else. That tool > > runs a series of small tests defined by the user and can simplified > > summary output that can be one of the following: > > > > FAILED_CRITICAL > > FAILED_HIGH >

Is there a more elegant way to handle determing fail status?

2013-01-15 Thread J
Ok, so I have a diagnostic tool, written by someone else. That tool runs a series of small tests defined by the user and can simplified summary output that can be one of the following: FAILED_CRITICAL FAILED_HIGH FAILED_MEDIUM FAILED_LOW PASSED I also have a wrapper script I wrote to run these te

Re: json.loads() should return a more specific error

2012-06-27 Thread Terry Reedy
On 6/27/2012 8:45 AM, Roy Smith wrote: Before I go open an enhancement request, what do people think of the idea that json.load() should return something more specific than ValueError? I do not know of any written policy about when to create custom error classes in the stdlib. I know there are

json.loads() should return a more specific error

2012-06-27 Thread Roy Smith
Before I go open an enhancement request, what do people think of the idea that json.load() should return something more specific than ValueError? I've got some code that looks like try: response = requests.get(url) except RequestException as ex: logger.exception(ex)

Re: A more general solution

2010-05-09 Thread Tim Chase
On 05/08/2010 10:33 PM, 3Jane wrote: You could interpret [[1,2,3,4],[5,6,7,8]] as a tree and your task as traversal of its leaves. All solutions before would not work with trees with bigger height. Here is how to traverse such trees recursively: def eventualPrint(x): for v in x: i

A more general solution

2010-05-08 Thread 3Jane
You could interpret [[1,2,3,4],[5,6,7,8]] as a tree and your task as traversal of its leaves. All solutions before would not work with trees with bigger height. Here is how to traverse such trees recursively: def eventualPrint(x): for v in x: if isinstance(v, list): eventualPrint(x)

Re: A more specific query ...

2010-02-26 Thread Gib Bogle
Dennis Lee Bieber wrote: On Sat, 27 Feb 2010 13:00:32 +1300, Gib Bogle declaimed the following in gmane.comp.python.general: The PyQt4 problem results from having copies of the Qt DLLs in directories that are in the PATH, as Doug Bell discovered. In my case I have two programs that use Qt, A

Re: A more specific query ...

2010-02-26 Thread Gib Bogle
The PyQt4 problem results from having copies of the Qt DLLs in directories that are in the PATH, as Doug Bell discovered. In my case I have two programs that use Qt, AMD CodeAnalyst and Matlab. If I rename BOTH these directories I can import the PyQt4 modules. Since this behaviour did not oc

Re: A more specific query ...

2010-02-26 Thread Gib Bogle
The PyQt4 problem results from having copies of the Qt DLLs in directories that are in the PATH, as Doug Bell discovered. In my case I have two programs that use Qt, AMD CodeAnalyst and Matlab. If I rename BOTH these directories I can import the PyQt4 modules. Since this behaviour did not oc

Re: A more specific query ...

2010-02-26 Thread Gib Bogle
The point of my question was that sys.path is clearly not being used in this case. When I start Python sys.path includes D:\python26\lib\site-packages which seems to be the Python default. Using sys.path.append I have tried adding both D:\python26\lib\site-packages\PyQt4 and D:\python26\lib\si

Re: A more specific query ...

2010-02-26 Thread Gib Bogle
Chris Rebert wrote: On Fri, Feb 26, 2010 at 12:45 PM, Gib Bogle wrote: How can I interrogate Python to find out where it is looking to find the PyQt4 DLLs in a Windows installation? import sys print(sys.path) Note this thread: http://www.mail-archive.com/[email protected]/msg20121

Re: A more specific query ...

2010-02-26 Thread Chris Rebert
On Fri, Feb 26, 2010 at 12:45 PM, Gib Bogle wrote: > How can I interrogate Python to find out where it is looking to find the > PyQt4 DLLs in a Windows installation? import sys print(sys.path) Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list

A more specific query ...

2010-02-26 Thread Gib Bogle
How can I interrogate Python to find out where it is looking to find the PyQt4 DLLs in a Windows installation? Secondarily, how is this search path set? -- http://mail.python.org/mailman/listinfo/python-list

Re: A more pythonish code

2010-02-26 Thread prasad_chand
Hi Mr.Posner & nn, Thank your for your time & effort. I never knew that for...ever combination even existed. I would keep these insights in mind in the future. Thanks again, Prasad On Feb 25, 10:57 pm, John Posner wrote: > On 2/25/2010 7:23 AM, prasad_chand wrote: > > > > > Hi, > > > I use pyth

Re: A more pythonish code

2010-02-25 Thread nn
prasad_chand wrote: > Hi, > > I use python to do simple math problems as a hobby. > > I have made a program that finds the number of divisors(factors) of a > given number. I am hoping to improve my language skills, specifically > I would like to re-write the function "prime_factors" more graceful

A more pythonish code

2010-02-25 Thread prasad_chand
Hi, I use python to do simple math problems as a hobby. I have made a program that finds the number of divisors(factors) of a given number. I am hoping to improve my language skills, specifically I would like to re-write the function "prime_factors" more gracefully. While the program works right,

Re: A More Concise Description of Numpy than the Guide to Numpy?

2009-11-23 Thread W. eWatson
Robert Kern wrote: On 2009-11-23 11:49 AM, W. eWatson wrote: I'm looking the 300+ page pdf of the Guide to Numpy. Is there a more concise and practical guide to its use in science and mathematics? You will want to ask numpy questions on the numpy mailing list: http://www.scip

Re: A More Concise Description of Numpy than the Guide to Numpy?

2009-11-23 Thread Robert Kern
On 2009-11-23 11:49 AM, W. eWatson wrote: I'm looking the 300+ page pdf of the Guide to Numpy. Is there a more concise and practical guide to its use in science and mathematics? You will want to ask numpy questions on the numpy mailing list: http://www.scipy.org/Mailing_Lists You may

A More Concise Description of Numpy than the Guide to Numpy?

2009-11-23 Thread W. eWatson
I'm looking the 300+ page pdf of the Guide to Numpy. Is there a more concise and practical guide to its use in science and mathematics? -- http://mail.python.org/mailman/listinfo/python-list

Re: A more pythonic way of writting

2008-12-05 Thread eric
On Dec 6, 12:19 am, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > On Fri, 05 Dec 2008 07:44:21 -0800, eric wrote: > > I like to believe that the less the 'debug pointer' stands in the python > > code, the fastest the code is (or is potentially) > > What's a debug pointer? > > Pre-

  1   2   3   >