Re: argparse: delimiter for argparse list arguments

2021-08-03 Thread Sven R. Kunze
don't any way to separate both lists on this command call: cool-script.py thing1 thing2 stuff1 stuff2 Do I miss something here? Best Sven On 03.08.21 01:49, Dan Stromberg wrote: Isn't -- usually used to signal the end of options? On Mon, Aug 2, 2021 at 12:52 PM Sven R. Kunze <mailto:s

argparse: delimiter for argparse list arguments

2021-08-02 Thread Sven R. Kunze
Hi everyone, maybe, I am missing something here but is it possible to specify a delimiter for list arguments in argparse: https://docs.python.org/3/library/argparse.html Usually, '--' is used to separate two lists (cf. git). Cheers, Sven --

Re: [Python-ideas] Inconsistencies

2016-09-11 Thread Sven R. Kunze
On 10.09.2016 15:00, Chris Angelico wrote: Some things are absolute hard facts. There is no way in which 1 will ever be greater than 2, ergo "1 is less than 2" is strictly true, and not a matter of opinion. If you hear someone trying to claim otherwise, would you let him have his opinion, or

[issue27598] Add SizedIterable to collections.abc and typing

2016-08-04 Thread Sven R. Kunze
Sven R. Kunze added the comment: I am way too late to the discussion but I also support the term "collections". I think it also helps developers coming from a C# background: https://msdn.microsoft.com/library/92t2ye13(v=vs.110).aspx -- nosy

Re: Best Practices for Internal Package Structure

2016-04-06 Thread Sven R. Kunze
On 06.04.2016 01:47, Chris Angelico wrote: Generally, I refactor code not because the files are getting "too large" (for whatever definition of that term you like), but because they're stretching the file's concept. Every file should have a purpose; every piece of code in that file should

Re: Best Practices for Internal Package Structure

2016-04-06 Thread Sven R. Kunze
On 06.04.2016 09:28, Michael Selik wrote: On Wed, Apr 6, 2016, 2:51 AM Steven D'Aprano wrote: On Wed, 6 Apr 2016 05:56 am, Michael Selik wrote: [Michael] When you made that suggestion earlier, I immediately guessed that you were using PyCharm. I agree that the

Re: Best Practices for Internal Package Structure

2016-04-05 Thread Sven R. Kunze
On 05.04.2016 20:40, Ethan Furman wrote: (utils.py does export a couple of functions, but they should be in the main module, or possibly made into a method of BidirectionalMapping.) Your package is currently under 500 lines. As it stands now, you could easily flatten it to a single module:

Re: Best Practices for Internal Package Structure

2016-04-05 Thread Sven R. Kunze
On 05.04.2016 19:59, Chris Angelico wrote: On Wed, Apr 6, 2016 at 3:38 AM, Sven R. Kunze <srku...@mail.de> wrote: Your package is currently under 500 lines. As it stands now, you could easily flatten it to a single module: bidict.py I don't recommend this. The line is blurry b

Re: Best Practices for Internal Package Structure

2016-04-05 Thread Sven R. Kunze
On 05.04.2016 03:43, Steven D'Aprano wrote: The purpose of packages isn't enable Java-style "one class per file" coding, especially since *everything* in the package except the top level "bidict" module itself is private. bidict.compat and bidict.util aren't flagged as private, but they should

Re: Best Practices for Internal Package Structure

2016-04-04 Thread Sven R. Kunze
Hi Josh, good question. On 04.04.2016 18:47, Josh B. wrote: My package, available at https://github.com/jab/bidict, is currently laid out like this: bidict/ ├── __init__.py ├── _bidict.py ├── _common.py ├── _frozen.py ├── _loose.py ├── _named.py ├── _ordered.py ├── compat.py ├── util.py

Re: Learning Python (or Haskell) makes you a worse programmer

2016-03-31 Thread Sven R. Kunze
On 31.03.2016 18:30, Travis Griggs wrote: British: http://www.oxforddictionaries.com/definition/english/python American: http://www.dictionary.com/browse/python?s=t That does it. If I ever make some sort of open source module for pythun/pythawn I’ll be sure to call it either

Re: Slice equivalent to dict.get

2016-03-31 Thread Sven R. Kunze
On 31.03.2016 17:07, Steven D'Aprano wrote: Sometimes people look for a method which is equivalent to dict.get, where they can set a default value for when the key isn't found: py> d = {1: 'a', 2: 'b'} py> d.get(999, '?') '?' The equivalent for sequences such as lists and tuples is a slice.

Re: Learning Python (or Haskell) makes you a worse programmer

