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 brim to the other: it was

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. >> > > Anyone on a moon of Ju

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 problems finding the pr

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 once, that's your limit. Mine > shows 70. I d

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 > Yes, you are right. I

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? The example that you pos

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 getting "twice the length"

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 but a >> while-vs-for con

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 call. It can't belong to a subcl

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 o

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 allows simpler syntax. > >

Re: I'm wrong or Will we fix the ducks limp?

2016-06-03 Thread Ian Kelly
On Fri, Jun 3, 2016 at 9:04 AM, Sayth Renshaw wrote: > > >> The problem is that you think that *variables* have a type. This isn't >> the case. Objects have a type. A variable is a name by which you can >> refer to an object. There are various ways in which you can associate a >> object with a var

Re: Multiple inheritance, super() and changing signature

2016-06-03 Thread Ian Kelly
On Fri, Jun 3, 2016 at 8:06 AM, Nagy László Zsolt wrote: > >>> That's overly strict. As Raymond shows, it is easy to deal with >>> changing method signatures in *cooperative* classes. >> I must watch that for sure. > > All right, I have read this: > > https://rhettinger.wordpress.com/2011/05/26/su

Re: for / while else doesn't make sense

2016-06-02 Thread Ian Kelly
On Thu, Jun 2, 2016 at 2:09 PM, Rob Gaddi wrote: > The limited variable scoping is the only thing missing, and you can get > around that by telling yourself you're not going to use that variable > again, and then believing you on the matter. Or you can actually limit the variable scope using a fu

Re: Multiple inheritance, super() and changing signature

2016-06-02 Thread Ian Kelly
On Thu, Jun 2, 2016 at 11:36 AM, Steven D'Aprano wrote: > On Thu, 2 Jun 2016 06:22 pm, Lawrence D’Oliveiro wrote: > >> On Wednesday, June 1, 2016 at 8:02:14 AM UTC+12, Ben Finney wrote: >>> (Note that ‘__init__’ is not a constructor, because it operates on the >>> *already constructed* instance, a

Re: reduction

2016-05-31 Thread Ian Kelly
On Tue, May 31, 2016 at 8:22 AM, Fillmore wrote: > > My problem. I have lists of substrings associated to values: > > ['a','b','c','g'] => 1 > ['a','b','c','h'] => 1 > ['a','b','c','i'] => 1 > ['a','b','c','j'] => 1 > ['a','b','c','k'] => 1 > ['a','b','c','l'] => 0 # <- Black sheep!!! > ['a','b',

Re: Do you think a DB based on Coroutine and AsyncIO is a good idea? I have written a demo on GitHub.

2016-05-25 Thread Ian Kelly
On Wed, May 25, 2016 at 10:52 AM, wrote: > Link: https://github.com/JimChengLin/AsyncDB > > I always wonder why people do not make an async DB, when they are crazy with > async web framework. Hard disks are faster than the Internet, but still > pretty slow compared to CPU/RAM. In-process dbm-s

Re: for / while else doesn't make sense

2016-05-23 Thread Ian Kelly
On Mon, May 23, 2016 at 9:30 AM, Rustom Mody wrote: > Yes the point is being missed but in a different direction: > The SET (as a completed whole) of real numbers (ℝ) is no more than a 100 years > old. > People may have used fractions earlier > > And even here the first line of Steven's http://nri

Re: for / while else doesn't make sense

2016-05-23 Thread Ian Kelly
On Mon, May 23, 2016 at 12:16 PM, Pete Forman wrote: > Something else which I do not think has been stated yet in this thread > is that floating point is an inexact representation. Just because > integers and binary fractions have an exact correspondence we ought not > to be affording them special

Re: for / while else doesn't make sense

2016-05-23 Thread Ian Kelly
On Mon, May 23, 2016 at 11:44 AM, Random832 wrote: > On Mon, May 23, 2016, at 13:33, Chris Angelico wrote: >> and then you can use the special "tagged literal" syntax, like with >> special forms of string literal: >> >> >>> f*22/7 + f*2/11 >> Fraction(256, 77) > > I like the infix fraction literal

Re: str(float) python 3 versus 2.7

2016-05-23 Thread Ian Kelly
On Mon, May 23, 2016 at 10:39 AM, Robin Becker wrote: > I had always imagined that the str founction did some kind of rounding on > floats to prevent small numerical errors from showing up. The 2.7 > documentation starts like this > >> class str(object='') >> Return a string containing a nicely pr

Re: for / while else doesn't make sense

