[issue24571] [RFE] Add asyncio.blocking_call API

2015-07-06 Thread Sven R. Kunze
Sven R. Kunze added the comment: Thanks for taking the initiative here, Nick. I created a follow-up on this: http://bugs.python.org/issue24578 In order to bridge both worlds, projects might need convenient way from and to either world (classic and asyncio). -- components: +asyncio

[issue24571] [RFE] Add asyncio.blocking_call API

2015-07-06 Thread Sven R. Kunze
Sven R. Kunze added the comment: 2 remarks: 1) I would rather go for a more comprehensible name such as 'get_awaitable' instead of 'blocking_call'. Later reminds me of the execution of f which is not the case. 2) redundant ) in the end of Usage: result = await asyncio.blocking_call(f, *args

[issue24578] [RFE] Add asyncio.wait_for_result API

2015-07-06 Thread Sven R. Kunze
New submission from Sven R. Kunze: In order to complement http://bugs.python.org/issue24571, this is another high-level convenience API for asyncio to treat an awaitable like a usual subroutine (credits go to Nick Coghlan): # Call awaitable from synchronous code def wait_for_result

[issue24578] [RFE] Add asyncio.wait_for_result API

2015-07-06 Thread Sven R. Kunze
Changes by Sven R. Kunze srku...@mail.de: -- nosy: +giampaolo.rodola, ncoghlan, pitrou -srkunze type: - enhancement ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue24578

[issue24578] [RFE] Add asyncio.wait_for_result API

2015-07-06 Thread Sven R. Kunze
Changes by Sven R. Kunze srku...@mail.de: -- nosy: +srkunze ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue24578 ___ ___ Python-bugs-list mailing

[issue24571] [RFE] Add asyncio.call_async API

2015-07-07 Thread Sven R. Kunze
Sven R. Kunze added the comment: I also fear adding too many functions to do the same things. For example, scheduling the execution of a coroutine can now be done by: * asyncio.async(coro) * asyncio.Task(coro) * loop.create_task(coro) * asyncio.ensure_task(coro) If you ask me

[issue24571] [RFE] Add asyncio.call_async API

2015-07-07 Thread Sven R. Kunze
Sven R. Kunze added the comment: @David What is the purpose of multitasking code? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue24571

Re: Hooking Mechanism when Entering and Leaving a Try Block

2015-08-13 Thread Sven R. Kunze
On 13.08.2015 02:45, Chris Angelico wrote: On Thu, Aug 13, 2015 at 6:54 AM, Mark Lawrence breamore...@yahoo.co.uk wrote: On 12/08/2015 19:44, Sven R. Kunze wrote: On 12.08.2015 18:11, Chris Angelico wrote: (Please don't top-post.) Is this some guideline? I actually quite dislike pick

Re: Hooking Mechanism when Entering and Leaving a Try Block

2015-08-13 Thread Sven R. Kunze
On 12.08.2015 20:44, Sven R. Kunze wrote: On 12.08.2015 18:11, Chris Angelico wrote: Sounds to me like you want some sort of AST transform, possibly in an import hook. Check out something like MacroPy for an idea of how powerful this sort of thing can be. Sounds like I MacroPy would enable me

Python Import Hooks and __main__

2015-08-17 Thread Sven R. Kunze
Hi, following up on this thread on StackOverflow http://stackoverflow.com/questions/16515347/python-import-hooks-and-main does somebody has a great idea how to manage this? The issue at hand is, that I would like to apply a specific import hook right from the beginning of the interpreter

Re: [Back off topic] - Hooking Mechanism when Entering and Leaving a Try Block

2015-08-14 Thread Sven R . Kunze
Am 14-Aug-2015 03:00:05 +0200 schrieb torr...@gmail.com: But I digress. We get sidetracked rather easily around here. You don't say. ;) - FreeMail powered by mail.de - MEHR SICHERHEIT, SERIOSITÄT

Hooking Mechanism when Entering and Leaving a Try Block

2015-08-12 Thread Sven R. Kunze
Hi everybody, is there something like a hook that a Python module could register to in order to 'trace' the entering and leaving of arbitrary try blocks? What is this good for? I am the maintainer of https://pypi.python.org/pypi/xfork . A package for converting a classic sequential program

Re: Hooking Mechanism when Entering and Leaving a Try Block

2015-08-12 Thread Sven R. Kunze
Unfortunately, no. :( It should work out of the box with no let me replace all my try-except statements in my 10 million line code base. On 12.08.2015 17:32, Ian Kelly wrote: On Tue, Aug 11, 2015 at 3:47 PM, Sven R. Kunze srku...@mail.de wrote: is there something like a hook that a Python

Re: Hooking Mechanism when Entering and Leaving a Try Block

2015-08-12 Thread Sven R. Kunze
On 12.08.2015 18:11, Chris Angelico wrote: On Thu, Aug 13, 2015 at 2:05 AM, Sven R. Kunze srku...@mail.de wrote: Unfortunately, no. :( It should work out of the box with no let me replace all my try-except statements in my 10 million line code base. (Please don't top-post.) Is this some

Re: asyncio, coroutines, etc. and simultaneous execution

2015-08-24 Thread Sven R. Kunze
On 23.08.2015 23:43, Charles Hixson wrote: If I understand correctly asyncio, coroutines, etc. (and, of course, Threads) are not simultaneously executed, and that if one wants that one must still use multiprocessing. But I'm not sure. The note is still there at the start of threading, so I'm

[issue24571] [RFE] Add asyncio.call_async API

2015-07-07 Thread Sven R. Kunze
Sven R. Kunze added the comment: Why bother with asyncio at all? Good question. My initial reaction to async+await was: 'great, finally a Pythonic (i.e. a single, explicit) way to do squeeze out more of our servers'. Moreover, the goal of 'being more like classic code' + 'having reasonable

[issue24571] [RFE] Add asyncio.background_call API

2015-07-09 Thread Sven R. Kunze
Sven R. Kunze added the comment: ... this sounds like it is encouraging staying ignorant. True. However, I being ignorant about the complexity eventually led to the development of high-level languages like Python. Each time, a next generation simply asks the question: 'does it really need

Re: Casting to a number (both int and float)?

2015-08-28 Thread Sven R. Kunze
Hey Victor, for proper parsing into native Python types, I would recommend YAML. Also also supports (besides int vs. float) dates and datetimes. Cheers, Sven On 28.08.2015 07:04, Victor Hooi wrote: Actually, I've just realised, if I just test for numeric or try to cast to ints, this will

Re: Casting to a number (both int and float)?

2015-08-30 Thread Sven R. Kunze
Sven R. Kunze: I'm reading JSON output from an input file, and extracting values. for proper parsing into native Python types, I would recommend YAML. What's the best way to get from A to B? I recommend starting at C. - Every other usenet-discussion. -- https://mail.python.org/mailman

Re: packing unpacking depends on order.

2015-09-02 Thread Sven R. Kunze
I agree as well. First evaluate the right side, then assign it to the left side at once. On 02.09.2015 12:22, Nick Sarbicki wrote: That's interesting. I agree with you, I'd prefer the second result in both cases. But makes sense as it evaluates left to right and seems to break up the

Re: packing unpacking depends on order.

2015-09-04 Thread Sven R. Kunze
On 04.09.2015 05:36, random...@fastmail.us wrote: You haven't demonstrated that the RHS is affected by anything. The sample code in the original post of this thread behaves identically if the RHS is a simple tuple of (2, 1) [or (1, 2)] respectively. If you have another sample that shows

Re: Python handles globals badly.

2015-09-04 Thread Sven R. Kunze
On 04.09.2015 18:55, t...@freenet.de wrote: From knowing e.g Java as OO language I had no need to set such a keyword "global" to get write access to class members. It is true and I really dislike Java for having this. Please consider this class MyClass: @classmethod def

Re: Wheels For ...

2015-09-08 Thread Sven R. Kunze
On 06.09.2015 22:06, Ned Batchelder wrote: As a developer of a Python package, I don't see how this would be better. The developer would still have to get their software into some kind of uniform configuration, so the central authority could package it. You've moved the problem from, "everyone

Re: packing unpacking depends on order.

2015-09-02 Thread Sven R. Kunze
On 02.09.2015 19:42, Terry Reedy wrote: On 9/2/2015 6:01 AM, Antoon Pardon wrote: a = [1, 2, 3, 4, 5] b = 1 b, a[b] = a[b], b a [1, 2, 1, 4, 5] a = [1, 2, 3, 4, 5] b = 1 a[b], b = b, a[b] a [1, 1, 3, 4, 5] I think I understand how it gets these results but I'm not really happy with them.

Re: Python handles globals badly.

2015-09-02 Thread Sven R. Kunze
On 02.09.2015 20:47, t...@freenet.de wrote: I agree with Skybuck Flying. I am aware if a var is a module function var or a module global var. If I want read or write a global var. Using the keyword global inside each(!) function only to mark the global var writeable in each of the functions is

Wheels For ...

2015-09-06 Thread Sven R. Kunze
Hi folks, currently, I came across http://pythonwheels.com/ during researching how to make a proper Python distribution for PyPI. I thought it would be great idea to tell other maintainers to upload their content as wheels so I approached a couple of them. Some of them already provided

Re: Python handles globals badly.

2015-09-03 Thread Sven R. Kunze
On 03.09.2015 00:25, t...@freenet.de wrote: It is the good idea of Python about modules which are singletons and therefore have already its state (so in some way they are already somehow like classes - except the bad annoying thing with the "global" statement). So, what you really want is a

Re: Strange location for a comma

2015-09-03 Thread Sven R. Kunze
On 03.09.2015 14:20, ast wrote: Hello, At the end of the last line of the following program, there is a comma, I dont understand why ? Thx from cx_Freeze import setup, Executable # On appelle la fonction setup setup( name = "salut", version = "0.1", description = "Ce programme vous

Re: packing unpacking depends on order.

2015-09-03 Thread Sven R. Kunze
On 03.09.2015 03:17, random...@fastmail.us wrote: The question is what does "assign it to the left side at once" even *mean* in the presence of subscripts? Build up a list of object-subscript pairs (evaluating all the subscripts, including if any may have side effects) before executing any

Re: Context-aware return

2015-09-10 Thread Sven R. Kunze
http://stackoverflow.com/questions/2356399/tell-if-python-is-in-interactive-mode On 10.09.2015 19:54, Steven D'Aprano wrote: I have a function which is intended for use at the interactive interpreter, but may sometimes be used non-interactively. I wish to change it's output depending on the

Re: Context-aware return

2015-09-10 Thread Sven R. Kunze
is the reason for this special behavior? On 10.09.2015 20:03, Sven R. Kunze wrote: http://stackoverflow.com/questions/2356399/tell-if-python-is-in-interactive-mode On 10.09.2015 19:54, Steven D'Aprano wrote: I have a function which is intended for use at the interactive interpreter, but may

Re: Context-aware return

2015-09-10 Thread Sven R. Kunze
On 10.09.2015 20:14, Ben Finney wrote: "Sven R. Kunze" <srku...@mail.de> writes: http://stackoverflow.com/questions/2356399/tell-if-python-is-in-interactive-mode I'm pretty sure Steven knows full well the answer to that question, which is not anything like the one he asked

Re: Context-aware return

2015-09-10 Thread Sven R. Kunze
On 10.09.2015 20:34, Sven R. Kunze wrote: You are right. I turned out to me harder that I first thought. My initial guess was like: use AST. But now I see, it would be hard to get the source code. So, what actually could work, would be faking the interactive interpreter wrapping it up

Re: Context-aware return

2015-09-10 Thread Sven R. Kunze
Oops, missing print: On 10.09.2015 20:45, Sven R. Kunze wrote: On 10.09.2015 20:34, Sven R. Kunze wrote: You are right. I turned out to me harder that I first thought. My initial guess was like: use AST. But now I see, it would be hard to get the source code. So, what actually could work

Re: Context-aware return

2015-09-10 Thread Sven R. Kunze
On 10.09.2015 20:12, Ben Finney wrote: First thing in the morning I will purchase a head of cabbage and store it in a warm place to make it rot, on the off chance you find some obscure way to achieve your benighted goal, just so I can be first in line to throw it as you pass. Well, go ahead.

Re: True == 1 weirdness

2015-09-16 Thread Sven R. Kunze
On 16.09.2015 18:16, Marko Rauhamaa wrote: Chris Angelico : Far as I can see, the only operator that you might want to disallow chaining on is 'in' (and its mate 'not in', of course). It isn't common, but "x is y is z is None" is a perfectly reasonable way to ascertain

Re: True == 1 weirdness

2015-09-16 Thread Sven R. Kunze
On 16.09.2015 19:39, Steven D'Aprano wrote: node = left <= ptr => right Wow. I have absolutely no idea what this is supposed to mean. Do you care to elaborate? Best, Sven -- https://mail.python.org/mailman/listinfo/python-list

Re: True == 1 weirdness

2015-09-16 Thread Sven R. Kunze
On 16.09.2015 19:46, Grant Edwards wrote: On 2015-09-16, Steven D'Aprano wrote: node = left <= ptr => right Exactly. I've no clue what that means. ;) Modern art. ;) Best, Sven -- https://mail.python.org/mailman/listinfo/python-list

Re: True == 1 weirdness

2015-09-16 Thread Sven R. Kunze
On 16.09.2015 19:33, Steven D'Aprano wrote: On Thu, 17 Sep 2015 01:40 am, Random832 wrote: "in" suggests a relationship between objects of different types (X and "something that can contain X") - all the other comparison operators are meant to work on objects of the same or similar types.

Re: True == 1 weirdness

2015-09-16 Thread Sven R. Kunze
On 16.09.2015 19:36, Random832 wrote: I just had another thought on *why* the other cases make me so uneasy. The reason this is reasonable for simple cases like a > b > c or a < b <= c is that, in their normal meanings, these operations are transitive. a > b and b > c implies a > c. a < b and b

Re: True == 1 weirdness

2015-09-16 Thread Sven R. Kunze
On 16.09.2015 22:55, Random832 wrote: On Wed, Sep 16, 2015, at 16:38, Mark Lawrence wrote: On 16/09/2015 18:41, Sven R. Kunze wrote: On 16.09.2015 19:33, Steven D'Aprano wrote: And with operator overloading, < <= > and => could have any meaning you like: graph = a => b

Re: True == 1 weirdness

2015-09-16 Thread Sven R. Kunze
On 16.09.2015 21:47, Grant Edwards wrote: On 2015-09-16, Sven R. Kunze <srku...@mail.de> wrote: On 16.09.2015 19:46, Grant Edwards wrote: On 2015-09-16, Steven D'Aprano <st...@pearwood.info> wrote: node = left <= ptr => right Exactly. I've no clue what that means. ;)

Re: True == 1 weirdness

2015-09-16 Thread Sven R. Kunze
On 16.09.2015 23:30, Mark Lawrence wrote: Barry John art is also art. So, why does Python not have Barry John art to define graphs and diagrams? Too colorful for a grammer? -- https://mail.python.org/mailman/listinfo/python-list

Re: True == 1 weirdness

2015-09-16 Thread Sven R. Kunze
On 16.09.2015 18:57, Random832 wrote: I think that chaining should be limited to: A) all operators are "=" B) all operators are "is" C) all operators are either >= or > D) all operators are either <= or < That certainly would be a fine guideline. Only use it with all operators the same.