2016-03-30 Thread Sven R. Kunze
On 30.03.2016 12:21, BartC wrote: On 30/03/2016 11:07, Sven R. Kunze wrote: On 30.03.2016 01:29, Eric S. Johansson wrote: On 3/29/2016 6:05 AM, Sven R. Kunze wrote: Python = English As someone who writes English text and code using speech recognition, I can assure you that Python

Re: Learning Python (or Haskell) makes you a worse programmer

2016-03-30 Thread Sven R. Kunze
On 30.03.2016 12:14, Tim Golden wrote: Not that you quite meant this, but I'm always amused (and still a little startled) when I listen to talks recorded from, say, PyCon and hear people with American accents pronouncing Python with the stress on the slightly longer second syllable. (I don't

Re: Learning Python (or Haskell) makes you a worse programmer

2016-03-30 Thread Sven R. Kunze
On 30.03.2016 01:29, Eric S. Johansson wrote: On 3/29/2016 6:05 AM, Sven R. Kunze wrote: Python = English As someone who writes English text and code using speech recognition, I can assure you that Python is not English. :-) :D Interesting. Never thought of how Python sounds when spoken

Re: Threading is foobared?

2016-03-30 Thread Sven R. Kunze
On 30.03.2016 01:43, Steven D'Aprano wrote: On Tue, 29 Mar 2016 09:26 pm, Sven R. Kunze wrote: On 27.03.2016 05:01, Steven D'Aprano wrote: Am I the only one who has noticed that threading of posts here is severely broken? It's always been the case that there have been a few posts here

Re: [OT] C# -- sharp or carp? was Re: Learning Python (or Haskell) makes you a worse programmer

2016-03-29 Thread Sven R. Kunze
On 29.03.2016 18:05, Peter Otten wrote: Reformatting it a bit String.Join( "\n", mylist.Where( foo => !String.IsNullOrEmpty(foo.description) ).Select( foo => foo.description)) this looks like a variant of Python's str.join( "\n", map(lambda foo:

Re: [OT] C# -- sharp or carp? was Re: Learning Python (or Haskell) makes you a worse programmer

2016-03-29 Thread Sven R. Kunze
On 29.03.2016 12:18, Sven R. Kunze wrote: On 29.03.2016 11:39, Peter Otten wrote: My question to those who know a bit of C#: what is the state-of-the-art equivalent to "\n".join(foo.description() for foo in mylist if foo.description() != "") U

Re: Exclude every nth element from list?

2016-03-29 Thread Sven R. Kunze
On 26.03.2016 18:06, Peter Otten wrote: beliavsky--- via Python-list wrote: I can use x[::n] to select every nth element of a list. Is there a one-liner to get a list that excludes every nth element? del x[::n] ;) Actually quite nice. -- https://mail.python.org/mailman/listinfo/python-list

Re: Threading is foobared?

2016-03-29 Thread Sven R. Kunze
On 27.03.2016 05:01, Steven D'Aprano wrote: Am I the only one who has noticed that threading of posts here is severely broken? It's always been the case that there have been a few posts here and there that break threading, but now it seems to be much more common. I agree. Didn't we both

Re: newbie question

2016-03-29 Thread Sven R. Kunze
On 28.03.2016 17:34, ast wrote: "Matt Wheeler" <m...@funkyhat.org> a écrit dans le message de news:mailman.92.1458825746.2244.python-l...@python.org... On Thu, 24 Mar 2016 11:10 Sven R. Kunze, <srku...@mail.de> wrote: On 24.03.2016 11:57, Matt Wheeler wrote: >&g

Re: [OT] C# -- sharp or carp? was Re: Learning Python (or Haskell) makes you a worse programmer

2016-03-29 Thread Sven R. Kunze
On 29.03.2016 11:39, Peter Otten wrote: My question to those who know a bit of C#: what is the state-of-the-art equivalent to "\n".join(foo.description() for foo in mylist if foo.description() != "") Using LINQ, I suppose:

Re: Learning Python (or Haskell) makes you a worse programmer

2016-03-29 Thread Sven R. Kunze
On 29.03.2016 06:13, Michael Torrie wrote: On 03/28/2016 06:44 PM, Steven D'Aprano wrote: http://lukeplant.me.uk/blog/posts/why-learning-haskell-python-makes-you-a-worse-programmer/ I have the same problem as the writer. Working in Python makes me really dislike working in any other

Re: Which are best, well-tested ways to create REST services, with Json, in Python?

2016-03-29 Thread Sven R. Kunze
Not heard of any but I can recommend django-restframework. We've got good experience with that. On 28.03.2016 23:06, David Shi via Python-list wrote: Has anyone done a recent reviews of creating REST services, in Python? Regards. David -- https://mail.python.org/mailman/listinfo/python-list