2016-05-23 Thread Ian Kelly
On Mon, May 23, 2016 at 9:53 AM, Ian Kelly wrote: > I'm not sure where ℝ comes into this in the first place. Existing > Python numeric types only represent various subsets of ℚ (in the case > of fractions.Fraction, the entirety of ℚ). And of course I realized after sending that

Re: for / while else doesn't make sense

2016-05-23 Thread Ian Kelly
On Mon, May 23, 2016 at 8:29 AM, Ben Bacarisse wrote: > Ian Kelly writes: > >> On Mon, May 23, 2016 at 2:09 AM, Steven D'Aprano >> wrote: >>> Are you saying that the Egyptians, Babylonians and Greeks didn't know how to >>> work with f

Re: for / while else doesn't make sense

2016-05-23 Thread Ian Kelly
On Mon, May 23, 2016 at 2:09 AM, Steven D'Aprano wrote: > Are you saying that the Egyptians, Babylonians and Greeks didn't know how to > work with fractions? > > http://mathworld.wolfram.com/EgyptianFraction.html > > http://nrich.maths.org/2515 > > Okay, it's not quite 4000 years ago. Sometimes my

Re: for / while else doesn't make sense

2016-05-22 Thread Ian Kelly
On Sun, May 22, 2016 at 11:55 AM, Jon Ribbens wrote: > On 2016-05-22, Random832 wrote: >> On Sun, May 22, 2016, at 12:46, Jon Ribbens wrote: >>> Sorry, I have to stop you there as the entire premise of your post is >>> clearly wrong. "int" is not "an approximation of real numbers", it's >>> a mod

Re: for / while else doesn't make sense

2016-05-21 Thread Ian Kelly
On Sat, May 21, 2016 at 5:26 AM, Steven D'Aprano wrote: > Does anyone know of other languages that include the same feature? It's very > rare for Python to innovate in language features. > > (I wonder if it came from ABC?) According to Raymond Hettinger starting at about 15:50 in this video: htt

Re: for / while else doesn't make sense

2016-05-19 Thread Ian Kelly
On Thu, May 19, 2016 at 2:01 PM, Chris Angelico wrote: > On Fri, May 20, 2016 at 3:46 AM, Steven D'Aprano wrote: >> The idea of finally is >> that it executes no matter what happens[1]. >> >> [1] Well, *almost* no matter what. If you pull the power from the computer, >> the finally block never ge

Re: for / while else doesn't make sense

2016-05-19 Thread Ian Kelly
On Thu, May 19, 2016 at 10:31 AM, Herkermer Sherwood wrote: > Most keywords in Python make linguistic sense, but using "else" in for and > while structures is kludgy and misleading. I am under the assumption that > this was just utilizing an already existing keyword. Adding another like > "andthen

Re: setrecursionlimit

2016-05-18 Thread Ian Kelly
On Wed, May 18, 2016 at 11:15 AM, Steven D'Aprano wrote: > I don't really understand why the system can't track the current top of the > stack and bottom of the heap, and if they're going to collide, halt the > process. That would still be kinda awful, in a sudden "your application > just died" ki

Re: Extract the middle N chars of a string

2016-05-18 Thread Ian Kelly
On Wed, May 18, 2016 at 9:47 AM, Steven D'Aprano wrote: > Extracting the first N or last N characters of a string is easy with > slicing: > > s[:N] # first N > s[-N:] # last N > > Getting the middle N seems like it ought to be easy: > > s[N//2:-N//2] > > but that is wrong. It's not even the righ

Re: Steve D'Aprano, you're the "master". What's wrong with this concatenation statement?

2016-05-10 Thread Ian Kelly
On Tue, May 10, 2016 at 10:16 AM, DFS wrote: > On 5/9/2016 3:53 AM, Steven D'Aprano wrote: >> >> On Monday 09 May 2016 09:10, DFS wrote: >> >>> sSQL = "line 1\n" >>> sSQL += "line 2\n" >>> sSQL += "line 3" >> >> >> Pointlessly provocative subject line edited. > > > > huh? You called yourself a "

Re: [Python-ideas] Boolean parameters guidelines

2016-05-08 Thread Ian Kelly
On May 8, 2016 9:37 AM, "Steven D'Aprano" wrote: > > Not sure why this has migrated to this list instead of Python-Ideas. Because Gmail has somehow never gotten around to implementing reply-to-list and I'm terrible at choosing the right one. -- https://mail.python.org/mailman/listinfo/python-lis

Re: [Python-ideas] Boolean parameters guidelines

