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

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

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

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') > ...

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

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

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

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

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

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

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

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

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

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 =

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:

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.

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

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

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

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

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

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

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

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

2016-08-16 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

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

Re: Python slang

2016-08-06 Thread Ian Kelly
On Aug 6, 2016 3:36 PM, "Michael Torrie" wrote: Sadly it has become an epidemic of late for folks to misuse the word, "myself." I think it comes from people not wanting to sound presumptuous when referring to themselves. It drives me crazy to hear so many people say

Re: How do I make a game in Python ?

2016-08-06 Thread Ian Kelly
On Aug 6, 2016 11:57 AM, "Cai Gengyang" wrote: How do I make a game in Python ? import random answer = random.randint(0, 100) while True: guess = input("What number am I thinking of? ") if int(guess) == answer: print("Correct!") break

Re: Python slang

2016-08-06 Thread Ian Kelly
On Aug 6, 2016 2:10 PM, "Marco Sulla via Python-list" < python-list@python.org> wrote: Yes, I was thinking manly to SQL. That furthermore is NOT a programming language. Why not? It's claimed to be Turing complete. http://beza1e1.tuxen.de/articles/accidentally_turing_complete.html --

Re: Can math.atan2 return INF?

2016-08-01 Thread Ian Kelly
On Sun, Jul 31, 2016 at 10:05 PM, Rustom Mody wrote: > All starts with the disorder in the middle-east and a whole lot of arbitrary > lines > drawn there > [Going backward in time] > - A line drawn in space called ‘Israel’ > - Based on a line drawn in time called the

Re: use import *