Re: newbie question

2016-03-24 Thread Sven R. Kunze
On 24.03.2016 14:22, Matt Wheeler wrote: On Thu, 24 Mar 2016 11:10 Sven R. Kunze, <srku...@mail.de> wrote: On 24.03.2016 11:57, Matt Wheeler wrote: import ast s = "(1, 2, 3, 4)" t = ast.literal_eval(s) t (1, 2, 3, 4) I suppose that's the better solution in terms of

Re: newbie question

2016-03-24 Thread Sven R. Kunze
On 24.03.2016 11:57, Matt Wheeler wrote: import ast s = "(1, 2, 3, 4)" t = ast.literal_eval(s) t (1, 2, 3, 4) I suppose that's the better solution in terms of safety. -- https://mail.python.org/mailman/listinfo/python-list

Re: monkey patching __code__

2016-03-23 Thread Sven R. Kunze
On 23.03.2016 09:24, dieter wrote: But you have observed that you cannot do everything with a code substitution: a function call does not only depend on the code but also on other properties of the function object: e.g. the parameter processing. Yep, that's because Python is very flexible and

how to cache invalidation

2016-03-22 Thread Sven R. Kunze
Hi everybody, I got another module up and running: xcache Background described here: http://srkunze.blogspot.com/2016/03/safe-cache-invalidation.html We needed a way to safely invalidate rlu_caches once a Web request has been finished. So, we came up with a solution using garbage collection

Re: monkey patching __code__

2016-03-22 Thread Sven R. Kunze
On 21.03.2016 21:42, Matt Wheeler wrote: On 20 March 2016 at 16:46, Sven R. Kunze <srku...@mail.de> wrote: On 19.03.2016 00:58, Matt Wheeler wrote: I know you have a working solution now with updating the code & defaults of the function, but what about just injecting you

Re: monkey patching __code__

2016-03-20 Thread Sven R. Kunze
On 19.03.2016 00:58, Matt Wheeler wrote: I know you have a working solution now with updating the code & defaults of the function, but what about just injecting your function into the modules that had already imported it after the monkeypatching? Seems perhaps cleaner, unless you'd end up

Re: empty clause of for loops

2016-03-19 Thread Sven R. Kunze
On 16.03.2016 16:02, Tim Chase wrote: On 2016-03-16 15:29, Sven R. Kunze wrote: I would re-use the "for-else" for this. Everything I thought I could make use of the "-else" clause, I was disappointed I couldn't. Hmm...this must be a mind-set thing. I use the "else&quo

Re: empty clause of for loops

2016-03-19 Thread Sven R. Kunze
On 16.03.2016 18:08, Random832 wrote: Yeah, well, you can *almost* get there with: try: thing = next(item for item in collection if good(item)) except StopIteration: thing = default But the for/else thing seems like a more natural way to do it. Plus, this is a toy example, if the

Re: monkey patching __code__

2016-03-19 Thread Sven R. Kunze
On 18.03.2016 14:47, Ian Kelly wrote: Your patched version takes two extra arguments. Did you add the defaults for those to the function's __defaults__ attribute? That's it! :-) Thanks a lot. Just to understand this better: why is that not part of the code object but part of the function?

Re: empty clause of for loops

2016-03-19 Thread Sven R. Kunze
On 16.03.2016 11:47, Peter Otten wrote: What would you expect? A keyword filling the missing functionality? Some Python magic, I haven't seen before. ;-) class Empty(Exception): pass ... def check_empty(items): ... items = iter(items) ... try: ... yield next(items)

Re: empty clause of for loops

2016-03-19 Thread Sven R. Kunze
On 18.03.2016 20:10, Palpandi wrote: You can do like this. if not my_iterable: for x in my_iterable: Thanks for you help here, however as already pointed out, my_iterable is not necessarily a list but more likely an exhaustible iterator/generator. Best, Sven --

Re: empty clause of for loops

2016-03-19 Thread Sven R. Kunze
On 16.03.2016 13:57, Peter Otten wrote: I'd put that the other way round: syntactical support for every pattern would make for a rather unwieldy language. You have to choose carefully, and this requirement could easily be fulfilled by a function, first in your personal toolbox, then in a public

Re: monkey patching __code__

2016-03-19 Thread Sven R. Kunze
On 18.03.2016 15:48, Ian Kelly wrote: Well I didn't design it, so I'm not really sure. But it could be argued that the defaults are intrinsic to the function declaration, not the code object, as not all code objects even have arguments. It also makes it straight-forward to create a new function