2016-05-08 Thread Ian Kelly
On May 8, 2016 12:42 AM, "Steven D'Aprano" wrote: > > def pvariance(data, mu=None): > if iter(data) is data: > data = list(data) > n = len(data) > if n < 1: > raise StatisticsError('pvariance requires at least one data point') > ss = _ss(data, mu) > T, ss = _ss(

Re: pylint woes

2016-05-07 Thread Ian Kelly
On Sat, May 7, 2016 at 9:28 PM, DFS wrote: > But I think there are some pylint bugs here: > - > > standard import "import pyodbc, sqlite3" comes before "import pyodbc, > sqlite3" (wrong-import-order) > > * complains that the

Re: Private message regarding: Howw to prevent the duplication of any value in a column within a CSV file (python)

2016-05-02 Thread Ian Kelly
On Mon, May 2, 2016 at 3:52 AM, Adam Davis wrote: > Hi Ian, > > I'm really struggling to implement a set into my code as I'm a beginner, > it's taking me a while to grasp the idea of it. If I was to show you my code > so you get an idea of my aim/function of the code, would you be able to help > m

Re: Differences between Class(Object) and Class(Dict) for dictionary usage?

2016-04-27 Thread Ian Kelly
On Tue, Apr 26, 2016 at 9:43 PM, Christopher Reimer wrote: > class Test2(dict): > def __init__(self): > self.__dict__ = {'key', 'value'} This class definition looks muddled. Because Test2 inherits from dict, the object referred to by "self" will be a dict, and self.__d

Re: Differences between Class(Object) and Class(Dict) for dictionary usage?

2016-04-27 Thread Ian Kelly
On Tue, Apr 26, 2016 at 11:31 PM, Ethan Furman wrote: > On 04/26/2016 08:43 PM, Christopher Reimer wrote: > >> If I'm using a dictionary to store variables for an object, and >> accessing the variable values from dictionary via property decorators, >> would it be better to derive the class from ob

Re: Running PyGame on OS X

2016-04-26 Thread Ian Kelly
On Tue, Apr 26, 2016 at 3:33 PM, D.M. Procida wrote: > I have PyGame installed. > > As soon as I run pygame.init() or pygame.display.init(), a PyGame icon > will pop up in the Dock, and then its application will simply stop > responding. Needless to say, I can't actually do anything with it. > > W

Re: Howw to prevent the duplication of any value in a column within a CSV file (python)

2016-04-26 Thread Ian Kelly
On Tue, Apr 26, 2016 at 2:07 PM, Adam Davis wrote: > On Tuesday, 26 April 2016 20:52:54 UTC+1, Ian wrote: >> On Tue, Apr 26, 2016 at 1:05 PM, Joaquin Alzola >> wrote: >> > Just an example. Didn't use the csv but just hope that it helps. >> > >> > name=[] >> > name_exist="Dop" >> > >> > with open

Re: Howw to prevent the duplication of any value in a column within a CSV file (python)

2016-04-26 Thread Ian Kelly
On Tue, Apr 26, 2016 at 1:05 PM, Joaquin Alzola wrote: > Just an example. Didn't use the csv but just hope that it helps. > > name=[] > name_exist="Dop" > > with open("dop.csv") as f: > for line in f: > line_split=line.split(',') > name.append(line_strip[0])

Re: Howw to prevent the duplication of any value in a column within a CSV file (python)

2016-04-26 Thread Ian Kelly
On Tue, Apr 26, 2016 at 11:00 AM, Adam Davis wrote: > On Tuesday, 26 April 2016 17:14:36 UTC+1, Ian wrote: >> On Tue, Apr 26, 2016 at 10:01 AM, wrote: >> > I am wondering how to make my code function so it does not allow any of >> > the same values to be entered into a column in my CSV file cr

Re: def __init__(self):

2016-04-26 Thread Ian Kelly
On Tue, Apr 26, 2016 at 11:13 AM, Chris Kaynor wrote: > Yah, if you really wanted to make it work properly, you'd need to incref > the newValue, while decref the oldValue. The incref would not be that > difficult, but the decref would be more challenging, as you may have to > also destroy the old

Re: Howw to prevent the duplication of any value in a column within a CSV file (python)

2016-04-26 Thread Ian Kelly
On Tue, Apr 26, 2016 at 10:01 AM, wrote: > I am wondering how to make my code function so it does not allow any of the > same values to be entered into a column in my CSV file created through > python. So I need to read into the CSV file and check if any names have > already been entered. If t

Re: Comparing Python enums to Java, was: How much sanity checking is required for function inputs?

2016-04-24 Thread Ian Kelly
On Sun, Apr 24, 2016 at 10:04 AM, Ethan Furman wrote: > On 04/24/2016 08:20 AM, Ian Kelly wrote: >> * Java doesn't have the hokey notion of enum instances being distinct >> from their "value". The individual enum members *are* the values. >> Whereas in Pytho

Comparing Python enums to Java, was: How much sanity checking is required for function inputs?

2016-04-24 Thread Ian Kelly
On Sun, Apr 24, 2016 at 1:20 AM, Ethan Furman wrote: > On 04/23/2016 06:29 PM, Ian Kelly wrote: > >> Python enums are great. Sadly, they're still not quite as awesome as Java >> enums. > > > What fun things can Java enums do? Everything that Python enums can do, p

Re: How much sanity checking is required for function inputs?

2016-04-23 Thread Ian Kelly
On Sat, Apr 23, 2016 at 7:00 PM, Christopher Reimer wrote: > On 4/21/2016 9:46 PM, Ethan Furman wrote: >> >> Oh! and Enum!!! ;) > > > OMG! I totally forgot about Enum. Oh, look. Python supports Enum. Now I > don't have to roll my own! > > Hmm... What do we use Enum for? :) Python enums are great