Re: True == 1 weirdness

2015-09-17 Thread Sven R. Kunze
On 17.09.2015 08:39, Gregory Ewing wrote: Sven R. Kunze wrote: Btw. ASCII art is also art. So, why does Python not have ASCII art to define graphs and diagrams? Nowadays it would have to support Unicode art. Mustn't leave out all the world's non-English-speaking artists! How do I debug

Re: True == 1 weirdness

2015-09-17 Thread Sven R. Kunze
On 17.09.2015 23:38, Marko Rauhamaa wrote: Random832 : It being *easier to implement* to have comparison operators be a single class and have chaining apply equally to all of them may be an excuse for the language to allow it, but it's certainly not an excuse for

Re: True == 1 weirdness

2015-09-17 Thread Sven R. Kunze
On 17.09.2015 23:26, Tim Chase wrote: On 2015-09-17 22:46, Sven R. Kunze wrote: Btw. ASCII art is also art. So, why does Python not have ASCII art to define graphs and diagrams? Nowadays it would have to support Unicode art. Mustn't leave out all the world's non-English-speaking artists! How

Re: Writing a module to abstract a REST api

2015-09-17 Thread Sven R. Kunze
Well, I would be interested in seeing such a module as well. Most modules and frameworks, I know, providing REST and interacting with REST are more like traditional SOAP-like web services. You got your functions which have a 1-to-1 correspondence with some resource URLs and that's it.

