Re: Ideas about how software should behave (was: replacing `else` with `then` in `for` and `try`)

2017-11-08 Thread Ian Kelly
On Wed, Nov 8, 2017 at 9:31 AM, Chris Angelico wrote: > On Thu, Nov 9, 2017 at 3:19 AM, Ian Kelly wrote: >> I was not referring to the possible future use of yield from for async >> generators; I was referring to the possibility *today* of using "yield >> from" a

Re: Ideas about how software should behave (was: replacing `else` with `then` in `for` and `try`)

2017-11-08 Thread Ian Kelly
On Wed, Nov 8, 2017 at 11:12 AM, Chris Angelico wrote: > On Thu, Nov 9, 2017 at 5:05 AM, Ian Kelly wrote: >> On Wed, Nov 8, 2017 at 9:31 AM, Chris Angelico wrote: >>> On Thu, Nov 9, 2017 at 3:19 AM, Ian Kelly wrote: >>>> I was not referring to the possible futu

Re: Ideas about how software should behave (was: replacing `else` with `then` in `for` and `try`)

2017-11-08 Thread Ian Kelly
On Wed, Nov 8, 2017 at 11:34 AM, Chris Angelico wrote: > On Thu, Nov 9, 2017 at 5:20 AM, Ian Kelly wrote: >> On Wed, Nov 8, 2017 at 11:12 AM, Chris Angelico wrote: >>> Except that "yield from" is used by generators to delegate to other >>> generators,

Re: What is the future of the PEP 467?

2017-11-10 Thread Ian Kelly
On Fri, Nov 10, 2017 at 7:16 AM, Kirill Balunov wrote: > What is the future of the PEP 467 ("Minor API improvements for binary > sequences")? It was not accepted and was not rejected, although there was a > rather active discussion. I don't know. This is probably a question for python-dev. > In

Re: Benefits of unicode identifiers (was: Allow additional separator in identifiers)

2017-11-23 Thread Ian Kelly
On Thu, Nov 23, 2017 at 1:04 PM, Karsten Hilbert wrote: > On Thu, Nov 23, 2017 at 08:46:01PM +0100, Thomas Jollans wrote: > >> > I mean for a real practical situation - for example for an average >> > Python programmer or someone who seeks a programmer job. >> > And who does not have a 500-key key

Re: Benefits of unicode identifiers (was: Allow additional separator in identifiers)

2017-11-23 Thread Ian Kelly
On Thu, Nov 23, 2017 at 2:19 PM, Richard Damon wrote: > The Unicode Standard provides a fairly good classification of the > characters, and it would make sense to define that an character that is > defined as a 'Letter' or a 'Number', and some classes of Punctuation > (connector and dash) be allow

Re: Why does asyncio.wait_for() need a timeout?

2017-11-24 Thread Ian Kelly
On Fri, Nov 24, 2017 at 6:31 AM, Frank Millman wrote: > "Frank Millman" wrote in message news:ov5v3s$bv7$1...@blaine.gmane.org... > >> Below is a simple asyncio loop that runs two background tasks. >> > [...] >> >> >> Both take an optional timeout. >> >> If I use the first method without a timeou

Re: Why does asyncio.wait_for() need a timeout?

2017-11-24 Thread Ian Kelly
On Fri, Nov 24, 2017 at 9:35 AM, Ian Kelly wrote: > On Fri, Nov 24, 2017 at 6:31 AM, Frank Millman wrote: >> "Frank Millman" wrote in message news:ov5v3s$bv7$1...@blaine.gmane.org... >> >>> Below is a simple asyncio loop that runs two background tasks. >

Re: connect four (game)

2017-11-24 Thread Ian Kelly
On Fri, Nov 24, 2017 at 7:05 PM, wrote: > On Friday, November 24, 2017 at 12:13:18 PM UTC-8, Terry Reedy wrote: > >> Since you did not start with tests or write tests as you wrote code, ... > > why on earth would you assume that? instantiate "window" and you'll see it > works exactly as i intend

Re: connect four (game)

2017-11-25 Thread Ian Kelly
On Sat, Nov 25, 2017 at 6:00 AM, bartc wrote: > Where are your unittests for these unittests? Taking this question more seriously than it deserves: the tests for the unittest module itself are at https://hg.python.org/cpython/file/tip/Lib/unittest/test. Yes, unittest has tests of itself. As for

Re: connect four (game)

2017-11-25 Thread Ian Kelly
On Sat, Nov 25, 2017 at 10:02 AM, Chris Angelico wrote: > On Sun, Nov 26, 2017 at 3:36 AM, Ian Kelly wrote: >> On Sat, Nov 25, 2017 at 6:00 AM, bartc wrote: >>> Where are your unittests for these unittests? >> >> No, the point of having unit tests is to build

Re: connect four (game)

2017-11-27 Thread Ian Kelly
On Nov 27, 2017 7:08 AM, "Chris Angelico" wrote: In every compiler, interpreter, and CPU that I've ever used, the remainder has been well-defined. In what situation was it ill-defined, such that different compilers could do different things? In C89 the result of integer division and modulo wit

Re: How to shut down a TCPServer serve_forever() loop?