Re: A pickle problem!

2016-04-22 Thread Ian Kelly
On Fri, Apr 22, 2016 at 2:21 PM, Paulo da Silva wrote: > Às 17:27 de 22-04-2016, Ian Kelly escreveu: >> On Thu, Apr 21, 2016 at 7:52 PM, Paulo da Silva >> wrote: >>> Às 22:43 de 21-04-2016, Paulo da Silva escreveu: > ... > >> >> Probably this is necess

Re: A pickle problem!

2016-04-22 Thread Ian Kelly
On Thu, Apr 21, 2016 at 7:52 PM, Paulo da Silva wrote: > Às 22:43 de 21-04-2016, Paulo da Silva escreveu: >> Hi. >> >> Why in this code fragment self.__name is not kept between pickle >> dumps/loads? How to fix it? >> >> Thanks. >> >> import pickle >> import pandas as pd >> import numpy as np >> >

Re: Guido sees the light: PEP 8 updated

2016-04-18 Thread Ian Kelly
On Mon, Apr 18, 2016 at 3:14 PM, Pete Forman wrote: > Why is it that Python continues to use a fixed width font and therefore > specifies the maximum line width as a character count? > > An essential part of the language is indentation which ought to continue > to mandate that lines start with a m

Re: [Python-ideas] Changing the meaning of bool.__invert__

2016-04-18 Thread Ian Kelly
On Sun, Apr 17, 2016 at 12:24 PM, Pavol Lisy wrote: > 2016-04-09 17:43 GMT+02:00, Steven D'Aprano : >> flag ^ flag is useful since we don't have a boolean-xor operator and >> bitwise-xor does the right thing for bools. And I suppose some people >> might prefer & and | over boolean-and and boolean-

Re: Guido sees the light: PEP 8 updated

2016-04-17 Thread Ian Kelly
On Sat, Apr 16, 2016 at 4:30 PM, Marko Rauhamaa wrote: > > Java generics ruined a perfectly good language. I mean: > > Map> customersOfAccountManager = > new HashMap>(); > > where classic Java would have: > > Map customersOfAccountManager = new HashMap(); The diamond operator in J

English dialect (Was: How to XOR a byte output?)

2016-04-13 Thread Ian Kelly
On Wed, Apr 13, 2016 at 10:15 AM, alister wrote: > On Wed, 13 Apr 2016 06:18:22 -0700, durgadevi1 wrote: > >> Hi all, >> >> I have a doubt regarding a problem. >> > No, you have a question doubt means you don't believe something > (sorry I know this is not an English language lesson) No, this is

Re: IdentationError; unexpected indent

2016-04-13 Thread Ian Kelly
On Wed, Apr 13, 2016 at 9:53 AM, salma ammar wrote: > Hi, > > I am about to run this code using python 2.7. But when executing this code, > an error appears (see attachement): IdentationError; unexpected indent > > What should I rectify to correct this error please? First of all, please post your

Re: How to XOR a byte output?

2016-04-13 Thread Ian Kelly
On Wed, Apr 13, 2016 at 8:27 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> Let's just guess that you want to xor with the byte value 0xAA. We can >> do that fairly simply, using integer operations. >> > data = b'$//W?\xc0\x829\xa2\xb9\x13\x8c\xd5{\\' > bytes(b ^ 0xAA for b in data) >>