Re: Python handles globals badly.

2015-09-09 Thread Sven R. Kunze
On 09.09.2015 19:55, Steven D'Aprano wrote: On Wed, 9 Sep 2015 11:09 am, Mario Figueiredo wrote: You know, it is a pointless exercise to try and downplay programming languages (any programming language) that has proven its worth by being generally adopted by the programming community. Adoption

Re: Python handles globals badly.

2015-09-09 Thread Sven R. Kunze
On 09.09.2015 21:00, Chris Angelico wrote: Suppose it's possible, somehow, to design the perfect language. (It isn't, because the best language for a job depends on the job, but suppose it for the nonce.) It is simultaneously more readable than Python, more ugly than Perl, more functional than

Re: Writing a module to abstract a REST api

2015-09-18 Thread Sven R. Kunze
On 18.09.2015 17:28, Joseph L. Casale wrote: So a design pattern I use often is to create Python objects to represent objects returned from what ever api I am abstracting. For example I might create named tuples for static data I dont intend to change or for an object I can both query for and

Re: A little test for you Guys

2015-09-22 Thread Sven R. Kunze
Hmm, why not. :D On 22.09.2015 20:43, Python_Teacher via Python-list wrote: you have 10 minutes Good luck!! 1. What is PEP8 ? A PEP. 2. What are the different ways to distribute some python source code ? unison, rsync, scp, ftp, sftp, samba, http, https, mail, git, 2 Lists