2017-11-27 Thread Ian Kelly
On Sat, Nov 25, 2017 at 7:10 AM, John Pote wrote: > Hi all, > > My problem in summary is that my use of the shutdown() method only shuts > down a server after the next TCP request is received. > > I have a TCP server created in the run() method of a thread. > > class TCPlistener( Thread ): >

Re: asyncio loop.call_soon()

2017-11-28 Thread Ian Kelly
On Tue, Nov 28, 2017 at 8:30 AM, ast wrote: > Hello > > Python's doc says about loop.call_soon(callback, *arg): > > Arrange for a callback to be called as soon as possible. The callback is > called after call_soon() returns, when control returns to the event loop. > > But it doesn't seem to be tru

Re: How to shut down a TCPServer serve_forever() loop?

2017-11-28 Thread Ian Kelly
On Tue, Nov 28, 2017 at 11:54 AM, Marko Rauhamaa wrote: > Chris Angelico : >> Would the OP have been trivially able to send a signal to the >> process? Yes. > >Python signal handlers are always executed in the main Python thread, >even if the signal was received in another thread. This mea

Re: Lies (was: we want python software)

2017-12-06 Thread Ian Kelly
On Wed, Dec 6, 2017 at 5:53 AM, Rustom Mody wrote: > I was at first surprised and even a bit shocked when people called me > right-wing. > Over time Ive come to accept that lies (left-wing) is upstream of hate > (right-wing). And to the extent that effects must be stemmed from causes, > the wo

Re: Politeness (was: we want python software)

2017-12-06 Thread Ian Kelly
On Wed, Dec 6, 2017 at 9:42 AM, Gene Heskett wrote: > On Wednesday 06 December 2017 11:28:22 Random832 wrote: >> The third possibility is that he believes that this list is official >> in some corporate sense, that if he asks for the software and it is >> not free he will receive a price quote. >

Re: Politeness (was: we want python software)

2017-12-06 Thread Ian Kelly
On Wed, Dec 6, 2017 at 10:56 AM, Gene Heskett wrote: > On Wednesday 06 December 2017 12:14:32 Ian Kelly wrote: > >> On Wed, Dec 6, 2017 at 9:42 AM, Gene Heskett > wrote: >> > On Wednesday 06 December 2017 11:28:22 Random832 wrote: >> >> The third possibility i

Re: asyncio awaitable object

2017-12-08 Thread Ian Kelly
On Fri, Dec 8, 2017 at 2:08 AM, ast wrote: > Hello, > > According to: https://www.python.org/dev/peps/pep-0492/#await-expression > an awaitable object is: > > - A native coroutine object returned from a native coroutine function > - A generator-based coroutine object returned from a function decor

Re: property decorator?

2017-12-20 Thread Ian Kelly
On Wed, Dec 20, 2017 at 5:56 PM, Irv Kalb wrote: > My questions about this are really historical. From my reading, it looks > like using an @property decorator is a reference to an older approach using a > built in "property" function. But here goes: > > 1) Why were these decorator names chose

Re: What is the meaning of @@?

2017-12-22 Thread Ian Kelly
@@ is a syntax error. Where did you encounter this? On Fri, Dec 22, 2017 at 10:38 PM, Peng Yu wrote: > Hi, I only can find the doc for @. What does @@ mean in python? > > -- > Regards, > Peng > -- > https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/

Re: What is the meaning of @@?

2017-12-24 Thread Ian Kelly
On Sun, Dec 24, 2017 at 7:33 PM, Peng Yu wrote: > See for example this file. > > https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/ops/rnn_cell.py > > On Sat, Dec 23, 2017 at 12:03 AM, Steve D'Aprano > wrote: >> On Sat, 23 Dec 2017 04:38 pm, Peng Yu wrote: >> >>> Hi, I only c

Re: Goto (Posting On Python-List Prohibited)