2016-08-01 Thread Ian Kelly
On Mon, Aug 1, 2016 at 9:31 AM, Ganesh Pal wrote: > Hi Team , > > I am a Linux user on python 2,6 . I have a very simple question > > I was going the zen of python by Tim peters and found an example that > demonstrates Explicit is better than implicit > > """Load the cat,

Re: Learning Descriptors

2016-07-31 Thread Ian Kelly
On Sun, Jul 31, 2016 at 6:33 AM, Gerald Britton wrote: > Today, I was reading RH's Descriptor HowTo Guide at > > https://docs.python.org/3/howto/descriptor.html?highlight=descriptors > > I just really want to fully "get" this. > > So I put together a little test from

Re: Why not allow empty code blocks?

2016-07-31 Thread Ian Kelly
On Sun, Jul 31, 2016 at 1:51 AM, Marko Rauhamaa wrote: > It is quite astounding how Lisp is steadily being reinvented by the > down-to-earth programming community. It was famously observed by Paul > Graham in 2002 (http://www.paulgraham.com/icad.html>). The > evolution has kept

Re: Call function via literal name

2016-07-29 Thread Ian Kelly
On Fri, Jul 29, 2016 at 2:35 PM, TUA wrote: > Rather than do this: > > if test['method'] == 'GET': > res = requests.get(test['endpoint'],auth=test['auth'], > verify=False) > elif test['method'] == 'POST': > res =

Re: Why not allow empty code blocks?

2016-07-29 Thread Ian Kelly
On Jul 29, 2016 7:22 AM, "BartC" wrote: > > On 29/07/2016 12:14, D'Arcy J.M. Cain wrote: >> >> On Fri, 29 Jul 2016 10:58:35 +0200 >> Antoon Pardon wrote: >>> >>> As BartC already mentions it happens fairly often during debugging. >>> Something like.

Re: Python Print Error

2016-07-28 Thread Ian Kelly
On Thu, Jul 28, 2016 at 11:40 AM, Cai Gengyang wrote: > How to debug this ? > print "This line will be printed." This is Python 2 print statement syntax. > SyntaxError: Missing parentheses in call to 'print' This indicates that you're trying to run the above in

Re: How asyncio works? and event loop vs exceptions

2016-07-23 Thread Ian Kelly
On Fri, Jul 22, 2016 at 6:27 PM, Marco S. via Python-list wrote: > Furthermore I have a question about exceptions in asyncio. If I > understand well how it works, tasks exceptions can be caught only if > you wait for task completion, with yield from, await or >

Re: reversed(enumerate(x))

2016-07-21 Thread Ian Kelly
On Wed, Jul 20, 2016 at 11:54 AM, Brendan Abel <007bren...@gmail.com> wrote: > You could create your own generator that wraps enumerate > > def reverse_enumerate(iterable): > for i, val in enumerate(reversed(iterable)): > yield len(iterable) - 1 - i, val > > for i, val in

Re: reversed(enumerate(x))

2016-07-21 Thread Ian Kelly
On Wed, Jul 20, 2016 at 1:16 PM, Random832 <random...@fastmail.com> wrote: > On Wed, Jul 20, 2016, at 13:42, Ian Kelly wrote: >> I had occasion to write something like this: >> >> for i, n in reversed(enumerate(x)): pass >> >> How would you write this? &g

reversed(enumerate(x))

2016-07-20 Thread Ian Kelly
I had occasion to write something like this: for i, n in reversed(enumerate(x)): pass Of course this fails with "TypeError: argument to reversed() must be a sequence". I ended up using this instead: for i, n in zip(reversed(range(len(x))), reversed(x)): pass This works but is

Re: What exactly is "exact" (was Clean Singleton Docstrings)

2016-07-19 Thread Ian Kelly
On Tue, Jul 19, 2016 at 2:35 PM, Gene Heskett wrote: > And I am not familiar with this foot-poundals per second that you > question about, but just from the wording I'd say it is a fifty dollar > way to say horsepower. https://en.wikipedia.org/wiki/Foot-poundal > Which is

Re: an error

2016-07-19 Thread Ian Kelly
On Tue, Jul 19, 2016 at 12:07 AM, WePlayGames WeEnjoyIt wrote: >pygame1.blit(image3,(143,146) This line is missing a closing parenthesis. -- https://mail.python.org/mailman/listinfo/python-list

Re: What exactly is "exact" (was Clean Singleton Docstrings)

2016-07-18 Thread Ian Kelly
On Mon, Jul 18, 2016 at 9:55 AM, Marko Rauhamaa <ma...@pacujo.net> wrote: > Marko Rauhamaa <ma...@pacujo.net>: > >> Ian Kelly <ian.g.ke...@gmail.com>: >>> Off-topic, c being a fundamental constant is actually in the latter >>> category. Its *e

Re: What exactly is "exact" (was Clean Singleton Docstrings)

2016-07-18 Thread Ian Kelly
On Mon, Jul 18, 2016 at 3:29 AM, Steven D'Aprano wrote: > On Monday 18 July 2016 14:16, Rustom Mody wrote: >> In short one could think of inexact and exact — in scheme's intended >> semantics — as better called scientific (or science-ic) and mathematic >>

Re: Curious Omission In New-Style Formats

2016-07-14 Thread Ian Kelly
On Jul 14, 2016 11:37 AM, "Marko Rauhamaa" <ma...@pacujo.net> wrote: > > Ian Kelly <ian.g.ke...@gmail.com>: > > On Thu, Jul 14, 2016 at 10:02 AM, Marko Rauhamaa <ma...@pacujo.net> wrote: > >>In American English, the original word for [signific

Re: Curious Omission In New-Style Formats

2016-07-14 Thread Ian Kelly
On Thu, Jul 14, 2016 at 10:02 AM, Marko Rauhamaa <ma...@pacujo.net> wrote: > Ian Kelly <ian.g.ke...@gmail.com>: > >> The significand of -3.14159 is the sequence of digits 314159. The >> mantissa of -3.14159 is the number 0.85841. > > Fight it all you want.

Re: Curious Omission In New-Style Formats

2016-07-14 Thread Ian Kelly
On Jul 14, 2016 1:52 AM, "Steven D'Aprano" <steve+comp.lang.pyt...@pearwood.info> wrote: > > On Thursday 14 July 2016 15:18, Ian Kelly wrote: > > > Side note, neither do floating point numbers, really; what is often > > called the mantissa is m

Re: Curious Omission In New-Style Formats

2016-07-13 Thread Ian Kelly
On Wed, Jul 13, 2016 at 9:39 PM, Lawrence D’Oliveiro wrote: > On Thursday, July 14, 2016 at 12:46:26 PM UTC+12, Ian wrote: >> On Wed, Jul 13, 2016 at 4:24 PM, Lawrence D’Oliveiro wrote: >>> On Wednesday, July 13, 2016 at 6:22:31 PM UTC+12, Ian wrote: >>> ... don't

Re: Curious Omission In New-Style Formats

2016-07-13 Thread Ian Kelly
On Wed, Jul 13, 2016 at 4:24 PM, Lawrence D’Oliveiro wrote: > On Wednesday, July 13, 2016 at 6:22:31 PM UTC+12, Ian wrote: > >> ... don't call it "precision". > > How about “mantissa length”, then. That sufficiently neutral for you? That makes even less sense for

Re: Clean Singleton Docstrings

2016-07-13 Thread Ian Kelly
On Wed, Jul 13, 2016 at 5:54 PM, Peter Otten <__pete...@web.de> wrote: > Lawrence D’Oliveiro wrote: > >> On Friday, July 8, 2016 at 7:38:56 PM UTC+12, Peter Otten wrote: >> >>> There is a test >>> >>> if not object: >>> raise ImportError('no Python documentation found for %r' % thing) >>> >>>

Re: Python Byte Code Hacking

2016-07-13 Thread Ian Kelly
On Wed, Jul 13, 2016 at 12:48 PM, Vijay Kumar wrote: > Hi Everyone, > I wrote an article on Python byte code hacking. The article is available > from http://www.bravegnu.org/blog/python-byte-code-hacks.html The article > uses an incremental approach for explaining

Re: Curious Omission In New-Style Formats

2016-07-13 Thread Ian Kelly
On Mon, Jul 11, 2016 at 9:38 PM, Steven D'Aprano wrote: > For integers, printf and % interpret the so-called "precision" field of the > format string not as a measurement precision (number of decimal places), > but as the number of digits to use (which is different from the

Re: Compression of random binary data

2016-07-12 Thread Ian Kelly
On Tue, Jul 12, 2016 at 11:35 AM, wrote: > > No it is only compressible down to a limit given by the algorithm. Then your algorithm does not compress random data as you claimed. For some input, determine the limiting output that it ultimately compresses down to. Take

Re: Curious Omission In New-Style Formats

2016-07-11 Thread Ian Kelly
On Mon, Jul 11, 2016 at 5:47 PM, Gregory Ewing wrote: > Ethan Furman wrote: >> >> I will readily admit to not having a maths degree, and so of course to me >> saying the integer 123 has a precision of 5, 10, or 99 digits seems like >> hogwash to me. > > > Seems to me

Re: Curious Omission In New-Style Formats

2016-07-11 Thread Ian Kelly
On Mon, Jul 11, 2016 at 12:54 PM, Terry Reedy wrote: > In any case, I think it an improvement to say that '0x00123' has a field > width of 7 rather than a 'precision' of 5. > '{:#07x}'.format(0x123) # specifiy field width > '0x00123' "%#0.5x" % 0x123 # specify int

Re: Curious Omission In New-Style Formats

2016-07-11 Thread Ian Kelly
On Mon, Jul 11, 2016 at 10:28 AM, Steven D'Aprano <st...@pearwood.info> wrote: > On Tue, 12 Jul 2016 01:04 am, Ian Kelly wrote: >> Your example showed a 3-digit number being formatted with a requested >> precision of 5 digits. The way this was done was by left-padding the &g

Re: Curious Omission In New-Style Formats

2016-07-11 Thread Ian Kelly
On Sun, Jul 10, 2016 at 6:34 PM, Lawrence D’Oliveiro wrote: > On Sunday, July 10, 2016 at 7:22:42 PM UTC+12, Ian wrote: >> On Sat, Jul 9, 2016 at 11:54 PM, Lawrence D’Oliveiro wrote: >>> In printf-style formats, you can specify the number of digits for an >>> integer

Re: one command on backslash and space for review

2016-07-10 Thread Ian Kelly
On Sun, Jul 10, 2016 at 9:19 AM, Ganesh Pal wrote: > Hello Team, > > I am on python 2.7 and Linux , I want to form the below sample > command so that I could run it on the shell. > > Command is --> run_parallel -za1 -s 'daemon -cf xyz; sleep 1' > > Here is how I formed

Re: Quick poll: gmean or geometric_mean

2016-07-10 Thread Ian Kelly
On Sun, Jul 10, 2016 at 9:03 AM, Marko Rauhamaa <ma...@pacujo.net> wrote: > Ian Kelly <ian.g.ke...@gmail.com>: > >> That's still excessive by any reasonable standards. Names should be >> descriptive, but no more verbose than necessary. How about: >> &

Re: Quick poll: gmean or geometric_mean

2016-07-10 Thread Ian Kelly
On Sun, Jul 10, 2016 at 2:01 AM, Jussi Piitulainen <jussi.piitulai...@helsinki.fi> wrote: > Ian Kelly <ian.g.ke...@gmail.com> writes: > >> On Sat, Jul 9, 2016 at 3:45 PM, Chris Angelico <ros...@gmail.com> wrote: >>> On Sat, Jul 9, 2016 at 3:26 PM, Stev

Re: Quick poll: gmean or geometric_mean

2016-07-10 Thread Ian Kelly
On Sun, Jul 10, 2016 at 8:29 AM, Rustom Mody wrote: > Newton's law F = -Gm₁m₂/r² > > Better seen in its normal math form: > https://en.wikipedia.org/wiki/Newton%27s_law_of_universal_gravitation#Modern_form > > De-abbreviated > > Force is given by the negative of the

Re: Quick poll: gmean or geometric_mean

2016-07-10 Thread Ian Kelly
On Sat, Jul 9, 2016 at 3:45 PM, Chris Angelico wrote: > On Sat, Jul 9, 2016 at 3:26 PM, Steven D'Aprano wrote: >> I'd like to get a quick show of hands regarding the names. Which do you >> prefer? >> >> hmean and gmean >> >> harmonic_mean and geometric_mean

Re: Curious Omission In New-Style Formats

2016-07-10 Thread Ian Kelly
On Sat, Jul 9, 2016 at 11:54 PM, Lawrence D’Oliveiro wrote: > In printf-style formats, you can specify the number of digits for an integer > separately from the field width. E.g. > > >>> "%#0.5x" % 0x123 > '0x00123' > > but not in new-style formats: > > >>>

Re: Making Classes Subclassable

2016-07-05 Thread Ian Kelly
On Mon, Jul 4, 2016 at 2:34 AM, Lawrence D’Oliveiro wrote: > On Monday, July 4, 2016 at 7:58:07 PM UTC+12, dieter wrote: >> --> "type(obj)" or "obj.__class__" (there are small differences) >> give you the type/class of "obj". > > When would it not be the same? I think the

Re: Making Classes Subclassable

2016-07-05 Thread Ian Kelly
On Mon, Jul 4, 2016 at 1:57 AM, dieter wrote: > Lawrence D’Oliveiro writes: > >> Some of the classes in Qahirah, my Cairo binding >> I found handy to reuse elsewhere, for >> example in my binding for Pixman

Re: Making Classes Subclassable

2016-07-05 Thread Ian Kelly
On Tue, Jul 5, 2016 at 2:31 AM, Steven D'Aprano wrote: > On Monday 04 July 2016 18:34, Lawrence D’Oliveiro wrote: > >> On Monday, July 4, 2016 at 7:58:07 PM UTC+12, dieter wrote: >>> --> "type(obj)" or "obj.__class__" (there are small differences) >>> give

Re: Nested class doesn't see class scope

2016-07-04 Thread Ian Kelly
On Mon, Jul 4, 2016 at 10:41 PM, Ian Kelly <ian.g.ke...@gmail.com> wrote: > On Mon, Jul 4, 2016 at 9:20 PM, Steven D'Aprano <st...@pearwood.info> wrote: >> I got this in Python 3.6: >> >> >> py> class A: >> ... var = 999 >> ... print

Re: Nested class doesn't see class scope

2016-07-04 Thread Ian Kelly
On Mon, Jul 4, 2016 at 9:20 PM, Steven D'Aprano wrote: > I got this in Python 3.6: > > > py> class A: > ... var = 999 > ... print(var) # succeeds > ... class B: > ... x = var > ... > 999 > Traceback (most recent call last): > File "", line 1, in >

Re: Nested class doesn't see class scope

2016-07-04 Thread Ian Kelly
On Mon, Jul 4, 2016 at 9:42 PM, Paul Rubin wrote: > Steven D'Aprano writes: >> ... class B: >> ... x = var > > x = A.var Nope. A doesn't exist yet at this point. -- https://mail.python.org/mailman/listinfo/python-list

Re: Meta decorator with parameters, defined in explicit functions

2016-07-03 Thread Ian Kelly
On Sun, Jul 3, 2016 at 6:06 PM, Lawrence D’Oliveiro wrote: > On Monday, July 4, 2016 at 12:02:23 PM UTC+12, Ian wrote: >> I'm talking about the docstring of the *decorator*, not func. > > *Sigh*. Originally somebody was complaining that the lambda version didn’t > allow

Re: Meta decorator with parameters, defined in explicit functions

2016-07-03 Thread Ian Kelly
On Sun, Jul 3, 2016 at 5:25 PM, Lawrence D’Oliveiro wrote: > On Monday, July 4, 2016 at 10:39:30 AM UTC+12, Ian wrote: >> Sorry, but you're the one who doesn't seem to get it. Because it's a >> decorator, "your" function is replacing the caller's function in the >>

Re: Meta decorator with parameters, defined in explicit functions

2016-07-03 Thread Ian Kelly
On Sun, Jul 3, 2016 at 3:17 PM, Lawrence D’Oliveiro wrote: > On Sunday, July 3, 2016 at 11:53:46 PM UTC+12, Ian wrote: >> On Sat, Jul 2, 2016 at 11:37 PM, Lawrence D’Oliveiro wrote: >>> That is a function that I am generating, so naturally I want to give it a >>> useful

Re: Special attributes added to classes on creation

2016-07-03 Thread Ian Kelly
On Sun, Jul 3, 2016 at 10:02 AM, Steven D'Aprano wrote: > If I then try it against two identical (apart from their names) classes, I > get these results: > > > py> @process > ... class K: > ... x = 1 > ... > ['__dict__', '__doc__', '__module__', '__weakref__', 'x'] > py>

Re: Meta decorator with parameters, defined in explicit functions

2016-07-03 Thread Ian Kelly
On Sat, Jul 2, 2016 at 11:37 PM, Lawrence D’Oliveiro wrote: > On Sunday, July 3, 2016 at 4:49:15 PM UTC+12, Ian wrote: >> >> On Sat, Jul 2, 2016 at 12:40 AM, Lawrence D’Oliveiro wrote: >>> >>> On Saturday, July 2, 2016 at 5:10:06 PM UTC+12, Ian wrote: You should

Re: Meta decorator with parameters, defined in explicit functions

2016-07-02 Thread Ian Kelly
On Sat, Jul 2, 2016 at 12:40 AM, Lawrence D’Oliveiro wrote: > On Saturday, July 2, 2016 at 5:10:06 PM UTC+12, Ian wrote: >> You should use functools.wraps instead of clobbering the decorated >> function's name and docstring: > > Where am I doing that? Using the

Re: Lost in descriptor land

2016-07-02 Thread Ian Kelly
On Sat, Jul 2, 2016 at 5:32 AM, Ankush Thakur wrote: > On Friday, July 1, 2016 at 9:13:19 AM UTC+5:30, Lawrence D’Oliveiro wrote: >> >> > Shouldn't we be instead using self.celcius in, say, __init__() and then >> > everything will work fine? >> >> I guess it might. But

Re: Descriptor: class name precedence over instance name

2016-07-02 Thread Ian Kelly
On Sat, Jul 2, 2016 at 3:34 AM, Veek. M wrote: > So essentially from what Ian said: > data_descriptor_in_instance -> instance_attribute -> non- > data_descriptor_in_instance -->__mro__ > > is how the search takes place. Correct? Close, but I would write it as:

Re: Meta decorator with parameters, defined in explicit functions

2016-07-01 Thread Ian Kelly
On Fri, Jul 1, 2016 at 11:32 PM, Ben Finney <ben+pyt...@benfinney.id.au> wrote: > Ian Kelly <ian.g.ke...@gmail.com> writes: > >> You should use functools.wraps instead of clobbering the decorated >> function's name and docstring: >> >> @functool

Re: Meta decorator with parameters, defined in explicit functions

2016-07-01 Thread Ian Kelly
On Fri, Jul 1, 2016 at 4:08 PM, Lawrence D’Oliveiro wrote: > On Tuesday, June 28, 2016 at 5:03:08 PM UTC+12, Ben Finney wrote: >> There is a clever one-line decorator that has been copy-pasted without >> explanation in many code bases for many years:: >> >>

Re: Descriptor: class name precedence over instance name

2016-07-01 Thread Ian Kelly
On Fri, Jul 1, 2016 at 10:27 PM, Veek. M wrote: > Trying to make sense of this para: > > -- > Also, the attribute name used by the class to hold a descriptor takes > prece- dence over attributes stored on instances. > > In the

Re: Lost in descriptor land

2016-06-30 Thread Ian Kelly
On Thu, Jun 30, 2016 at 7:06 PM, Ankush Thakur wrote: > Hello, > > There's something I don't understand about descriptors. On a StackOverflow > discussion > (http://stackoverflow.com/questions/12846116/python-descriptor-vs-property) > one of the answers provides the

Re: Iteration, while loop, and for loop

2016-06-30 Thread Ian Kelly
On Wed, Jun 29, 2016 at 5:59 PM, Steven D'Aprano wrote: > But there's no need to go to such effort for a mutable iterator. This is > much simpler: > > py> mi = list('bananas') > py> for char in mi: > ... if char == 'a': > ... mi.extend(' yum') > ...

Re: Iteration, while loop, and for loop

2016-06-30 Thread Ian Kelly
On Wed, Jun 29, 2016 at 5:59 PM, Steven D'Aprano wrote: > I'm curious what REPL you are using, because in the vanilla Python > interactive interpreter, the output if over-written by the prompt. That is, > what I see in Python 3.6 is: > > py> nas yum yum yumpy> > > unless I

Re: Iteration, while loop, and for loop

2016-06-29 Thread Ian Kelly
On Tue, Jun 28, 2016 at 11:58 AM, Grant Edwards wrote: > On 2016-06-28, Tim Chase wrote: >> On 2016-06-29 01:20, Steven D'Aprano wrote: >>> While loops are great for loops where you don't know how many >>> iterations there will be but you

Re: Assignment Versus Equality

2016-06-28 Thread Ian Kelly
On Tue, Jun 28, 2016 at 10:39 AM, Marko Rauhamaa wrote: > > (sorry for the premature previous post) > > Random832 : >> All objects, not just black holes, have those properties. The point >> here is that we are in fact observing those properties of an

Re: is there a concurrent list for append in parallel programming in python? how to pass parameter in this parallel program with pool?

2016-06-21 Thread Ian Kelly
On Thu, Jun 16, 2016 at 2:45 AM, meInvent bbird wrote: > the name in c# is not called concurrent list, it is called > blockingcollection > > dictionary called concurrent dictionary > > thread safe these kind of things > >

Re: value of pi and 22/7

2016-06-20 Thread Ian Kelly
On Mon, Jun 20, 2016 at 10:01 AM, Ian Kelly <ian.g.ke...@gmail.com> wrote: > I'm not aware of any other such legislative attempts. Snopes records > one that allegedly occurred in Indiana but dismisses the claim as > false. s/Indiana/Alabama -- https://mail.python.org/mailman/listinfo/python-list

Re: value of pi and 22/7

2016-06-20 Thread Ian Kelly
On Mon, Jun 20, 2016 at 12:22 AM, Steven D'Aprano wrote: > There's a difference though. Nobody has tried to legislate the value of pi to > match your casual reference to "about 1900 square feet", but there's been at > least one serious attempt to legislate

Re: value of pi and 22/7

2016-06-19 Thread Ian Kelly
On Sun, Jun 19, 2016 at 4:25 PM, Gregory Ewing <greg.ew...@canterbury.ac.nz> wrote: > Ian Kelly wrote: >> >> Remember, the cubit was based on the length of the >> forearm, so it's not like it was a terribly precise measurement to >> begin with; > > &g

Re: value of pi and 22/7

2016-06-17 Thread Ian Kelly
On Fri, Jun 17, 2016 at 10:30 PM, Lawrence D’Oliveiro wrote: > On Saturday, June 18, 2016 at 3:48:43 PM UTC+12, Random832 wrote: >> >> On Fri, Jun 17, 2016, at 19:12, Lawrence D’Oliveiro wrote: >>> >>> I’m not sure how you can write “30” with one digit... >> >> One

Re: value of pi and 22/7

2016-06-17 Thread Ian Kelly
On Jun 17, 2016 5:44 PM, "Lawrence D’Oliveiro" wrote: > > On Saturday, March 19, 2011 at 3:16:41 AM UTC+13, Grant Edwards wrote: > > > > On 2011-03-18, peter wrote: > > > >> The Old Testament (1 Kings 7,23) says ... "And he made a molten sea, > >> ten cubits from the one

Re: for / while else doesn't make sense

2016-06-14 Thread Ian Kelly
On Tue, Jun 14, 2016 at 5:39 AM, alister wrote: > On Tue, 14 Jun 2016 12:43:35 +1000, Steven D'Aprano wrote: >> >> On this list, I daresay somebody will insist that if their computer is >> on one of Jupiter's moons it will keep running fine and therefore I'm >> wrong.

Re: Overriding methods inherited from a superclass with methods from a mixin

2016-06-13 Thread Ian Kelly
On Mon, Jun 13, 2016 at 1:13 AM, dieter wrote: > alanquei...@gmail.com writes: > >> I'm trying to override methods inherited from a superclass by methods >> defined in a mixin class. >> Here's an sscce: >> https://bpaste.net/show/6c7d8d590658 (never expires) >> >> I've had

Re: for / while else doesn't make sense

2016-06-10 Thread Ian Kelly
On Jun 10, 2016 6:37 AM, "Marko Rauhamaa" wrote: > > alister : > > > Or more simply a hard fixed RULE (MUST be less than X lines) is Bad. > > It's not X lines, it's "you must see the whole function at once." > > If your display can show 1,500 lines at

Re: Recursive type annotations

2016-06-08 Thread Ian Kelly
On Wed, Jun 8, 2016 at 7:31 AM, Nagy László Zsolt wrote: > >>> pass >>> >>> NameError: name 'Test' is not defined >> I think you can fix this by using a string annotation as follows: >> >> class Test: >> def test(self, child: "Test"): >> pass

Re: for / while else doesn't make sense

2016-06-07 Thread Ian Kelly
On Tue, Jun 7, 2016 at 3:58 PM, Lawrence D’Oliveiro wrote: > On Tuesday, June 7, 2016 at 11:53:46 PM UTC+12, Ian wrote: >> On Tue, Jun 7, 2016 at 1:52 AM, Lawrence D’Oliveiro wrote: > >>> Wow, that’s only twice the length of the code you’re replacing. Well done. >> >> Huh?

Re: for / while else doesn't make sense

2016-06-07 Thread Ian Kelly
On Tue, Jun 7, 2016 at 1:52 AM, Lawrence D’Oliveiro wrote: > Wow, that’s only twice the length of the code you’re replacing. Well done. Huh? The example that you posted was 17 lines, excluding comments. My replacement code is 17 lines, excluding comments. Where are you

Re: for / while else doesn't make sense

2016-06-06 Thread Ian Kelly
On Mon, Jun 6, 2016 at 6:51 PM, Lawrence D’Oliveiro wrote: > On Sunday, June 5, 2016 at 11:43:20 PM UTC+12, Marko Rauhamaa wrote: >> I often experiment with different loop constructs to find the one most >> pleasing to the eye. Working directly off iterators is quite rare

Re: Multiple inheritance, super() and changing signature

2016-06-03 Thread Ian Kelly
On Jun 3, 2016 7:12 PM, "Gregory Ewing" wrote: > > 4. It must not matter what order the methods in a super > chain are called. This is because you cannot predict > which method a given super call will invoke. It could > belong to a subclass of the class making the

Re: Catch exception with message?

2016-06-03 Thread Ian Kelly
try: something except Exception as e: if e.args[0] == message_of_interest: handle_it else: raise On Fri, Jun 3, 2016 at 5:14 PM, Piyush Verma <114piy...@gmail.com> wrote: > Generally we catch exception using > except Exception as e: > > But sometimes, we see same type

Re: Multiple inheritance, super() and changing signature

2016-06-03 Thread Ian Kelly
On Fri, Jun 3, 2016 at 2:16 PM, Ben Finney wrote: > If you're writing a custom initialiser that handles two additional > parameters, then those parameters should not be present when you call > the super() method's initialiser:: > > # You specified Python 3, which

<    1   2   3   4   5   6   7   8   9   10   >