Re: Replace weird error message?

2016-03-19 Thread Sven R. Kunze
On 16.03.2016 19:53, Ben Finney wrote: Do you think some better error message should be used? Yes, I think that error message needs to be improved. Please file a bug report in Python's issue tracker . For example a hint that "0" does work for the given argument.

Re: monkey patching __code__

2016-03-19 Thread Sven R. Kunze
On 18.03.2016 15:23, Ian Kelly wrote: On Fri, Mar 18, 2016 at 7:47 AM, Ian Kelly wrote: Your patched version takes two extra arguments. Did you add the defaults for those to the function's __defaults__ attribute? And as an afterthought, you'll likely need to replace the

Re: empty clause of for loops

2016-03-19 Thread Sven R. Kunze
On 16.03.2016 17:37, Random832 wrote: On Wed, Mar 16, 2016, at 11:17, Sven R. Kunze wrote: I can imagine that. Could you describe the general use-case? From what I know, "else" is executed when you don't "break" the loop. When is this useful? for item in collecti

Re: empty clause of for loops

2016-03-19 Thread Sven R. Kunze
On 16.03.2016 13:08, Steven D'Aprano wrote: Doing what? What is the code supposed to do? What's "empty" mean as a keyword? If you explain what your friends wants, then perhaps we can suggest something. Otherwise we're just guessing. I can think of at least two different meanings: * run the

Re: empty clause of for loops

2016-03-19 Thread Sven R. Kunze
On 16.03.2016 15:29, Sven R. Kunze wrote: On 16.03.2016 13:57, Peter Otten wrote: I'd put that the other way round: syntactical support for every pattern would make for a rather unwieldy language. You have to choose carefully, and this requirement could easily be fulfilled by a function

Re: empty clause of for loops

2016-03-19 Thread Sven R. Kunze
On 16.03.2016 14:58, alister wrote: no , i just typed it, while trying to hold a conversation with swmbo :-( apologies to the op if e could not see where i was intending to go with this. No problem, I perform quite well at guessing folk's intention. So, yes, I can extrapolate what you

Re: empty clause of for loops

2016-03-19 Thread Sven R. Kunze
On 16.03.2016 14:09, Tim Chase wrote: If you can len() on it, then the obvious way is if my_iterable: for x in my_iterable: do_something(x) else: something_else() However, based on your follow-up that it's an exhaustible iterator rather than something you can len(), I'd

Re: empty clause of for loops

2016-03-19 Thread Sven R. Kunze
On 16.03.2016 17:20, Terry Reedy wrote: On 3/16/2016 11:17 AM, Sven R. Kunze wrote: On 16.03.2016 16:02, Tim Chase wrote: Does it annoy me when I have to work in other languages that lack Python's {for/while}/else functionality? You bet. I can imagine that. Could you describe

Re: empty clause of for loops

2016-03-18 Thread Sven R. Kunze
On 16.03.2016 17:56, Sven R. Kunze wrote: On 16.03.2016 17:37, Random832 wrote: On Wed, Mar 16, 2016, at 11:17, Sven R. Kunze wrote: I can imagine that. Could you describe the general use-case? From what I know, "else" is executed when you don't "break" the loop.

Re: monkey patching __code__

2016-03-18 Thread Sven R. Kunze
On 18.03.2016 15:33, Sven R. Kunze wrote: On 18.03.2016 15:23, Ian Kelly wrote: On Fri, Mar 18, 2016 at 7:47 AM, Ian Kelly <ian.g.ke...@gmail.com> wrote: Your patched version takes two extra arguments. Did you add the defaults for those to the function's __defaults__ att

Re: empty clause of for loops

2016-03-18 Thread Sven R. Kunze
On 17.03.2016 01:27, Steven D'Aprano wrote: That post describes the motivating use-case for the introduction of "if...else", and why break skips the "else" clause: for x in data: if meets_condition(x): break else: # raise error or do additional processing It might help to

Re: Bash-like pipes in Python

2016-03-18 Thread Sven R. Kunze
On 16.03.2016 16:09, Joel Goldstick wrote: symbol '|' in python. Can you elaborate bitwise or -- https://mail.python.org/mailman/listinfo/python-list

monkey patching __code__

2016-03-18 Thread Sven R. Kunze
Hi, we got an interesting problem. We need to monkeypatch Django's reverse function: First approach: urlresolvers.reverse = patched_reverse Problem: some of Django's internal modules import urlresolvers.reverse before we can patch it for some reasons. Second approach:

Re: empty clause of for loops

2016-03-16 Thread Sven R. Kunze
On 16.03.2016 11:28, Joaquin Alzola wrote: If len(my_iterable) is not 0: for x in my_iterable: # do else: # do something else I am sorry, I should have been more precise here. my_iterable is an iterator that's exhausted after a complete iteration and cannot be restored.

empty clause of for loops

2016-03-16 Thread Sven R. Kunze
Hi, a colleague of mine (I write this mail because I am on the list) has the following issue: for x in my_iterable: # do empty: # do something else What's the most Pythonic way of doing this? Best, Sven -- https://mail.python.org/mailman/listinfo/python-list

Re: argparse

2016-03-12 Thread Sven R. Kunze
On 12.03.2016 00:18, Fillmore wrote: Playing with ArgumentParser. I can't find a way to override the -h and --help options so that it provides my custom help message. I remember everything being a lot easier using argh instead of argparse. https://pypi.python.org/pypi/argh#examples The doc

Re: even faster heaps

2016-03-09 Thread Sven R. Kunze
On 09.03.2016 19:19, Sven R. Kunze wrote: ps: there are two error's when i ran tests with test_xheap. Damn. I see this is Python 2 and Python 3 related. Thanks for bringing this to my attention. I am going to fix this soon. Fixed. -- https://mail.python.org/mailman/listinfo/python-list

Re: even faster heaps

2016-03-09 Thread Sven R. Kunze
On 06.03.2016 14:59, Sven R. Kunze wrote: Using the original xheap benchmark <http://srkunze.blogspot.de/2016/02/the-xheap-benchmark.html>, I could see huge speedups: from 50x/25x down to 3x/2x compared to heapq. That's a massive improvement. I will publish an update soon. A

Re: even faster heaps

2016-03-09 Thread Sven R. Kunze
. :) But you are right. I re-executed the benchmark and compared 100, 1000 and 1 with each other. Almost no difference at all. I am going to reduce it to 100. So, it takes ca. 8 minutes on my machine. Thanks for your feedback, Sven On Sun, Mar 6, 2016 at 7:29 PM, Sven R. Kunze <s