2017-12-30 Thread Ian Kelly
On Sat, Dec 30, 2017 at 8:41 AM, bartc wrote: > (I had introduced a special language feature just for this kind of thing, > but it was unsatisfactory. Goto was simpler and understood by everyone. And > portable to any other language - that hasn't done away with goto. But it > worked like this (not

Re: has sourceforge exposed the dirty little secret ?

2018-01-05 Thread Ian Kelly
On Fri, Jan 5, 2018 at 9:27 AM, Kim of K. wrote: > > "Background > > We feel that the world still produces way too much software that is > frankly substandard. The reasons for this are pretty simple: software > producers do not pay enough attention [...]" > > > quote from http://texttest.sourcefor

Re: is comp.lang.python still the pinnacle of the py community ?

2018-01-05 Thread Ian Kelly
On Fri, Jan 5, 2018 at 2:06 PM, Kim of K. wrote: > > post frequency is down to a precarious level It's true that compared to ten years ago, the quantity of posts here has diminished by a significant fraction, maybe even by an order of magnitude. This is still a great place for discussion however,

Re: Spectre/Meltdown bug affecting Python ?

2018-01-06 Thread Ian Kelly
On Sat, Jan 6, 2018, 4:45 PM Grant Edwards wrote: > On 2018-01-06, Etienne Robillard wrote: > > > > > > Le 2018-01-06 à 15:49, J.O. Aho a écrit : > >> On 01/06/18 13:43, Etienne Robillard wrote: > >>> My understanding of this vulnerability is that speculative indirect > >>> calls in Linux kernel

Re: [OT] Dutch Reach [was Re: Where has the practice of sending screen shots as source code come from?]

2018-01-30 Thread Ian Kelly
On Tue, Jan 30, 2018 at 9:24 AM, Grant Edwards wrote: > On 2018-01-30, Steven D'Aprano wrote: >> On Tue, 30 Jan 2018 15:48:29 +, Matt Wheeler wrote: >> >>> Checking the side mirrors isn't particularly helpful advice if you're >>> sitting in any seat other than the driver's seat, however. >> >

Re: Create an alias to an attribute on superclass

2018-02-01 Thread Ian Kelly
On Thu, Feb 1, 2018 at 11:44 AM, Sean DiZazzo wrote: > On Thursday, February 1, 2018 at 10:37:32 AM UTC-8, Chris Angelico wrote: >> On Fri, Feb 2, 2018 at 5:22 AM, Sean DiZazzo wrote: >> > Hi! >> > >> > I basically just want to create an alias to an attribute on an item's >> > superclass. So th

Re: Problem with coroutines old-style / new-style usage and features

2018-02-01 Thread Ian Kelly
On Thu, Feb 1, 2018 at 5:38 AM, Yahya Abou 'Imran via Python-list wrote: > Hi guys. > > I am discovering coroutines and asynchronous programming, and I have a little > problem with a little example I'm coding myself as an excercice. > > Let say you take two guys in the street: Dave and Bryan. > Y

Re: Why no '|' operator for dict?

2018-02-05 Thread Ian Kelly
On Mon, Feb 5, 2018 at 12:35 AM, Frank Millman wrote: > So I have 2 questions - > > 1. Is there any particular reason why '|' is not supported? '|' is the set union operation, roughly equivalent to the set.union method. Dicts don't have a union operation. If they did, and the same key were found

Re: Python "Bad syntax"

2018-02-05 Thread Ian Kelly
On Mon, Feb 5, 2018 at 10:13 AM, wrote: > > Hi, I have a problem in continuing the function. > > I'm a beginner, I'm learning from a textbook. I'm going to put the following > examples from a textbook that displays "wrong syntax" It would be very helpful if you would copy/paste the exact error m

Re: Does anyone know ni?

2018-02-06 Thread Ian Kelly
It was used for package support and is no longer needed from Python 1.5. http://legacy.python.org/doc/essays/packages.html On Tue, Feb 6, 2018 at 1:27 PM, Roel Schroeven wrote: > I'm having a look at py-iso8211 from > https://sourceforge.net/projects/py-iso8211/ to see if I can get it to work > w

Re: What F strings should have been

2018-02-15 Thread Ian Kelly
On Wed, Feb 14, 2018 at 2:24 PM, D'Arcy Cain wrote: > A recent post by Terry Jan Reedy got me thinking about formatting. I > like the new(ish) format method for strings and I see some value in F > strings but it only works well with locals. Anything more starts > getting messier than format() an

Re: How to run script from interpreter?

2018-02-16 Thread Ian Kelly
On Fri, Feb 16, 2018 at 3:18 PM, windhorn wrote: > Yes, it's been covered, but not quite to my satisfaction. > > Here's an example simple script: > > # Very simple script > bar = 123 > > I save this as "foo.py" somewhere Python can find it > import foo bar > Traceback (most recent call l

Re: Are the critiques in "All the things I hate about Python" valid?

2018-02-17 Thread Ian Kelly
On Fri, Feb 16, 2018 at 9:32 PM, Chris Angelico wrote: > You'd be surprised how rarely that kind of performance even matters. > The author of that article cites C# as a superior language, but in the > rewrite from C# to Python (the same one I mentioned in the other > post), I sped the program up i

Re: Are the critiques in "All the things I hate about Python" valid?

2018-02-20 Thread Ian Kelly
On Tue, Feb 20, 2018 at 8:38 AM, Steven D'Aprano wrote: > On Tue, 20 Feb 2018 15:23:44 +0100, Antoon Pardon wrote: > >>> Okay. Now create a constraint on a name in C++ such that it can only >>> accept integers representing A.D. years which, on the Gregorian >>> calendar, are leap years. (Using a d

Re: Are the critiques in "All the things I hate about Python" valid?

2018-02-21 Thread Ian Kelly
On Tue, Feb 20, 2018 at 10:09 PM, Chris Angelico wrote: > On Wed, Feb 21, 2018 at 6:39 AM, Geldenhuys, J, Prof > wrote: >> I think your case illustrates the Python/Mathematica issue well: you found >> a job for which Mathematica was not the perfect tool and you used Python. >> At the end of

Re: How to make Python run as fast (or faster) than Julia

2018-02-22 Thread Ian Kelly
On Thu, Feb 22, 2018 at 12:55 PM, Jack Fearnley wrote: > I realize that this thread is about benchmarking and not really about > generating fibonacci numbers, but I hope nobody is using this code to > generate them on a 'production' basis, > > Fibonacci numbers, any linearly recursive sequence for

Re: For Loop Dilema [python-list]

2018-02-25 Thread Ian Kelly
On Sun, Feb 25, 2018 at 11:19 AM, wrote: > Why we don’t use: > > for _ in _ in _ > > Instead of > > for _ in _: > for _ in _: > > Ex: > > Names = ["Arya","Pupun"] > > for name in Names: >for c in name: >print(c) > > instead use: > > for c in name in Names: > print(c)

Re: For Loop Dilema [python-list]

2018-02-26 Thread Ian Kelly
On Sun, Feb 25, 2018 at 8:05 PM, INADA Naoki wrote: > https://docs.python.org/3.6/library/itertools.html#itertools.product I don't see how you would use itertools.product to do what the OP asked for. You could use itertools.chain.from_iterable, though: py> names = ['Jack', 'Susan'] py> list(chai

Re: matrix multiplication

2018-02-26 Thread Ian Kelly
On Mon, Feb 26, 2018 at 9:53 AM, Seb wrote: > On Sun, 25 Feb 2018 18:52:14 -0500, > Terry Reedy wrote: > > [...] > >> numpy has a matrix multiply function and now the '@' matrix multiply >> operator. > > Yes, but what I was wondering is whether there's a faster way of > multiplying each row (1x3)

Re: Is there are good DRY fix for this painful design pattern?

2018-02-26 Thread Ian Kelly
On Mon, Feb 26, 2018 at 8:06 AM, Chris Angelico wrote: > On Tue, Feb 27, 2018 at 1:41 AM, Steven D'Aprano > wrote: >> I have a class with a large number of parameters (about ten) assigned in >> `__init__`. The class then has a number of methods which accept >> *optional* arguments with the same n

Re: Is there are good DRY fix for this painful design pattern?

2018-02-26 Thread Ian Kelly
On Mon, Feb 26, 2018 at 1:09 PM, wrote: > def foo(self, *args, **kwargs): > assert len(args) == 0 Better: def foo(self, **kwargs): > So, use the inspect module to detect the valid arguments > from the class initializer. Then use **kwargs in every > class method. It would be nice if

Re: Is there are good DRY fix for this painful design pattern?

2018-02-26 Thread Ian Kelly
On Mon, Feb 26, 2018 at 2:37 PM, Ian Kelly wrote: > On Mon, Feb 26, 2018 at 1:09 PM, wrote: >> def foo(self, *args, **kwargs): >> assert len(args) == 0 > > Better: > > def foo(self, **kwargs): > >> So, use the inspect module to detect t

Re: matrix multiplication

2018-02-26 Thread Ian Kelly
On Mon, Feb 26, 2018 at 2:40 PM, Dan Stromberg wrote: > On Mon, Feb 26, 2018 at 8:53 AM, Seb wrote: >> On Sun, 25 Feb 2018 18:52:14 -0500, >> Terry Reedy wrote: >> >> [...] >> >>> numpy has a matrix multiply function and now the '@' matrix multiply >>> operator. >> >> Yes, but what I was wonderi

Re: matrix multiplication

2018-02-26 Thread Ian Kelly
On Mon, Feb 26, 2018 at 3:12 PM, Dan Stromberg wrote: > On Mon, Feb 26, 2018 at 2:07 PM, Ian Kelly wrote: >> Taking LMGTFY to a whole new level of rudeness by obviously not even >> bothering to read the entire paragraph before responding. > > Is LMGTFY rude? I think mayb

Re: Are the critiques in "All the things I hate about Python" valid?

2018-02-26 Thread Ian Kelly
On Mon, Feb 26, 2018 at 8:09 PM, Steven D'Aprano wrote: > Yes you did: "the last second of every year" is always 23:59:59 of 31st > December, and it is always the same time and date "every year". Except when it's 23:59:60 or 23:59:61 (which hasn't yet happened but could). -- https://mail.python.

Re: Are the critiques in "All the things I hate about Python" valid?

2018-02-26 Thread Ian Kelly
On Mon, Feb 26, 2018 at 8:55 PM, Ian Kelly wrote: > On Mon, Feb 26, 2018 at 8:09 PM, Steven D'Aprano > wrote: >> Yes you did: "the last second of every year" is always 23:59:59 of 31st >> December, and it is always the same time and date "every year"

Re: matrix multiplication

2018-02-27 Thread Ian Kelly
On Tue, Feb 27, 2018 at 4:08 AM, Peter Otten <__pete...@web.de> wrote: > Seb wrote: > >> On Tue, 27 Feb 2018 12:25:30 +1300, >> Gregory Ewing wrote: >> >>> Seb wrote: I was wondering is whether there's a faster way of multiplying each row (1x3) of a matrix by another matrix (3x3), compar

Re: matrix multiplication

2018-02-27 Thread Ian Kelly
On Tue, Feb 27, 2018 at 9:02 AM, Seb wrote: > That's right. I just tried this manipulation by replacing the last > block of code in my example, from the line above `for` loop with: > > ------ > # Alternative using `np.matmul` >

Re: help me ?

2018-02-27 Thread Ian Kelly
On Tue, Feb 27, 2018 at 10:16 AM, Igor Korot wrote: > Congratulations! > You have an "A" for solving the problem and "F" for helping the guy cheat. > You should be expelled from the course. In my experience, this is what happens pretty much every time. Somebody posts a homework question asking fo

Re: help me ?

2018-02-27 Thread Ian Kelly
On Tue, Feb 27, 2018 at 2:50 PM, Andre Müller wrote: > Hello, > > it's a duplicate: > https://python-forum.io/Thread-Working-with-lists-homework-2 > > I have seen this more than one time. We don't like it. You keep people busy > with one question at different places. You assume that it was posted

Re: cute interview problem

2018-02-28 Thread Ian Kelly
On Wed, Feb 28, 2018 at 12:55 PM, wrote: > On Tuesday, 27 February 2018 00:42:02 UTC+1, Paul Rubin wrote: >> Ron Aaron posted the below url on comp.lang.forth. It points to what I >> thought was a cute problem, along with his solution in his Forth dialect >> 8th: >> >> https://8th-dev.com/for

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-01 Thread Ian Kelly
On Wed, Feb 28, 2018 at 8:00 PM, Chris Angelico wrote: > On Thu, Mar 1, 2018 at 1:46 PM, Rick Johnson > wrote: >> On Wednesday, February 28, 2018 at 5:02:17 PM UTC-6, Chris Angelico wrote: >> >>> Here's one example: reference cycles. When do they get detected? >>> Taking a really simple situation

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-01 Thread Ian Kelly
On Wed, Feb 28, 2018 at 9:00 PM, ROGER GRAYDON CHRISTMAN wrote: > > On Wed, Feb 28, 2018, Rick Johnson wrote: > > On Wednesday, February 28, 2018 at 5:02:17 PM UTC-6, Chris Angelico wrote: >> >>> Here's one example: reference cycles. When do they get detected? >>> Taking a really simple situation:

Re: RFC: Proposal: Deterministic Object Destruction

2018-03-01 Thread Ian Kelly
On Thu, Mar 1, 2018 at 10:35 PM, Chris Angelico wrote: > On Fri, Mar 2, 2018 at 4:16 PM, Ian Kelly wrote: >> On Wed, Feb 28, 2018 at 8:00 PM, Chris Angelico wrote: >>> Not off hand, but I can provide an EXTREMELY real-world example of a >>> fairly tight loop: exc

Re: RFC: Proposal: Deterministic Object Destruction (Posting On Python-List Prohibited)

2018-03-03 Thread Ian Kelly
On Fri, Mar 2, 2018 at 9:57 PM, Gregory Ewing wrote: > Paul Rubin wrote: >> >> So you want the programmer to put more head scratching into figuring out >> which reference should be strong and which should be weak? > > > Also, sometimes weak references don't really solve the > problem, e.g. if you

Re: RFC: Proposal: Deterministic Object Destruction (Posting On Python-List Prohibited)

2018-03-03 Thread Ian Kelly
On Sat, Mar 3, 2018 at 9:19 AM, Richard Damon wrote: > One idea does come to mind though, would it be reasonable, and somewhat > Pythonic, for a class to define member functions like __ref__ and __unref__ > (or perhaps some other name) that if defined, would be called every time a > name was bound

Re: cute interview problem

2018-03-03 Thread Ian Kelly
On Sat, Mar 3, 2018 at 3:26 PM, Richard Damon wrote: > On 2/28/18 3:51 PM, Ian Kelly wrote: >> >> On Wed, Feb 28, 2018 at 12:55 PM, wrote: >>> >>> On Tuesday, 27 February 2018 00:42:02 UTC+1, Paul Rubin wrote: >>>> >>>> Ron Aaron post

Re: Python slang

2016-08-10 Thread Ian Kelly
On Aug 10, 2016 4:36 PM, "Lawrence D’Oliveiro" wrote: On Thursday, August 11, 2016 at 5:35:03 AM UTC+12, Rustom Mody wrote: > On Wednesday, August 10, 2016 at 9:31:40 PM UTC+5:30, Anders J. Munch wrote: > Python’s inspiration and origin is ABC > Whose assignment looked like > PUT expr INTO var

Re: I am new to python. I have a few questions coming from an armature!

2016-08-15 Thread Ian Kelly
On Aug 15, 2016 6:57 PM, "Lawrence D’Oliveiro" wrote: Python, on the other hand, introduces the special word “lambda” for this purpose, eschewing its usual “def”. Why? Something to do with GvR’s allergy to anonymous functions... Actually, GvR is on record stating that he's never much cared fo

Re: I am new to python. I have a few questions coming from an armature!

2016-08-16 Thread Ian Kelly
On Aug 16, 2016 12:36 AM, "Lawrence D’Oliveiro" wrote: On Tuesday, August 16, 2016 at 6:26:01 PM UTC+12, Paul Rudin wrote: > sohcahtoa82 writes: >> squared_plus_one_list = map(lambda x: x**2 + 1, some_list) > > I realise that this is about understanding lambda, but it's worth noting > in passing

Re: I am new to python. I have a few questions coming from an armature!

2016-08-16 Thread Ian Kelly
On Aug 16, 2016 12:57 AM, "Lawrence D’Oliveiro" wrote: I see. I thought I saw a mention somewhere else that Python lambdas were designed to be less functional than full def-style functions. But perhaps this limitation wasn’t intentional, just an inherent consequence of the fact that Python’s si

Re: Why monkey patching on module object doesn't work ?

2016-08-17 Thread Ian Kelly
On Wed, Aug 17, 2016 at 10:14 PM, Shiyao Ma wrote: > Hi, > > I am using Python2. > > For the following snippet, > > http://ideone.com/i36pKO > > I'd suppose the dummy_func would be invoked, but seems not. > > Indeed, heapq.heapify does invoke cmp_lt per here: > https://hg.python.org/cpython/file/2

Re: Why don't we call the for loop what it really is, a foreach loop?

2016-09-13 Thread Ian Kelly
On Tue, Sep 13, 2016 at 2:57 PM, wrote: > It would help newbies and prevent confusion. Ada uses "for". C++11 uses "for". Dart uses "for". Go uses "for". Groovy uses "for". Java uses "for". JavaScript uses "for". MATLAB uses "for". Objective-C uses "for". Pasceal uses "for". Perl moved from "fore

Re: Linear Time Tree Traversal Generator

2016-09-21 Thread Ian Kelly
On Tue, Sep 20, 2016 at 11:03 AM, Rob Gaddi wrote: > The only thing that's O(N log N) in that is the number of actual yield > calls. If you're doing pretty much anything with those values as > they're being iterated over then they'll dominate the timing, and that > is O(N). It's fair to say that

Re: Is there a way to change the closure of a python function?

2016-09-27 Thread Ian Kelly
On Tue, Sep 27, 2016 at 8:41 AM, jmp wrote: > On 09/27/2016 04:01 PM, Peng Yu wrote: >> >> Hi, In many other functional language, one can change the closure of a >> function. Is it possible in python? >> >> http://ynniv.com/blog/2007/08/closures-in-python.html >> > > If I understood correctly your

Re: Is there a way to change the closure of a python function?

2016-09-27 Thread Ian Kelly
On Tue, Sep 27, 2016 at 3:19 PM, Terry Reedy wrote: > On 9/27/2016 11:01 AM, Chris Angelico wrote: >> >> On Wed, Sep 28, 2016 at 12:01 AM, Peng Yu wrote: >>> >>> Hi, In many other functional language, one can change the closure of a >>> function. Is it possible in python? >>> >>> http://ynniv.com

Re: Is it possible to use 'groupby' asynchronously?

2016-10-06 Thread Ian Kelly
On Thu, Oct 6, 2016 at 9:57 AM, Chris Angelico wrote: > On Thu, Oct 6, 2016 at 11:09 PM, Frank Millman wrote: >> Hi all >> >> I have used itertools.groupby before, and I love it. I used it to process a >> csv file and 'break' on change of a particular field. It worked very well. >> >> Now I want

Re: Function to take the minimum of 3 numbers

2016-10-09 Thread Ian Kelly
On Oct 9, 2016 2:57 PM, wrote: On Sunday, October 9, 2016 at 2:41:41 PM UTC+1, BartC wrote: > def min3(a,b,c): > if a<=b and a<=c: > return a > elif b<=a and b<=c: > return b > else: > return c The Pythonic way if b >= a <= c: ... Better: if a <=

Re: Inplace shuffle function returns none

2016-10-18 Thread Ian Kelly
On Tue, Oct 18, 2016 at 2:25 PM, Sayth Renshaw wrote: > So why can't i assign the result slice to a variable b? > > It just keeps getting none. Because shuffle returns none. If you want to keep both the original list and the shuffled list, then do something like: b = a[:] shuffle(b) print(a) pri

Re: How to execute "gksudo umount VirtualDVD"

2016-10-27 Thread Ian Kelly
On Thu, Oct 27, 2016 at 3:30 PM, Demosthenes Koptsis wrote: > I want to execute the command "gksudo umount VirtualDVD" > > My code is this but it fails: > > def umount(self): > '''unmounts VirtualDVD''' cmd ='gksudo umount VirtualDVD' proc = > subprocess.Popen(str(cmd),shell=True,stdout=subpro

Re: N-grams

2016-11-09 Thread Ian Kelly
On Wed, Nov 9, 2016 at 6:38 AM, Steve D'Aprano wrote: > And here's an implementation for arbitrary n-grams: > > > def ngrams(iterable, n=2): > if n < 1: > raise ValueError > t = tee(iterable, n) > for i, x in enumerate(t): > for j in range(i): > next(x, None

Re: Python rules!

2016-11-09 Thread Ian Kelly
On Nov 9, 2016 5:48 PM, "Michael Torrie" wrote: On 11/09/2016 12:39 PM, jlada...@itu.edu wrote: > On Wednesday, November 9, 2016 at 4:32:15 AM UTC-8, Rustom Mody wrote: >> https://twitter.com/UdellGames/status/788690145822306304 > > It took me a minute to see it. That's insane! Yeah it is... ho

Re: N-grams

2016-11-09 Thread Ian Kelly
On Wed, Nov 9, 2016 at 7:06 PM, Paul Rubin wrote: > This can probably be cleaned up some: Okay. :-) > from itertools import islice > from collections import deque > > def ngram(n, seq): Looks like "seq" can be any iterable, not just a sequence. > it = iter(seq) > d

Re: how to multiply two matrices with different size?

2016-11-18 Thread Ian Kelly
On Fri, Nov 18, 2016 at 6:51 PM, wrote: > Hi :) > I'm trying to multiply two matrices that has different size. > > -code- > > import numpy as np > > a = np.random.randn(4, 3) > b = np.random.randn(4, 1) > > print a > print b > >

Re: How to append a modified list into a list?

2016-11-18 Thread Ian Kelly
On Nov 18, 2016 6:47 PM, wrote: I have a working list 'tbl' and recording list 'm'. I want to append 'tbl' into 'm' each time when the 'tbl' was modified. I will record the change by append it through the function 'apl'. For example: >>>tbl=[0,0] >>>m=[] >>>tbl[0]=1 >>>apl(tbl) >>>m [[1,0]] >

Re: Extra base class in hierarchy

2016-11-19 Thread Ian Kelly
On Nov 19, 2016 11:22 AM, "Victor Porton" wrote: Consider class FinalTreeNode(object): def childs(self): return [] class UsualTreeNode(FinalTreeNode) def childs(self): return ... In this structure UsualTreeNode derives from FinalTreeNode. This looks odd because "final

Re: The Case Against Python 3

2016-11-26 Thread Ian Kelly
On Fri, Nov 25, 2016 at 1:29 AM, Mark Summerfield wrote: > The article has a section called: > > "Too Many Formatting Options" > > He's right! The % formatting was kept to help port old code, the new > .format() which is far more versatile is a bit verbose, so finally they've > settled on f-

Re: Asyncio -- delayed calculation

2016-11-28 Thread Ian Kelly
On Mon, Nov 28, 2016 at 5:48 AM, Steve D'Aprano wrote: > Let's pretend that the computation can be performed asynchronously, so that > I can have all five Counter objects counting down in parallel. I have this: > > > import asyncio > > class Counter: > def __init__(self): > self.count

Re: async enumeration - possible?

2016-11-29 Thread Ian Kelly
On Tue, Nov 29, 2016 at 7:25 AM, Frank Millman wrote: > However, it does not allow you to enumerate over the generator output - > async def main(): > > ... c = counter(5) > ... async for j, k in enumerate(c): > ... print(j, k) > ... print('done') > ... loop.run_until_compl

Re: Asyncio -- delayed calculation

2016-11-29 Thread Ian Kelly
On Mon, Nov 28, 2016 at 10:42 PM, Chris Angelico wrote: > On Tue, Nov 29, 2016 at 4:13 PM, Paul Rubin wrote: >> >> I haven't gotten my head around Python asyncio and have been wanting >> to read this: >> >>http://lucumr.pocoo.org/2016/10/30/i-dont-understand-asyncio/ > > It's talking a lot ab

Re: async enumeration - possible?

2016-11-30 Thread Ian Kelly
On Tue, Nov 29, 2016 at 8:22 PM, Chris Angelico wrote: > Interestingly, I can't do that in a list comp: > [x async for x in aiterable] > File "", line 1 > [x async for x in aiterable] >^ > SyntaxError: invalid syntax > > Not sure why. Because you tried to use an async compr

Re: async enumeration - possible?

2016-11-30 Thread Ian Kelly
On Wed, Nov 30, 2016 at 12:53 AM, Marko Rauhamaa wrote: > I have a couple of points to make with my question: > > * We are seeing the reduplication of a large subset of Python's >facilities. I really wonder if the coroutine fad is worth the price. I don't think there's any technical reason w

Re: async enumeration - possible?

2016-11-30 Thread Ian Kelly
On Wed, Nov 30, 2016 at 1:20 AM, Chris Angelico wrote: > Hmm. The thing is, comprehensions and generators are implemented with > their own nested functions. So I would expect that their use of async > is independent of the function they're in. But maybe we have a bug > here? > async def spam(

Re: async enumeration - possible?

2016-11-30 Thread Ian Kelly
On Wed, Nov 30, 2016 at 1:29 AM, Frank Millman wrote: > "Marko Rauhamaa" wrote in message news:87d1hd4d5k@elektro.pacujo.net... >> >> >> One of the more useful ones might be: >> >> o = await anext(ait) >> > > Definitely! > > But I found it easy to write my own - > > async def anext(aiter)

Re: async enumeration - possible?

2016-11-30 Thread Ian Kelly
On Wed, Nov 30, 2016 at 2:28 AM, Marko Rauhamaa wrote: > "Frank Millman" : > >> "Marko Rauhamaa" wrote in message news:87d1hd4d5k@elektro.pacujo.net... >>> I don't think bulk iteration in asynchronous programming is ever that >>> great of an idea. You want to be prepared for more than one

Re: Timer runs only once.

2016-11-30 Thread Ian Kelly
On Wed, Nov 30, 2016 at 8:06 AM, siva gnanam wrote: > On Wednesday, November 30, 2016 at 8:11:49 PM UTC+5:30, vnthma...@gmail.com > wrote: >> from threading import Timer >> >> class TestTimer: >> def foo(self): >> print("hello world") >> self.startTimer() >> >> def startTi

Re: async enumeration - possible?

2016-11-30 Thread Ian Kelly
On Wed, Nov 30, 2016 at 5:05 PM, Steve D'Aprano wrote: > On Wed, 30 Nov 2016 07:51 pm, Ian Kelly wrote: > >> On Wed, Nov 30, 2016 at 1:29 AM, Frank Millman wrote: > >>> But I found it easy to write my own - >>> >>> async def anext(aiter): >>&

Re: async enumeration - possible?

2016-11-30 Thread Ian Kelly
On Wed, Nov 30, 2016 at 8:34 PM, Ian Kelly wrote: > To be pedantic, it should be more like: > > return type(aiter).__dict__['__anext__']() And of course, if you don't find it there then to be proper you also have to walk the MRO and check all of those class

Re: Asyncio -- delayed calculation

2016-12-01 Thread Ian Kelly
On Thu, Dec 1, 2016 at 12:53 AM, Christian Gollwitzer wrote: > well that works - but I think it it is possible to explain it, without > actually understanding what it does behind the scences: > > x = foo() > # schedule foo for execution, i.e. put it on a TODO list This implies that if you never a

Re: When will they fix Python _dbm?

2016-12-06 Thread Ian Kelly
On Mon, Dec 5, 2016 at 7:45 AM, clvanwall wrote: > I have been a Perl programmer for 15+ years and decided to give Python a try. > My platform is windows and I installed the latest 3.5.2. Next I decided to > convert a perl program that uses a ndbm database since according to the doc > on pytho

Re: When will they fix Python _dbm?

2016-12-06 Thread Ian Kelly
On Dec 6, 2016 4:04 PM, wrote: On Tuesday, December 6, 2016 at 9:35:19 PM UTC, Ian wrote: > On Mon, Dec 5, 2016 at 7:45 AM, clvanwall wrote: > > I have been a Perl programmer for 15+ years and decided to give Python a try. My platform is windows and I installed the latest 3.5.2. Next I decided t

Re: % string formatting - what special method is used for %d?

2016-12-10 Thread Ian Kelly
On Sat, Dec 10, 2016 at 11:40 PM, Veek M wrote: > Well take a look at this: > ### > #!/usr/bin/python > > class Foo(int): > def __init__(self, value): > self.value = value > > def __str__(self): > print '__str__' > return str(

Re: asyncio question

2016-12-13 Thread Ian Kelly
On Tue, Dec 13, 2016 at 6:15 AM, Frank Millman wrote: > The client uses AJAX to send messages to the server. It sends the message > and continues processing, while a background task waits for the response and > handles it appropriately. As a result, the client can send a second message > before re

Re: Recipe request: asyncio "spin off coroutine"

2016-12-14 Thread Ian Kelly
On Wed, Dec 14, 2016 at 12:53 PM, Chris Angelico wrote: > On Thu, Dec 15, 2016 at 6:27 AM, Marko Rauhamaa wrote: >> Chris Angelico : >> >>> asyncio.spin_off(parallel()) # ??? >>> >>> [...] >>> >>> What code should go on the "???" line to accomplish this? >> >> asyncio.ensure_future(parallel()

Re: Python constructors have particular semantics, and ‘Foo.__init__’ doesn't qualify

2016-12-15 Thread Ian Kelly
On Thu, Dec 15, 2016 at 11:05 AM, Terry Reedy wrote: > On 12/14/2016 11:14 PM, Thomas 'PointedEars' Lahn wrote: > >> According to >> , >> “Foo.__init__” is _not_ an instance method. Were it an instance >> method, the following would

Re: Metaclasses - magic functions

2016-12-20 Thread Ian Kelly
On Tue, Dec 20, 2016 at 2:04 PM, Mr. Wrobel wrote: > Hi, > > Quick question, can anybody tell me when to use __init__ instead of __new__ > in meta programming? > > I see that __new__ can be used mostly when I want to manipulate with class > variables that are stored into dictionary. > > But when t

Re: US/Eastern offset

2016-12-22 Thread Ian Kelly
On Thu, Dec 22, 2016 at 2:49 PM, Skip Montanaro wrote: > In a small application I realized I needed all my timestamps to have > timezone info. Some timestamp strings come in with no TZ markings, but > I know they are US/Eastern. so, I built one: > import pytz tz = pytz.timezone("US/Easte

Re: US/Eastern offset

2016-12-22 Thread Ian Kelly
On Thu, Dec 22, 2016 at 4:19 PM, Ian Kelly wrote: > On Thu, Dec 22, 2016 at 2:49 PM, Skip Montanaro > wrote: >> In a small application I realized I needed all my timestamps to have >> timezone info. Some timestamp strings come in with no TZ markings, but >> I know th

<    7   8   9   10   11   12   13   14   15   16   >