Re: Writing a module to abstract a REST api

2015-09-19 Thread Sven R. Kunze
Hi Joseph, the basic wiring instances together is done via the assignment operator: "=". Like: queue._api = foo. Now, the "queue" knows about its API instance. Question now is, when do you do "="? On 18.09.2015 23:43, Joseph L. Casale wrote: This is where I am going, but how do you perform

Re: How to remove item from heap efficiently?

2016-01-09 Thread Sven R. Kunze
Thanks for your reply. On 08.01.2016 14:26, Peter Otten wrote: Sven R. Kunze wrote: Hi everybody, suppose, I need items sorted by two criteria (say timestamp and priority). For that purpose, I use two heaps (heapq module): heapA # items sorted by timestamp heapB # items sorted by priority

Re: How to remove item from heap efficiently?

2016-01-09 Thread Sven R. Kunze
be thrown away once they are too long in the queue. On Fri, Jan 8, 2016 at 4:22 AM, Sven R. Kunze <srku...@mail.de> wrote: Hi everybody, suppose, I need items sorted by two criteria (say timestamp and priority). For that purpose, I use two heaps (heapq module): heapA # items sorted by tim

Re: graphs

2016-01-09 Thread Sven R. Kunze
Hi Saski, Python's dataset processing machine is *pandas*. Have a look at this cookbook entry here:

How to remove item from heap efficiently?

2016-01-08 Thread Sven R. Kunze
Hi everybody, suppose, I need items sorted by two criteria (say timestamp and priority). For that purpose, I use two heaps (heapq module): heapA # items sorted by timestamp heapB # items sorted by priority Now my actual problem. When popping an item of heapA (that's the oldest item), I need

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

Re: How to remove item from heap efficiently?

2016-01-10 Thread Sven R. Kunze
ing minimum number has highest priority convention. I like Web technology, so no problem here. :) On Fri, Jan 8, 2016 at 10:15 PM, Sven R. Kunze <srku...@mail.de> wrote: Thanks for your suggestion. On 08.01.2016 14:21, srinivas devaki wrote: You can create a single heap with pr

Re: How to remove item from heap efficiently?

2016-01-10 Thread Sven R. Kunze
On 09.01.2016 19:32, Paul Rubin wrote: "Sven R. Kunze" <srku...@mail.de> writes: Basically a task scheduler where tasks can be thrown away once they are too long in the queue. I don't think there's a real nice way to do this with heapq. The computer-sciencey way would

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: 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: 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-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: _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: 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: 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: 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: 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: 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: 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

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 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

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: 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 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,

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 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: 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: 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: 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

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: 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

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:

  1   2   >