Re: reversed(zip(...)) not working as intended

2016-03-06 Thread Sven R. Kunze
On 06.03.2016 19:51, Tim Chase wrote: So it looks like one needs to either results = reversed(list(zip(...))) or, more efficiently (doing it with one less duplication of the list) results = list(zip(...)) results.reverse() Nice idea. :) Unfortunately, I used it while drafting

Re: reversed(zip(...)) not working as intended

2016-03-06 Thread Sven R. Kunze
On 06.03.2016 19:53, Peter Otten wrote: Sven R. Kunze wrote: what's the reason that reversed(zip(...)) raises as a TypeError? Would allowing reversed to handle zip and related functions lead to strange errors? In Python 3 zip() can deal with infinite iterables -- what would you expect from

reversed(zip(...)) not working as intended

2016-03-06 Thread Sven R. Kunze
Hi, what's the reason that reversed(zip(...)) raises as a TypeError? Would allowing reversed to handle zip and related functions lead to strange errors? Best, Sven -- https://mail.python.org/mailman/listinfo/python-list

even faster heaps

2016-03-06 Thread Sven R. Kunze
Hi python-list, hi Srinivas, I managed to implement the mark approach for fast removal from heaps. This way, I got three pleasant results: 1) a substantial speed up! 2) an improved testsuite 3) discovery and fixing of several bugs @Srinivas I would be honored if you could have a look at the

Re: [Off-topic] Requests author discusses MentalHealthError exception

2016-03-01 Thread Sven R. Kunze
On 01.03.2016 13:13, Steven D'Aprano wrote: On Tue, 1 Mar 2016 09:38 am, Larry Martell wrote: But what is reality? Reality is that which, when you stop believing in it, doesn't go away. Just like that. -- https://mail.python.org/mailman/listinfo/python-list

Re: Everything good about Python except GUI IDE?

2016-02-28 Thread Sven R. Kunze
On 28.02.2016 07:34, Steven D'Aprano wrote: I think that's out-and-out wrong, and harmful to the developer community. I think that we're stuck in the equivalent of the pre-WYSIWYG days of word processing: you can format documents as nicely as you like, but you have to use a separate mode to see

Re: Bug in Python?

2016-02-28 Thread Sven R. Kunze
On 27.02.2016 12:48, Terry Reedy wrote: On 2/27/2016 4:44 AM, Steven D'Aprano wrote: On Sat, 27 Feb 2016 07:55 pm, Terry Reedy wrote: In other words, when that doc says *list*, it means a *list*. "To create a heap, use a list initialized to [], or you can transform a populated list into a

