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 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 your function into the modules that

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

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: 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, 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 safety. It has the added

Hooking Mechanism when Entering and Leaving a Try Block

2015-08-11 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 wrote: is there something like a hook that a Python mo

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

Re: Hooking Mechanism when Entering and Leaving a Try Block

2015-08-12 Thread Sven R. Kunze
On 13.08.2015 02:45, Chris Angelico wrote: On Thu, Aug 13, 2015 at 6:54 AM, Mark Lawrence 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 somebody's mail to

Re: Hooking Mechanism when Entering and Leaving a Try Block

2015-08-12 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

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 UN

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 run

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 p

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 bre

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

2015-08-30 Thread Sven R. Kunze
28.08.2015 um 18:09 schrieb 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." - E

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 unpacki

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 r

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

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 d

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 bet

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 __set

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 differe

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 method(cls):at

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

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 h

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 Ha

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 con

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

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

Re: Context-aware return

2015-09-10 Thread Sven R. Kunze
On 10.09.2015 20:14, Ben Finney wrote: "Sven R. Kunze" 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. Would you care to re

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 and

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: 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 whether or not they're al

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

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. `is`

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

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 wrote: 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. ;) Ah, well I know that _tha

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

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

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 *actually* using it from a stan

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 art

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 cre

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 d

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 Let's

<    1   2