Re: Enum questions.

2016-04-13 Thread Ian Kelly
On Wed, Apr 13, 2016 at 7:50 AM, Grant Edwards wrote: > FWIW, as an old Pascal programmer, I too would have been surprised > that an "enum" is not ordinal and doesn't support a next/prev and > iteration. They do support iteration, but it's by order of declaration, not by value. -- https://mail.p

Re: QWERTY was not designed to intentionally slow typists down (was: Unicode normalisation [was Re: [beginner] What's wrong?])

2016-04-10 Thread Ian Kelly
On Sat, Apr 9, 2016 at 9:09 PM, pyotr filipivich wrote: > ASINTOER are the top eight English letters (not in any order, it > is just that "A Sin To Err" is easy to remember. What's so hard to remember about ETA OIN SHRDLU? Plus that even gives you the top twelve. :-) -- https://mail.pyth

Re: Find the number of robots needed to walk through the rectangular grid

2016-04-09 Thread Ian Kelly
On Sat, Apr 9, 2016 at 8:18 AM, Joe wrote: > How to find the number of robots needed to walk through the rectangular grid > The movement of a robot in the field is divided into successive steps > > In one step a robot can move either horizontally or vertically (in one row or > in one column of ce

Re: (Python 3.5) Asyncio and an attempt to run loop.run_until_complete() from within a running loop

2016-04-09 Thread Ian Kelly
On Sat, Apr 9, 2016 at 9:14 AM, Ian Kelly wrote: > On Fri, Apr 8, 2016 at 5:54 PM, Alexander Myodov wrote: > This does mean that the pattern for calling aio_map from outside the > event loop is different from calling it inside the event loop. Your > main_loop coroutine becomes (note

Re: (Python 3.5) Asyncio and an attempt to run loop.run_until_complete() from within a running loop

2016-04-09 Thread Ian Kelly
On Fri, Apr 8, 2016 at 5:54 PM, Alexander Myodov wrote: > Hello. > > TLDR: how can I use something like loop.run_until_complete(coro), to execute > a coroutine synchronously, while the loop is already running? > > More on this: > > I was trying to create an aio_map(coro, iterable) function (which

Re: past exam paper help!

2016-04-09 Thread Ian Kelly
On Sat, Apr 9, 2016 at 7:49 AM, Joseph Caulfield wrote: > On Saturday, April 9, 2016 at 2:48:16 PM UTC+1, Joseph Caulfield wrote: >> how would I model a mug a cylindrical vessel with an open top in python? >> thansk :) > > *as a cylindrical vessel. class Vessel: def __init__(self, shape, o

Re: Python programs and relative imports

2016-04-08 Thread Ian Kelly
On Fri, Apr 8, 2016 at 11:50 AM, Rob Gaddi wrote: > Sort of. If I've got a directory full of files (in a package) > that I'm working on, the relative import semantics change based on > whether I'm one directory up and importing the package or in the same > directory and importing the files locall

Re: how to convert code that uses cmp to python3

2016-04-08 Thread Ian Kelly
On Fri, Apr 8, 2016 at 10:33 AM, Marko Rauhamaa wrote: > Ian Kelly : > >> That's fine for those operations and probably insert, but how do you >> search an AVL tree for a specific key without also using

Re: how to convert code that uses cmp to python3

2016-04-08 Thread Ian Kelly
On Fri, Apr 8, 2016 at 8:08 AM, Chris Angelico wrote: > On Fri, Apr 8, 2016 at 11:31 PM, Antoon Pardon > wrote: >> Doing it as follows: >> seq1 < seq2 >> seq2 < seq1 >> >> takes about 110 seconds. >> >> >> Doing it like this: >> delta = cmp(seq1, seq2) >> delta < 0 >> delta >

Re: how to convert code that uses cmp to python3

2016-04-08 Thread Ian Kelly
On Fri, Apr 8, 2016 at 3:23 AM, Steven D'Aprano wrote: > On Fri, 8 Apr 2016 06:34 pm, Marko Rauhamaa wrote: > >> Antoon Pardon : >> >>> In python2 descending the tree would only involve at most one >>> expensive comparison, because using cmp would codify that comparison >>> into an integer which w

Re: how to convert code that uses cmp to python3

2016-04-07 Thread Ian Kelly
On Apr 7, 2016 10:22 PM, "Marko Rauhamaa" wrote: > > Ian Kelly : > > > On Thu, Apr 7, 2016 at 1:32 PM, Marko Rauhamaa wrote: > >> I use AVL trees to implement timers. You need to be able to insert > >> elements in a sorted order and remove them quickl

Re: how to convert code that uses cmp to python3

2016-04-07 Thread Ian Kelly
On Thu, Apr 7, 2016 at 2:56 PM, Antoon Pardon wrote: > Op 07-04-16 om 14:22 schreef Chris Angelico: > > ... > >> There's no __cmp__ method, but you could easily craft your own >> compare() function: >> >> def compare(x, y): >> """Return a number < 0 if x < y, or > 0 if x > y""" >> if x ==

Re: how to convert code that uses cmp to python3

2016-04-07 Thread Ian Kelly
On Thu, Apr 7, 2016 at 1:32 PM, Marko Rauhamaa wrote: > Paul Rubin : > >> Chris Angelico writes: >>> First off, what does it actually *mean* to have a tree with numbers >>> and keys as strings? Are they ever equal? Are all integers deemed >>> lower than all strings? Something else? >> >> If the A

Re: Untrusted code execution

2016-04-07 Thread Ian Kelly
On Thu, Apr 7, 2016 at 11:35 AM, Jon Ribbens wrote: > Well, it entirely depends on how much you're trying to allow the > sandboxed code to do. Most of the stuff in that script (e.g. > _copy_module and safe versions of get/set/delattr, exec, and eval) > I don't think is really necessary for most se

Re: Promoting Python

2016-04-07 Thread Ian Kelly
On Thu, Apr 7, 2016 at 12:30 AM, Marko Rauhamaa wrote: > Or: > >When a class attribute reference (for class C, say) would yield a >class method object, it is transformed into an instance method object >whose __self__ attributes is C. >https://docs.python.org/3/reference/datamodel.h

Re: Promoting Python

2016-04-06 Thread Ian Kelly
On Wed, Apr 6, 2016 at 2:39 PM, Marko Rauhamaa wrote: > Ian Kelly : > >> On Wed, Apr 6, 2016 at 1:59 PM, Marko Rauhamaa wrote: >>> It seems to me CPython is being a bit too picky here. Why should it >>> care if the method is a class method or an object method?

Re: Promoting Python

2016-04-06 Thread Ian Kelly
On Wed, Apr 6, 2016 at 1:59 PM, Marko Rauhamaa wrote: > Ian Kelly : > >> On Wed, Apr 6, 2016 at 1:22 PM, Marko Rauhamaa wrote: >>> Why is a SimpleNamespace object not an iterator even though it >>> provides __iter__ and __next__? >> >> Because Python

Re: Promoting Python

2016-04-06 Thread Ian Kelly
On Wed, Apr 6, 2016 at 1:22 PM, Marko Rauhamaa wrote: > However, BartC's No-Buzzword Python doesn't have classes... If he > allowed for types.SimpleNamespace, we could have: > > > import types > > def While(predicate): >

Re: Promoting Python

2016-04-06 Thread Ian Kelly
On Wed, Apr 6, 2016 at 8:14 AM, Marko Rauhamaa wrote: > Now, if Python had an unlimited range() iterator/iterable, you could use > a "for" statement to emulate "while". You can already do this. >>> class While: ... def __init__(self, predicate): ... self._predicate = predicate ...

Re: Untrusted code execution

2016-04-06 Thread Ian Kelly
On Wed, Apr 6, 2016 at 10:04 AM, Chris Angelico wrote: > On Thu, Apr 7, 2016 at 1:41 AM, Ian Kelly wrote: >> type might also be a concern since it can be used to assemble >> arbitrary classes. > > Sadly, this means denying the ability to interrogate an object for its >

Re: Untrusted code execution

2016-04-06 Thread Ian Kelly
On Tue, Apr 5, 2016 at 7:43 PM, Steven D'Aprano wrote: > I think Jon is on the right approach here for restricting evaluation of > evaluation, which is a nicely constrained and small subset of Python. He's > not allowing unrestricted arbitrary code execution: he has a very > restricted (too restri

Re: Untrusted code execution

2016-04-05 Thread Ian Kelly
On Tue, Apr 5, 2016 at 11:48 AM, Chris Angelico wrote: > Your code is a *lot* safer for using 'eval' rather than 'exec'. > Otherwise, you'd be easily exploited using exceptions, which carry a > ton of info. But even so, I would not bet money (much less the > security of my systems) on this being s

Re: Untrusted code execution

2016-04-05 Thread Ian Kelly
On Tue, Apr 5, 2016 at 8:17 AM, Rustom Mody wrote: > On Tuesday, April 5, 2016 at 7:19:39 PM UTC+5:30, Jon Ribbens wrote: >> On 2016-04-03, Jon Ribbens wrote: >> > I'd just like to say up front that this is more of a thought experiment >> > than anything else, I don't have any plans to use this id

Re: Request Help With Function

2016-04-04 Thread Ian Kelly
On Mon, Apr 4, 2016 at 1:42 PM, Wildman via Python-list wrote: > commandlist = commandlist.split(",") commandlist is a list. > command = [target, commandlist] > subprocess.Popen(command) This is passing a list containing two elements: the first is a string, a

Re: Drowning in a teacup?

2016-04-01 Thread Ian Kelly
On Fri, Apr 1, 2016 at 3:10 PM, Chris Kaynor wrote: > The overall algorithm is O(n^2), as its doing a O(n) operation in a O(n) > loop: Depends on whether the OP expects to find only one match or potentially multiple matches in the list. E did say "if one of the elements matches". If there are on

Re: Drowning in a teacup?

2016-04-01 Thread Ian Kelly
On Fri, Apr 1, 2016 at 2:39 PM, Rob Gaddi wrote: > Fillmore wrote: >> Nope, wrong! contrary to what I thought I had understood about how >> parameters are passed in Python, the function is acting on a copy(!) and >> my original list is unchanged. >> > > Nope, that's not your problem. Your problem

Re: [Python-ideas] Decorators for variables

2016-04-01 Thread Ian Kelly
On Fri, Apr 1, 2016 at 11:14 AM, Matthias welp wrote: >> An example of the transformation would help here > > An example, that detects cycles in a graph, and doesn't do an update if > the graph has cycles. Thanks. > class A(object): > def __init__(self, parent): > @prevent_cycles >

Re: Strange range

2016-04-01 Thread Ian Kelly
On Fri, Apr 1, 2016 at 8:42 AM, Random832 wrote: > On Fri, Apr 1, 2016, at 09:24, Chris Angelico wrote: >> It is an iterable. It is not a factory, as that implies that you call >> it. > > I do have an objection to this statement. It's perfectly reasonable to > describe the factory pattern as apply

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

2016-03-31 Thread Ian Kelly
On Thu, Mar 31, 2016 at 10:30 AM, Travis Griggs wrote: > >> On Mar 30, 2016, at 2:36 PM, Gregory Ewing >> wrote: >> >> Tim Golden wrote: >> >>> (I don't know how other English-speaking groups say the word, but in >>> England the first syllable is stressed and the second is the >>> conventional s

Re: Slice equivalent to dict.get

2016-03-31 Thread Ian Kelly
On Thu, Mar 31, 2016 at 9:24 AM, Peter Otten <__pete...@web.de> wrote: > But note: > def get(seq, index, default=None): > ... return (seq[index:index+1] or [default])[0] > ... get("abc", -1, "default") > 'default' The discontinuity between -1 and 0 in indexing is a pain in the rear.

Re: [OT'ish] Is there a list as good as this for Javascript

2016-03-24 Thread Ian Kelly
On Thu, Mar 24, 2016 at 4:58 PM, Mark Lawrence wrote: > No. While this idiot, BartC, is let loose on this forum, I'll say what I > like. Good to know. I've been on the fence about this for a long time, but lately the frequency of your outbursts seems to have increased, and you're being more of a

Re: Static caching property

2016-03-22 Thread Ian Kelly
On Mon, Mar 21, 2016 at 6:05 PM, Steven D'Aprano wrote: > On Tue, 22 Mar 2016 04:48 am, Ian Kelly wrote: > >> You don't actually need a metaclass for this: >> >>>>> class Desc: >> ... def __get__(self, obj, type=None): >> ...

Re: multiprocessing, pool, queue length

2016-03-21 Thread Ian Kelly
On Mon, Mar 21, 2016 at 1:46 PM, Michael Welle wrote: > Wait on the result means to set a multiprocessing.Event if one of the > consumers finds the sentinel task and wait for it on the producer? Hmm, > that might be better than incrementing a counter. But still, it couples > the consumers and the

Re: Convert list to another form but providing same information

2016-03-21 Thread Ian Kelly
On Mon, Mar 21, 2016 at 2:12 PM, Ian Kelly wrote: > On Mon, Mar 21, 2016 at 2:03 PM, Ben Bacarisse wrote: >> For experts here: why can't I write a lambda that has a statement in it >> (actually I wanted two: lambda l, i: l[i] += 1; return l)? > > https://docs.python.org

Re: Convert list to another form but providing same information

2016-03-21 Thread Ian Kelly
On Mon, Mar 21, 2016 at 2:03 PM, Ben Bacarisse wrote: > For experts here: why can't I write a lambda that has a statement in it > (actually I wanted two: lambda l, i: l[i] += 1; return l)? https://docs.python.org/3/faq/design.html#why-can-t-lambda-expressions-contain-statements -- https://mail.p

Re: multiprocessing, pool, queue length

2016-03-21 Thread Ian Kelly
On Mon, Mar 21, 2016 at 4:25 AM, Michael Welle wrote: > Hello, > > I use a multiprocessing pool. My producer calls pool.map_async() > to fill the pool's job queue. It can do that quite fast, while the > consumer processes need much more time to empty the job queue. Since the > producer can create

Re: Static caching property

2016-03-21 Thread Ian Kelly
On Mon, Mar 21, 2016 at 10:54 AM, Chris Angelico wrote: > On Tue, Mar 22, 2016 at 3:49 AM, Joseph L. Casale > wrote: >> Right, but _private refers to an api call that is expensive and may not even >> be accessed, >> so while I may new up three instances of Test across a, b and c, if none of >>

Re: Static caching property

2016-03-21 Thread Ian Kelly
On Mon, Mar 21, 2016 at 10:36 AM, Steven D'Aprano wrote: > On Tue, 22 Mar 2016 03:15 am, Ian Kelly wrote: >> Why not do the same thing but using a class attribute instead of an >> instance attribute? > > Properties don't work when called from a class: Prop

Re: Static caching property

2016-03-21 Thread Ian Kelly
On Mon, Mar 21, 2016 at 9:38 AM, Joseph L. Casale wrote: > With non static properties, you can use a decorator that overwrites the > method on the instance with an attribute containing the methods return > effectively caching it. Can you give an example of what you mean? > What technique for a s

Re: monkey patching __code__

2016-03-20 Thread Ian Kelly
On Fri, Mar 18, 2016 at 7:47 AM, Ian Kelly wrote: > Your patched version takes two extra arguments. Did you add the > defaults for those to the function's __defaults__ attribute? And as an afterthought, you'll likely need to replace the function's __globals__ with your o

Re: monkey patching __code__

2016-03-19 Thread Ian Kelly
On Mar 18, 2016 8:33 AM, "Sven R. Kunze" wrote: > > On 18.03.2016 14:47, Ian Kelly wrote: >> >> Your patched version takes two extra arguments. Did you add the >> defaults for those to the function's __defaults__ attribute? > > > That's it!

Re: monkey patching __code__

2016-03-19 Thread Ian Kelly
On Fri, Mar 18, 2016 at 9:01 AM, Sven R. Kunze wrote: > On 18.03.2016 15:48, Ian Kelly wrote: >> >> Well I didn't design it, so I'm not really sure. But it could be argued >> that the defaults are intrinsic to the function declaration, not the code >> obje

Re: monkey patching __code__

2016-03-19 Thread Ian Kelly
On Fri, Mar 18, 2016 at 5:49 AM, Sven R. Kunze wrote: > 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

Re: How to waste computer memory?

2016-03-19 Thread Ian Kelly
On Thu, Mar 17, 2016 at 1:21 PM, Rick Johnson wrote: > In the event that i change my mind about Unicode, and/or for > the sake of others, who may want to know, please provide a > list of languages that *YOU* think handle Unicode better than > Python, starting with the best first. Thanks. jmf has

Re: How to waste computer memory?

2016-03-19 Thread Ian Kelly
On Fri, Mar 18, 2016 at 6:37 AM, Chris Angelico wrote: > On Fri, Mar 18, 2016 at 10:46 PM, Steven D'Aprano wrote: >> Technically, UTF-8 doesn't *necessarily* imply indexing is O(n). For >> instance, your UTF-8 string might consist of an array of bytes containing >> the string, plus an array of in

Re: How to waste computer memory?

2016-03-18 Thread Ian Kelly
On Fri, Mar 18, 2016 at 3:19 PM, Mark Lawrence wrote: > > I have no idea at what the above can mean, other than that you are agreeing > with the RUE. Mark, are you aware that this is a rather classic ad hominem of guilt by association? "I didn't pay any attention to your actual argument, but you

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