Re: Bug in Python?

2016-02-28 Thread Sven R. Kunze
On 27.02.2016 00:07, eryk sun wrote: On Fri, Feb 26, 2016 at 4:08 PM, Sven R. Kunze <srku...@mail.de> wrote: Python sometimes seems not to hop back and forth between C and Python code. Can somebody explain this? Normally a C extension would call PySequence_SetItem, which woul

Re: Bug in Python?

2016-02-28 Thread Sven R. Kunze
On 26.02.2016 23:37, Ian Kelly wrote: On Fri, Feb 26, 2016 at 3:08 PM, Sven R. Kunze <srku...@mail.de> wrote: Python sometimes seems not to hop back and forth between C and Python code. C code as a rule tends to ignore dunder methods. Those are used to implement Python operations,

Bug in Python?

2016-02-26 Thread Sven R. Kunze
Hi everybody, I recognized the following oddity (background story: http://srkunze.blogspot.com/2016/02/lets-go-down-rabbit-hole.html). Python sometimes seems not to hop back and forth between C and Python code. Can somebody explain this? class MyList(list): count = 0 def

Re: How the heck does async/await work in Python 3.5

2016-02-23 Thread Sven R. Kunze
On 20.02.2016 07:53, Christian Gollwitzer wrote: If you have difficulties wit hthe overall concept, and if you are open to discussions in another language, take a look at this video: https://channel9.msdn.com/Shows/C9-GoingNative/GoingNative-39-await-co-routines MS has added coroutine

Re: How the heck does async/await work in Python 3.5

2016-02-23 Thread Sven R. Kunze
On 23.02.2016 18:37, Ian Kelly wrote: It's not entirely clear to me what the C++ is actually doing. With Python we have an explicit event loop that has to be started to manage resuming the coroutines. Since it's explicit, you could easily drop in a different event loop, such as Tornado or curio,

Re: How the heck does async/await work in Python 3.5

2016-02-23 Thread Sven R. Kunze
On 23.02.2016 01:48, Ian Kelly wrote: On Mon, Feb 22, 2016 at 3:16 PM, Sven R. Kunze <srku...@mail.de> wrote: Is something like shown in 12:50 ( cout << tcp_reader(1000).get() ) possible with asyncio? (tcp_reader would be async def) loop = asyncio.get_event_loop() print(loop.run_un

Re: How the heck does async/await work in Python 3.5

2016-02-22 Thread Sven R. Kunze
On 20.02.2016 07:53, Christian Gollwitzer wrote: If you have difficulties wit hthe overall concept, and if you are open to discussions in another language, take a look at this video: https://channel9.msdn.com/Shows/C9-GoingNative/GoingNative-39-await-co-routines MS has added coroutine

benchmarking in general and using xheap

2016-02-19 Thread Sven R. Kunze
Hi everybody, I've finally had the time to do the benchmarks and here you go: http://srkunze.blogspot.com/2016/02/the-xheap-benchmark.html The benchmark compares heapq, Heap, OrderHeap, RemovalHeap and XHeap regarding their operation heapify, push and pop. As expected wrapping results in

Re: Guido on python3 for beginners

2016-02-18 Thread Sven R. Kunze
On 18.02.2016 07:59, Paul Rubin wrote: Steven D'Aprano writes: I suppose that it is objectively correct that it is harder to learn than Python 2. But I don't think the learning curve is any steeper. If anything, the learning curve is ever-so-slightly less

Re: Multiple Assignment a = b = c

2016-02-16 Thread Sven R. Kunze
On 16.02.2016 14:05, Sven R. Kunze wrote: Hi Srinivas, I think the tuple assignment you showed basically nails it. First, the rhs is evaluated. Second, the lhs is evaluated from left to right. Completely wrong? Best, Sven As you mentioned swapping. The following two statements do the same

Re: Multiple Assignment a = b = c

2016-02-16 Thread Sven R. Kunze
Hi Srinivas, On 16.02.2016 13:46, srinivas devaki wrote: Hi, a = b = c as an assignment doesn't return anything, i ruled out a = b = c as chained assignment, like a = (b = c) SO i thought, a = b = c is resolved as a, b = [c, c] at-least i fixed in my mind that every assignment like

Re: Asyncio thought experiment

2016-02-10 Thread Sven R. Kunze
On 08.02.2016 23:13, Marko Rauhamaa wrote: As I stated in an earlier post, a normal subroutine may turn out to be blocking. To make it well-behaved under asyncio, you then dutifully tag the subroutine with "async" and adorn the blocking statement with "await". Consequently, you put "await" in

Re: Heap Implementation

2016-02-10 Thread Sven R. Kunze
Hi Cem, On 08.02.2016 02:37, Cem Karan wrote: My apologies for not writing sooner, but work has been quite busy lately (and likely will be for some time to come). no problem here. :) I read your approach, and it looks pretty good, but there may be one issue with it; how do you handle the

Re: _siftup and _siftdown implementation

2016-02-05 Thread Sven R. Kunze
Hi srinivas, I wrote this simple benchmark to measure comparisons: import random from xheapimport RemovalHeap class X(object): c =0 def __init__(self, x): self.x = x def __lt__(self, other): X.c +=1 return self.x < other.x n =10 for jjin range(5): items =

Re: _siftup and _siftdown implementation

2016-02-05 Thread Sven R. Kunze
r i in range(n)] random.shuffle(items) heap = RemovalHeap(items) random.shuffle(items) for i in items: heap.remove(i) print(X.c) X.c = 0 (note to myself: never copy PyCharm formatting strings to this list). On 05.02.2016 17:27, Sven R. Kunze wrote: Hi srinivas,

Re: _siftup and _siftdown implementation

2016-02-05 Thread Sven R. Kunze
On 05.02.2016 15:48, Bernardo Sulzbach wrote: On 02/05/2016 12:42 PM, Sven R. Kunze wrote: PS: I do competitive programming, I use these modules every couple of days when compared to other modules. so didn't give much thought when posting to the mailing list. sorry for that. Competitive

Re: _siftup and _siftdown implementation

2016-02-05 Thread Sven R. Kunze
On 05.02.2016 02:26, srinivas devaki wrote: as I come to think of it again, it is not subheap, it actually heap cut at some level hope you get the idea from the usage of _siftup. so even though the `pos` children are valid the _siftup brings down the new element (i.e the element which is at

Re: _siftup and _siftdown implementation

2016-02-04 Thread Sven R. Kunze
On 05.02.2016 01:12, Steven D'Aprano wrote: On Fri, 5 Feb 2016 07:50 am, srinivas devaki wrote: _siftdown function breaks out of the loop when the current pos has a valid parent. but _siftup function is not implemented in that fashion, if a valid subheap is given to the _siftup, it will bring

Re: Efficient Wrappers for Instance Methods

2016-02-04 Thread Sven R. Kunze
On 04.02.2016 00:47, Random832 wrote: On Wed, Feb 3, 2016, at 16:43, Sven R. Kunze wrote: Actually a nice idea if there were no overhead of creating methods for all heap instances separately. I'll keep that in mind. :) What about changing the class of the object to one which is inherited from

Re: Efficient Wrappers for Instance Methods

2016-02-04 Thread Sven R. Kunze
On 04.02.2016 19:35, Random832 wrote: On Thu, Feb 4, 2016, at 11:18, Sven R. Kunze wrote: On 04.02.2016 00:47, Random832 wrote: On Wed, Feb 3, 2016, at 16:43, Sven R. Kunze wrote: Actually a nice idea if there were no overhead of creating methods for all heap instances separately. I'll keep

Re: Efficient Wrappers for Instance Methods

2016-02-03 Thread Sven R. Kunze
On 03.02.2016 22:06, Bernardo Sulzbach wrote: I may say something wrong, but this is what I see going on: When you get "replace = heapreplace" you are creating a data attribute called replace (you will access it by self.replace or variable.replace) that is an alias for heapreplace. When you

Efficient Wrappers for Instance Methods

2016-02-03 Thread Sven R. Kunze
Hi, as you might have noticed, I am working on https://github.com/srkunze/xheap right now. In order to make it even faster and closer to heapq's baseline performance, I wonder if there is a possibility of creating fast wrappers for functions. Please compare

Re: Efficient Wrappers for Instance Methods

2016-02-03 Thread Sven R. Kunze
On 03.02.2016 22:19, Peter Otten wrote: You could try putting self.heappush = functools.partial(heapq.heappush, self) into the initializer. Actually a nice idea if there were no overhead of creating methods for all heap instances separately. I'll keep that in mind. :) --

Re: Efficient Wrappers for Instance Methods

2016-02-03 Thread Sven R. Kunze
On 03.02.2016 22:15, Peter Otten wrote: The technical reason is that functions written in C don't implement the descriptor protocol. The bound method is created by invoking the __get__ method of the class attribute: Good to know. :-/ It's sad. These functions just look so method-like.

Re: Efficient Wrappers for Instance Methods

2016-02-03 Thread Sven R. Kunze
On 03.02.2016 22:34, Bernardo Sulzbach wrote: Did Peter's suggestion work? Somewhat for a single Heap class. However, it breaks inheritance. -- https://mail.python.org/mailman/listinfo/python-list

Re: Efficient Wrappers for Instance Methods

2016-02-03 Thread Sven R. Kunze
On 03.02.2016 21:40, Bernardo Sulzbach wrote: I am not entirely sure about what your question is. Are you talking about the "heapreplace expected 2 arguments, got 1" you get if you set replace = heapreplace? Yes, I think so. I might ask differently: why do I need to write wrapper method when

Re: Efficient Wrappers for Instance Methods

2016-02-03 Thread Sven R. Kunze
On 03.02.2016 22:14, Bernardo Sulzbach wrote: Thanks for quoting, for some reason my client always replies to the person and not the list (on this list only). I did what I could. I could show you a lambda function there, but it doesn't solve anything. If there is a way to avoid a wrapper, I

Re: Heap Implementation

2016-02-02 Thread Sven R. Kunze
On 02.02.2016 01:48, srinivas devaki wrote: On Feb 1, 2016 10:54 PM, "Sven R. Kunze" <srku...@mail.de <mailto:srku...@mail.de>> wrote: > > Maybe I didn't express myself well. Would you prefer the sweeping approach in terms of efficiency over how I implemented xhe

Re: Heap Implementation

2016-02-01 Thread Sven R. Kunze
On 31.01.2016 02:48, Steven D'Aprano wrote: On Sunday 31 January 2016 09:47, Sven R. Kunze wrote: @all What's the best/standardized tool in Python to perform benchmarking? timeit Thanks, Steven. Maybe, I am doing it wrong but I get some weird results: >>> min(timeit.Timer('for _

Re: Heap Implementation

2016-02-01 Thread Sven R. Kunze
, it is brilliant of you to simply use __setitem__ Thanks. :) On Sun, Jan 31, 2016 at 4:17 AM, Sven R. Kunze <srku...@mail.de> wrote: Hi again, as the topic of the old thread actually was fully discussed, I dare to open a new one. I finally managed to finish my heap implementation. You ca

Re: psss...I want to move from Perl to Python

2016-01-30 Thread Sven R. Kunze
On 29.01.2016 23:49, Ben Finney wrote: "Sven R. Kunze" <srku...@mail.de> writes: On 29.01.2016 01:01, Fillmore wrote: How was the Python 2.7 vs Python 3.X solved? which version should I go for? Python 3 is the new and better one. More importantly: Python 2 will never i

Heap Implemenation

2016-01-30 Thread Sven R. Kunze
Hi again, as the topic of the old thread actually was fully discussed, I dare to open a new one. I finally managed to finish my heap implementation. You can find it at https://pypi.python.org/pypi/xheap + https://github.com/srkunze/xheap. I described my motivations and design decisions at

Heap Implementation

2016-01-30 Thread Sven R. Kunze
Hi again, as the topic of the old thread actually was fully discussed, I dare to open a new one. I finally managed to finish my heap implementation. You can find it at https://pypi.python.org/pypi/xheap + https://github.com/srkunze/xheap. I described my motivations and design decisions at

Re: psss...I want to move from Perl to Python

2016-01-29 Thread Sven R. Kunze
Hi, On 29.01.2016 01:01, Fillmore wrote: I look and Python and it looks so much more clean add to that that it is the language of choice of data miners... add to that that iNotebook looks powerful All true. :) Does Python have Regexps? "import re"

Re: issues

2016-01-14 Thread Sven R. Kunze
Hi Gert, just upgrade to 5.03. Best, Sven On 13.01.2016 18:38, Gert Förster wrote: Ladies, Gentlemen, using the PyCharm Community Edition 4.5.4, with Python-3-5-1-amd64.exe, there is constantly a “Repair”-demand. This is “successful” when executed. Without execution, there results an “Error

Re: How to remove item from heap efficiently?

2016-01-13 Thread Sven R. Kunze
On 13.01.2016 12:20, Cem Karan wrote: On Jan 12, 2016, at 11:18 AM, "Sven R. Kunze" <srku...@mail.de> wrote: Thanks for replying here. I've come across these types of wrappers/re-implementations of heapq as well when researching this issue. :) Unfortunately, they don't solv

Re: How to remove item from heap efficiently?

2016-01-12 Thread Sven R. Kunze
On 12.01.2016 03:48, Cem Karan wrote: Jumping in late, but... If you want something that 'just works', you can use HeapDict: http://stutzbachenterprises.com/ I've used it in the past, and it works quite well. I haven't tested its asymptotic performance though, so you might want to check

  1   2   >