Re: if statement on lenght of a list

2011-05-17 Thread Ian Kelly
On Tue, May 17, 2011 at 12:02 PM, Joe Leonardo wrote: > Hey all, > > > > Totally baffled by this…maybe I need a nap. Writing a small function to > reject input that is not a list of 19 fields. > > > > def breakLine(value): > > if value.__class__() != [] and value.__len__() != 19: > > p

Re: Python 3.x and bytes

2011-05-17 Thread Ian Kelly
On Tue, May 17, 2011 at 12:47 PM, Ethan Furman wrote: > In Python 3 one can say > > --> huh = bytes(5) > > Since the bytes type is actually a list of integers, I would have expected > this to have huh being a bytestring with one element -- the integer 5. >  Actually, what you get is: > > --> huh >

Re: Python 3.x and bytes

2011-05-17 Thread Ian Kelly
On Tue, May 17, 2011 at 1:20 PM, Ian Kelly wrote: > I suppose it's for interoperability with the mutable bytearray type, > which takes the same parameters in the constructor. http://www.python.org/dev/peps/pep-3137/#constructors -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 3.x and bytes

2011-05-17 Thread Ian Kelly
On Tue, May 17, 2011 at 1:50 PM, Corey Richardson wrote: > - From help(bytes): >  |  bytes(iterable_of_ints) -> bytes >  |  bytes(string, encoding[, errors]) -> bytes >  |  bytes(bytes_or_buffer) -> immutable copy of bytes_or_buffer >  |  bytes(memory_view) -> bytes > > Looks like you're using the

Re: Python 3.x and bytes

2011-05-17 Thread Ian Kelly
On Tue, May 17, 2011 at 2:20 PM, Ethan Furman wrote: > The big question, though, is would you do it this way: > > some_var = bytes(23).replace(b'\x00', b'a') > > or this way? > > some_var = bytes(b'a' * 23) Actually, I would just do it this way: some_var = b'a' * 23 That's already a bytes objec

Re: portable multiprocessing code

2011-05-17 Thread Ian Kelly
On Tue, May 17, 2011 at 9:14 AM, Eric Frederich wrote: > I have written some code using Python 2.7 but I'd like these scripts > to be able to run on Red Hat 5's 2.4.3 version of Python which doesn't > have multiprocessing. > I can try to import multiprocessing and set a flag as to whether it is >

Re: python logging

2011-05-17 Thread Ian Kelly
On Tue, May 17, 2011 at 2:55 PM, Fei wrote: > where is default logging file on Mac? I saw lots of app just import > logging, and begins to logging.info(...) etc.  I'm not sure where to > look at the logging configuration to figure out the log location. There is no default log file. You're seeing

Re: English Idiom in Unix: Directory Recursively

2011-05-17 Thread Ian Kelly
On Tue, May 17, 2011 at 4:26 PM, Xah Lee wrote: > Though, if you think about it, it's not exactly a correct description. > “Recursive”, or “recursion”, refers to a particular type of algorithm, > or a implementation using that algorithm. Only when used as programming jargon. In mathematics, "rec

Re: in search of graceful co-routines

2011-05-17 Thread Ian Kelly
On Tue, May 17, 2011 at 11:27 PM, Chris Withers wrote: > Yes, but it's this kind of birds nest I'm trying to avoid... I was actually kind of hoping you might see it that way. That's about as simple as you're going to get using a generator for this, though. I'll second Terry's suggestion on this:

Re: English Idiom in Unix: Directory Recursively

2011-05-18 Thread Ian Kelly
On Wed, May 18, 2011 at 12:06 AM, rusi wrote: > 4. Recursion in 'recursion theory' aka 'computability theory' is > somehow different from recursion in programming. Um, it is. Consider the simple function (lambda x, y: x + y). Mathematically, this function is recursive. Algorithmically, it is no

Re: English Idiom in Unix: Directory Recursively

2011-05-18 Thread Ian Kelly
On Wed, May 18, 2011 at 1:10 AM, rusi wrote: >> Um, it is.  Consider the simple function (lambda x, y: x + y). >> Mathematically, this function is recursive.  Algorithmically, it is >> not.  Do you disagree? > > See the definition of primitive recursion eg. > > http://en.wikipedia.org/wiki/Primiti

Re: English Idiom in Unix: Directory Recursively

2011-05-18 Thread Ian Kelly
On Wed, May 18, 2011 at 9:15 AM, rusi wrote: >> What you're failing to explain is why you would consider that function >> to be recursive from a programming standpoint. > > As for putting + under the format of primitive recursion, it would go > something like this (I guess) > > Matching up that de

Re: python logging

2011-05-18 Thread Ian Kelly
2011/5/18 Rafael Durán Castañeda : > That's not exactly how it works. You can use logging without any > configuration and the default output will be console. In addition default > logging level is warning, so: > > logging.info("Some text") > > won't  show anything and > > logging.warning("Other tex

Re: python logging

2011-05-18 Thread Ian Kelly
2011/5/18 Rafael Durán Castañeda : > I think you are confuse because of you are looking at advanced logging, > where getLogger is being used. Simple logging works without any > configuration, getLogger doesn't. It seems to work without any configuration just as well as the root logger: >>> import

Indexable properties recipe

2011-05-18 Thread Ian Kelly
http://code.activestate.com/recipes/577703-item-properties/ -- http://mail.python.org/mailman/listinfo/python-list

Re: python logging

2011-05-18 Thread Ian Kelly
2011/5/18 Rafael Durán Castañeda : > Are you using python 2.x or 3.x? At python 2.7 using: > > import logging > logging.getLogger('log').warning('test') > > I got: > > No handlers could be found for logger "log" Ah, that's it. I was using Python 2.5. Using 2.7 I get the same result that you do.

Re: python logging

2011-05-18 Thread Ian Kelly
2011/5/18 Ian Kelly : > Ah, that's it.  I was using Python 2.5.  Using 2.7 I get the same > result that you do. > > Still, it's a surprising change that doesn't seem to be documented as > such.  I'm not sure whether it's a regression or an intentional >

Re: Inheriting Object

2011-05-20 Thread Ian Kelly
On Thu, May 19, 2011 at 10:11 PM, Navkirat Singh wrote: > Thanks Guys...I will look deeper into this. I thought I read somewhere that > it was required in older python releases, but in newer releases it is not. I > might be wrong though. In Python 3.x all classes inherit from object by default, s

Re: Faster Recursive Fibonacci Numbers

2011-05-20 Thread Ian Kelly
On Thu, May 19, 2011 at 11:58 PM, Steven D'Aprano wrote: > Sure, which is why the above fib() function will become increasing > inaccurate beyond some given n, by memory about n=71 or so. Er, at least > the fib() function that *was* above until you deleted most of it :) > > If you want an *accurat

Re: Faster Recursive Fibonacci Numbers

2011-05-20 Thread Ian Kelly
2011/5/20 Ian Kelly : > def fib_decimal(n): >    with localcontext() as ctx: >        ctx.prec = n // 4 + 1 >        sqrt_5 = Decimal('5').sqrt() >        phi = (1 + sqrt_5) / 2 >        numerator = (phi ** n) - (1 - phi) ** n >        return int((numerator / sqr

Re: hash values and equality

2011-05-20 Thread Ian Kelly
On Fri, May 20, 2011 at 10:36 AM, Chris Kaynor wrote: > I think the question was: can this dummy code ever produce a set containing > less then itemCount items (for 0 < itemCount < 2**32)? In CPython, no. Even when you get a hash collision, the code checks to see whether the hashes are actually

Re: TK program problem

2011-05-20 Thread Ian Kelly
On Fri, May 20, 2011 at 12:03 PM, bvdp wrote: > All this is fine (and worked perfectly before my upgrade). The menu > items which are ordinary functions continue to work. BUT the callbacks > which are classes are just ignored when they are clicked. I'm not a tk user, but it sounds like it has reg

Re: TK program problem

2011-05-20 Thread Ian Kelly
On Fri, May 20, 2011 at 4:12 PM, bvdp wrote: > Okay, this works. Great and thanks! Seems to me that the way I was > doing it should be alright ... and I've got some other programs > exhibiting the same problem. > > Before I go "fixing" the issue ... is this known or even a bug? The docs [1] say t

Re: TK program problem

2011-05-20 Thread Ian Kelly
On Fri, May 20, 2011 at 5:07 PM, bvdp wrote: > You mention the tkinter group. Ummm, what group is that??? http://tkinter.unpythonic.net/wiki/TkinterDiscuss -- http://mail.python.org/mailman/listinfo/python-list

Re: referring to package scope from module, using relative import?

2011-05-21 Thread Ian Kelly
On Sat, May 21, 2011 at 1:28 PM, Irmen de Jong wrote: > Hi, > > I have a package with several modules in it. The package also has some > objects created > in the package scope (done in the package __init__.py). > > Is it possible to access those package scope objects from the modules, with > rel

Re: Writing multiple files with with-context

2011-05-23 Thread Ian Kelly
On Sun, May 22, 2011 at 8:48 PM, Shunichi Wakabayashi wrote: > One idea is using contextlib.nested(), > > from contextlib import nested > > with nested(*[open('list_%d.txt' % i, 'w') for i in range(LIST_LEN)]) as > fobjlist: >  for i in range(1000): >    fobjlist[random.randrange(LIST_LEN)].write

Re: Unit testing beginner question

2011-05-23 Thread Ian Kelly
On Mon, May 23, 2011 at 4:30 PM, Andrius wrote: > and I am expecting test to pass, but I am getting exception: > Traceback (most recent call last): >    self.assertRaises(TypeError, self.testListNone[:1]) > TypeError: 'NoneType' object is unsubscriptable > > I thought that assertRaises will pass s

Re: super() in class defs?

2011-05-25 Thread Ian Kelly
On Wed, May 25, 2011 at 11:54 AM, Jess Austin wrote: > So I guess that when super() is called in the context of a class def > rather than that of a method def, it doesn't have the information it > needs. Now I'll probably just say: > >    do_GET = do_decorate(CGIHTTPRequestHandler.do_GET) > > but

Re: Python 3.2 bug? Reading the last line of a file

2011-05-25 Thread Ian Kelly
On Wed, May 25, 2011 at 2:00 PM, MRAB wrote: > You're opening the file in text mode, and seeking relative to the end > of the file is not allowed in text mode, presumably because the file > contents have to be decoded, and, in general, seeking to an arbitrary > position within a sequence of encode

Re: super() in class defs?

2011-05-25 Thread Ian Kelly
On Wed, May 25, 2011 at 3:40 PM, Steven D'Aprano wrote: > If you actually read that article, carefully, without being fooled by the > author's provocative ex-title and misleading rhetoric, you will discover > that super is not harmful. What is harmful is making unjustified > assumptions about what

Re: Python 3.2 bug? Reading the last line of a file

2011-05-25 Thread Ian Kelly
On Wed, May 25, 2011 at 3:52 PM, MRAB wrote: > What do you mean by "may include the decoder state in its return value"? > > It does make sense that the values returned from tell() won't be in the > middle of an encoded sequence of bytes. If you take a look at the source code, tell() returns a lon

Re: Python's super() considered super!

2011-05-26 Thread Ian Kelly
On Thu, May 26, 2011 at 12:13 PM, Dotan Cohen wrote: > On Thu, May 26, 2011 at 19:39, Raymond Hettinger wrote: >>> It would also be great if some of you would upvote it on HackerNews. >> >> >> Here's a link to the super() how-to-guide and commentary:  bit.ly/ >> iFm8g3 >> > > Is that the same lin

Re: Python's super() considered super!

2011-05-27 Thread Ian Kelly
On Thu, May 26, 2011 at 10:31 AM, Raymond Hettinger wrote: > I just posted a tutorial and how-to guide for making effective use of > super(). I posted this already on the HackerNews thread but it seems to have largely gone unnoticed, so I'm reposting it here. It seems to me that the example of c

Re: Python's super() considered super!

2011-05-27 Thread Ryan Kelly
er().hello(msg) d = Diamond() d.hello("autosuper!") And you get the expected output: here we go... gunna say it yes I am hello autosuper! There may well be some cases where this breaks down, but it seems to do the right thing in simple cases. Not that I&

PyCon Australia 2011: Early Bird Closing Soon

2011-05-28 Thread Ryan Kelly
d for the conference: Standard Talks: A Python on the Couch (Mark Rees) Behaviour Driven Development (Malcolm Tredinnick) Benchmarking stuff made ridiculously easy (Tennessee Leeuwenburg) Bytecode: What, Why, and How to Hack it (Ryan Kelly) Developing Scientific Software in

Re: Beginner needs advice

2011-05-29 Thread Ian Kelly
On Sat, May 28, 2011 at 8:33 PM, harrismh777 wrote: > In this present case the straw-man was not "me," rather the straw-man was > the python language itself. You chose a code-snippet (one small puny dangle > that doesn't prove a thing) and used it to speak for the entire language! >  As though one

Re: scope of function parameters

2011-05-29 Thread Ian Kelly
On Sun, May 29, 2011 at 12:38 PM, Chris Angelico wrote: > I thought it basically functioned top-down. You get a different error > on the print line if there's a "bar = 42" *after* it. This could make > debugging quite confusing. > > Guess it's just one of the consequences of eschewing variable > d

Re: searching in list

2011-05-30 Thread Ian Kelly
On Mon, May 30, 2011 at 7:41 AM, Chris Angelico wrote: > If you're always going to look them up by the argument, the best way > would be to use a dictionary: > cache={arg1: res1, arg2: res2, ...} > > Then you can search with a simple: cache[arg135] > > You can add things with: cache[arg135]=res135

Re: Beginner needs advice

2011-05-30 Thread Ian Kelly
On Mon, May 30, 2011 at 6:43 PM, harrismh777 wrote: >> I realize you are now asserting that compatibility is a boolean >> condition, and that "totally incompatible" is a redundant phrase that >> you tossed out as a joke.  I don't know whether you're sincere or >> backpedaling, but in any case this

Re: Something is rotten in Denmark...

2011-05-31 Thread Ian Kelly
On Tue, May 31, 2011 at 12:48 AM, harrismh777 wrote: >     What is going on with the binding in the first construct... this seems > to reduce the usefulness of lambda to a considerable extent? I don't see why; as you've shown there are a couple of simple ways to avoid this problem. The trick is

Re: scope of function parameters (take two)

2011-05-31 Thread Ian Kelly
On Tue, May 31, 2011 at 1:38 AM, Daniel Kluev wrote: > @decorator.decorator > def copy_args(f, *args, **kw): >    nargs = [] >    for arg in args: >        nargs.append(copy.deepcopy(arg)) >    nkw = {} >    for k,v in kw.iteritems(): >        nkw[k] = copy.deepcopy(v) >    return f(*nargs, **nkw)

Re: scope of function parameters (take two)

2011-05-31 Thread Ian Kelly
On Tue, May 31, 2011 at 10:34 AM, Chris Kaynor wrote: > Is there any reason not to simplify this to: > def copy_args(f): >    @functools.wraps(f) >    def wrapper(*args, **kw): >        nargs = copy.deepcopy(args) >        nkw = copy.deepcopy(kw) >        return f(*nargs, **nkw) >    return wrappe

Re: Beginner needs advice

2011-05-31 Thread Ian Kelly
On Tue, May 31, 2011 at 11:56 AM, Dotan Cohen wrote: >>  If you disagree, then I invite you to list one example of two >> different things that are compatible. >> > > Men and women. This is a slightly different sense of the word compatible than we have been discussing: able to work together to pe

Re: Something is rotten in Denmark...

2011-05-31 Thread Ian Kelly
On Tue, May 31, 2011 at 3:14 PM, Martin Manns wrote: > $ python > Python 2.6.6 (r266:84292, Apr 20 2011, 11:58:30) > [GCC 4.5.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. fs=[] fs = [(lambda n: i + n) for i in range(10)] [fs[i](1) for i in ra

Re: Something is rotten in Denmark...

2011-05-31 Thread Ian Kelly
On Tue, May 31, 2011 at 2:18 PM, harrismh777 wrote: > If I'm understanding that correctly, then that means lambda is working as > designed, and that there are very subtle nuances to be aware of. In my > little case > >   (lambda n: i + n) > >   ... if the  i  goes out of scope before the anonymous

Re: scope of function parameters (take two)

2011-05-31 Thread Ian Kelly
On Tue, May 31, 2011 at 6:04 PM, Daniel Kluev wrote: > On Wed, Jun 1, 2011 at 3:16 AM, Ian Kelly wrote: >> >> There is no "decorator" module in the standard library.  This must be >> some third-party module.  The usual way to do this would be: > > Yes, b

Re: Updated blog post on how to use super()

2011-06-01 Thread Ian Kelly
On Wed, Jun 1, 2011 at 7:03 AM, Billy Mays wrote: > I read this when it was on HN the other day, but I still don't see what is > special about super().  It seems (from your post) to just be a stand in for > the super class name?  Is there something special I missed? It's not a stand-in for the su

Re: Updated blog post on how to use super()

2011-06-01 Thread Ian Kelly
On Wed, Jun 1, 2011 at 10:46 AM, Billy Mays wrote: > What it does is clear to me, but why is it interesting or special isn't. >  This looks like a small feature that would be useful in a handful of cases. Well, I agree with you there. The complexity introduced by super typically outweighs the be

Re: Comparison operators in Python

2011-06-01 Thread Ian Kelly
On Wed, Jun 1, 2011 at 12:50 PM, Anirudh Sivaraman wrote: > Hi > > I am a relative new comer to Python. I see that typing is strongly > enforced in the sense you can't concatenate or add a string and an > integer. However comparison between a string and an integer seems to > be permitted. Is there

Re: tictactoe script - commented - may have pedagogical value

2017-09-05 Thread Ian Kelly
On Mon, Sep 4, 2017 at 9:26 PM, wrote: > > """ > this program makes an optimal tictactoe move by answering the following > questions > in their given order until it is told where to put its mark: > > 1) can you win the game? > if so then do it > 2) could your opponent win the game if it was

Re: Please improve these comprehensions (was meaning of [ ])

2017-09-06 Thread Ian Kelly
On Wed, Sep 6, 2017 at 1:37 AM, Marko Rauhamaa wrote: > > Which reminds me of this puzzle I saw a couple of days ago: > >1 + 4 = 5 >2 + 5 = 12 >3 + 6 = 21 >8 + 11 = ? > > A mathematician immediately comes up with a "wrong" answer. There are no "wrong" answers with these kinds of p

Re: tictactoe script - commented - may have pedagogical value

2017-09-06 Thread Ian Kelly
On Tue, Sep 5, 2017 at 6:15 PM, Stefan Ram wrote: > Ian Kelly writes: >>Usually I've seen Tic Tac Toe implemented using the Minimax algorithm >>since the decision tree for Tic Tac Toe is quite shallow. > > This thread made me want to write a tic-tac-toe game. > &g

Re: tictactoe script - commented - may have pedagogical value

2017-09-07 Thread Ian Kelly
On Thu, Sep 7, 2017 at 2:05 AM, Chris Angelico wrote: > On Thu, Sep 7, 2017 at 5:11 PM, Steven D'Aprano >> I don't know why it places *two* pairs of crosses and naughts instead of >> one. Maybe the page is broken. > > I think it is, as part of being on the Internet Archive. To get a > working vers

Re: tictactoe script - commented - may have pedagogical value

2017-09-07 Thread Ian Kelly
On Thu, Sep 7, 2017 at 6:21 AM, Chris Angelico wrote: > On Thu, Sep 7, 2017 at 10:07 PM, Steve D'Aprano > wrote: >> As a practical technique, naturally using a lookup table of pre-computed >> values >> is a good solution to many problems. But you cannot say you are performing >> general computat

Re: detaching comprehensions

2017-09-08 Thread Ian Kelly
On Fri, Sep 8, 2017 at 2:24 PM, Stefan Ram wrote: > Maybe you all know this, but to me this is something new. > I learnt it by trial and error in the Python 3.6.0 console. > > Most will know list comprehensions: > > |>>> [ i for i in range( 3, 5 )] > |[3, 4] > > I found out that the compre

Re: detaching comprehensions

2017-09-08 Thread Ian Kelly
On Fri, Sep 8, 2017 at 3:03 PM, Peter Otten <__pete...@web.de> wrote: *"bar", > ('b', 'a', 'r') Now that just makes my eyes hurt. -- https://mail.python.org/mailman/listinfo/python-list

Re: Not appending ("lib") to sys.path breaks tests.

2017-09-08 Thread Ian Kelly
On Fri, Sep 8, 2017 at 3:18 PM, Leam Hall wrote: > A kind soul pointed out that my code uses a sys.path.append("lib") to get > files to be imported: > > sys.path.append("lib") > from character_tools import * > > He noted that having an __init__.py in lib and using: > > from

Re: Not appending ("lib") to sys.path breaks tests.

2017-09-08 Thread Ian Kelly
On Fri, Sep 8, 2017 at 3:54 PM, Leam Hall wrote: > On 09/08/2017 05:41 PM, Ian Kelly wrote: > >> I'm confused about where the character_tools import is made. If that's >> within a module in the lib package, it should be fine. > > >> It looks like it'

Re: Using Python 2

2017-09-10 Thread Ian Kelly
On Sat, Sep 9, 2017 at 9:26 PM, Rick Johnson wrote: > On Friday, September 8, 2017 at 8:57:56 AM UTC-5, Ned Batchelder wrote: >> On 9/8/17 6:12 AM, Leam Hall wrote: >> > I've read comments about Python 3 moving from the Zen of Python. I'm a >> > "plain and simple" person myself. Complexity to supp

Re: Using Python 2

2017-09-10 Thread Ian Kelly
On Sun, Sep 10, 2017 at 10:06 AM, Rick Johnson wrote: > Ian wrote: >> Rick Johnson wrote: >> > Ned Batchelder wrote: >> > > Leam Hall wrote: >> > > > >> > > > I've read comments about Python 3 moving from the Zen of >> > > > Python. I'm a "plain and simple" person myself. >> > > > Complexity to su

Re: Simple game board GUI framework

2017-09-11 Thread Ian Kelly
On Mon, Sep 11, 2017 at 10:36 AM, ROGER GRAYDON CHRISTMAN wrote: > I would echo the recommendation of teaching something you are already > familiar with doing. Perhaps you can find a different class hierarchy to > work > with. > > I remember that the first time I really began to grok OOP was in

Re: Simple game board GUI framework

2017-09-11 Thread Ian Kelly
On Mon, Sep 11, 2017 at 6:26 PM, Dennis Lee Bieber wrote: > I used to have a character on Furtoonia whose "tail" was described as > having a naked singularity at the tip (the tail was an object that > automatically followed the character around) -- the character's "home" was > inside said

Re: Simple board game GUI framework

2017-09-13 Thread Ian Kelly
On Tue, Sep 12, 2017 at 10:39 PM, Rick Johnson wrote: >> > board[r,c] = lbl > > Dude, that tuple is naked! And nudity in public places is > not cool; unless of course your code is a Ms. America model, > or it resides in a nudist colony (Hey, don't forget your > "sitting towel"!), whic

Re: String to Dictionary conversion in python

2017-09-14 Thread Ian Kelly
On Fri, Sep 15, 2017 at 12:01 AM, wrote: > Hi, > > Can anyone help me in the below issue. > > I need to convert string to dictionary > > string = " 'msisdn': '7382432382', 'action': 'select', 'sessionId': '123', > 'recipient': '7382432382', 'language': 'english'" > > Can anyone help me with the

Re: Research paper "Energy Efficiency across Programming Languages: How does energy, time, and memory relate?"

2017-09-16 Thread Ian Kelly
On Sat, Sep 16, 2017 at 8:01 PM, Steve D'Aprano wrote: > On Sun, 17 Sep 2017 09:04 am, breamore...@gmail.com wrote: > >> I thought some might find this >> https://sites.google.com/view/energy-efficiency-languages/ interesting. > > "Made with the new Google Sites, an effortless way to create beauti

Re: Project Euler 20.

2017-09-24 Thread Ian Kelly
On Sun, Sep 24, 2017 at 4:35 PM, Paul Rubin wrote: > > "Robert L." writes: > >> Find the sum of the digits in the number 100! > > In Python? > > So you have come to plague us here too. > > >>> sum(ord(c)-ord('0') for c in str(reduce(lambda a,b: a*b, range(1,101),1))) > 648 Or for any Python 2.6

Re: Looking for an algorithm - calculate ingredients for a set of recipes

2017-09-25 Thread Ian Kelly
On Mon, Sep 25, 2017 at 6:49 AM, Paul Moore wrote: > I'm trying to work out a good algorithm to code a calculation I need > to do. I can see brute force ways of handling the problem, but I keep > getting bogged down in details, and the question seems like it's > something that should have been sol

Re: on a very slow function

2017-10-02 Thread Ian Kelly
On Sun, Oct 1, 2017 at 8:14 PM, Steve D'Aprano wrote: > > On Mon, 2 Oct 2017 12:00 pm, Ben Bacarisse wrote: > > > >> Better: > >> > >> last = (pow(last, 2, N) + (2 % N)) % N > > > > You meant c rather than 2, I think. > > Oops, yes, that was a typo. > > > > And I'm not convinced all the %Ns > > ar

Re: newb question about @property

2017-10-02 Thread Ian Kelly
On Mon, Oct 2, 2017 at 1:32 PM, Bill wrote: > @property def circumference(self): > return 2 * math.pi *self.radius Of course the *proper* formula here is just math.tau * self.radius. -- https://mail.python.org/mailman/listinfo/python-list

Re: newb question about @property

2017-10-03 Thread Ian Kelly
On Tue, Oct 3, 2017 at 4:41 AM, Steve D'Aprano wrote: > On Tue, 3 Oct 2017 06:51 am, Bill wrote: > >> Can you inspire me with a good decorator problem (standard homework >> exercise-level will be fine)? > > > Here is a nice even dozen problems for you. Please ask for clarification if > any > are

Re: newb question about @property

2017-10-03 Thread Ian Kelly
On Tue, Oct 3, 2017 at 9:16 AM, Jorge Gimeno wrote: > No, I see this as teaching the skills involved to drive a car. Practicing a > turn, scanning gauges, and checking blind spots are all a part of driving. > When one is learning, it's easier to learn these in isolation so when the > problem must

Re: newb question about @property

2017-10-04 Thread Ian Kelly
On Wed, Oct 4, 2017 at 5:07 AM, bartc wrote: > It is just being elitist. I have a preference for keeping things simple and > avoiding unnecessary complexity. But with programming languages many do have > a penchant for the latter. > > As an example, a recent discussion on comp.lang.c was about imp

Re: Constants [was Re: newb question about @property]

2017-10-04 Thread Ian Kelly
On Wed, Oct 4, 2017 at 9:08 AM, Steve D'Aprano wrote: > But in large projects, especially those where you cannot trust every module in > the project to obey the naming convention, I can see that this lack might > contribute to the perception, if not the fact, of Python being a bit too > unsafe for

Re: The "loop and a half"

2017-10-08 Thread Ian Kelly
On Sun, Oct 8, 2017 at 10:49 PM, Chris Angelico wrote: > On Mon, Oct 9, 2017 at 3:35 PM, Mikhail V wrote: >>> Have you ever worked on a slow remote session where a GUI is >>> completely impracticable (or maybe even unavailable), and redrawing >>> the screen is too expensive to do all the time? >>

Re: An endless loop

2017-10-16 Thread Ian Kelly
On Sat, Oct 14, 2017 at 8:10 PM, Stefan Ram wrote: > I made an error I made a thousand times before. > > I had programmed an endless loop. > > But never did I see before so clear why it's called > an endless loop. (Tested in IDLE.) > > from turtle import * > > reset(); reset(); shape( 'tur

Re: Cooperative class tree filtering

2017-10-16 Thread Ian Kelly
On Thu, Oct 12, 2017 at 5:07 PM, Alberto Berti wrote: > Now, what i ideally want is to get rid of that super() call at the end of > the methods in classes B and c and to code that "fallback to what my > superclass says" coded into A's implementation, where it kicks in if the > method in the target

Re: Cooperative class tree filtering

2017-10-16 Thread Ian Kelly
On Mon, Oct 16, 2017 at 8:20 PM, Ian Kelly wrote: > On Thu, Oct 12, 2017 at 5:07 PM, Alberto Berti > wrote: >> I would really like to find a way to do this that doesn't involve >> decorating the methods in A subclasses to free the final developer to >> remember to i

Re: multiprocessing shows no benefit

2017-10-18 Thread Ian Kelly
On Wed, Oct 18, 2017 at 9:46 AM, Jason wrote: > #When I change line19 to True to use the multiprocessing stuff it all slows > down. > > from multiprocessing import Process, Manager, Pool, cpu_count > from timeit import default_timer as timer > > def f(a,b): > return dict_words[a]-b Since

Re: multiprocessing shows no benefit

2017-10-18 Thread Ian Kelly
On Wed, Oct 18, 2017 at 10:13 AM, Ian Kelly wrote: > On Wed, Oct 18, 2017 at 9:46 AM, Jason wrote: >> #When I change line19 to True to use the multiprocessing stuff it all slows >> down. >> >> from multiprocessing import Process, Manager, Pool, cpu_count >> fr

Re: multiprocessing shows no benefit

2017-10-18 Thread Ian Kelly
On Wed, Oct 18, 2017 at 10:21 AM, Jason wrote: > On Wednesday, October 18, 2017 at 12:14:30 PM UTC-4, Ian wrote: >> On Wed, Oct 18, 2017 at 9:46 AM, Jason wrote: >> > #When I change line19 to True to use the multiprocessing stuff it all >> > slows down. >> > >> > from multiprocessing import Proc

Re: Searching For Old Posts On Python

2017-10-18 Thread Ian Kelly
On Mon, Oct 16, 2017 at 10:42 PM, Cai Gengyang wrote: > https://duckduckgo.com/html/?q=%22Cai%20Gengyang%22%20python This > seems to be the only method that works, using DuckDuckGo Or any search engine, really. https://www.google.com/search?q=site%3Apython.org+cai+gengyang -- https://mail.p

Re: Compression of random binary data

2017-10-23 Thread Ian Kelly
On Mon, Oct 23, 2017 at 1:42 PM, wrote: > Wow, do programmers actually use zscii. That is huge. So much wated space. Not really. ZSCII is only relevant if you're writing Z-code or a Z-code interpreter. Those in turn are only relevant if you're writing Infocom games. -- https://mail.python.org/m

Re: Compression of random binary data

2017-10-24 Thread Ian Kelly
On Tue, Oct 24, 2017 at 12:20 AM, Gregory Ewing wrote: > danceswithnumb...@gmail.com wrote: >> >> I did that quite a while ago. 352,954 kb. > > > Are you sure? Does that include the size of all the > code, lookup tables, etc. needed to decompress it? My bet is that danceswithnumbers does indeed h

Re: Compression of random binary data

2017-10-25 Thread Ian Kelly
On 10/24/17, Richard Damon wrote: > My understanding of the 'Random Data Comprehensibility' challenge is > that is requires that the compression take ANY/ALL strings of up to N > bits, and generate an output stream no longer than the input stream, and > sometime less. That's incorrect, at least o

Re: Compression of random binary data

2017-10-26 Thread Ian Kelly
On Thu, Oct 26, 2017 at 2:38 PM, wrote: > > Thomas Jollans > > On 2017-10-25 23:22, danceswi...@gmail.com wrote: >> With every transform the entropy changes, > > That's only true if the "transform" loses or adds information. > > If it loses information, that's lossy compression, which is only use

Re: Compression of random binary data

2017-10-27 Thread Ian Kelly
On Thu, Oct 26, 2017 at 8:19 PM, wrote: > It looks like that averages my two examples. I don't know how you can look at two numbers and then look at a third number that is larger than both of them and conclude it is the average. > H by the way that equation is really coolwhy does it ret

Re: Compression of random binary data

2017-10-27 Thread Ian Kelly
On Thu, Oct 26, 2017 at 8:48 PM, wrote: > Shouldn't that be? > > py> 16 * (-7/16 * math.log2(7/16) - 6/16 * math.log2(6/16)) = No, that's failing to account for 3/16 of the probability space. -- https://mail.python.org/mailman/listinfo/python-list

Re: Just a quick question about main()

2017-10-27 Thread Ian Kelly
In addition to what others have answered, if the code in question has any variables then I'll prefer to put it inside a function and call the function. This ensures that the variables are local and not going. It's a minor code hygiene point, but a good practice in my opinion. -- https://mail.pytho

Re: Just a quick question about main()

2017-10-27 Thread Ian Kelly
On Oct 27, 2017 5:38 PM, "Ian Kelly" wrote: In addition to what others have answered, if the code in question has any variables then I'll prefer to put it inside a function and call the function. This ensures that the variables are local and not going. It's a minor code hygie

Re: Compression of random binary data

2017-10-28 Thread Ian Kelly
On Oct 28, 2017 10:30 AM, "Stefan Ram" wrote: > Well, then one can ask about the entropy of a data source > thatt only is emitting this message. (If it needs to be endless: > thatt only is emitting this message repeatedly.) If there is only one possible message then the entropy is zero. -1.0 * l

Re: Compression of random binary data

2017-10-29 Thread Ian Kelly
On Oct 28, 2017 5:53 PM, "Chris Angelico" wrote: > One bit. It might send the message, or it might NOT send the message. Not sending the message is equivalent to having a second possible message. -- https://mail.python.org/mailman/listinfo/python-list

Re: Thread safety issue (I think) with defaultdict

2017-11-01 Thread Ian Kelly
On Tue, Oct 31, 2017 at 11:38 AM, Israel Brewster wrote: > A question that has arisen before (for example, here: > https://mail.python.org/pipermail/python-list/2010-January/565497.html > ) is > the question of "is defaultd

Re: Thread safety issue (I think) with defaultdict

2017-11-03 Thread Ian Kelly
On Thu, Nov 2, 2017 at 10:27 AM, Israel Brewster wrote: > >> On Nov 1, 2017, at 4:53 PM, Steve D'Aprano >> wrote: >> >> On Thu, 2 Nov 2017 05:53 am, Israel Brewster wrote: >> >> [...] >>> So the end result is that the thread that "updates" the dictionary, and the >>> thread that initially *popul

Re: replacing `else` with `then` in `for` and `try`

2017-11-03 Thread Ian Kelly
On Fri, Nov 3, 2017 at 8:32 AM, Chris Angelico wrote: > On Fri, Nov 3, 2017 at 10:49 PM, Jon Ribbens > wrote: >> On 2017-11-03, Steve D'Aprano wrote: >>> On Fri, 3 Nov 2017 03:31 am, Jon Ribbens wrote: No, it's an obvious bug. You have a 'for...else' with no 'break'. Like I said, that

Re: replacing `else` with `then` in `for` and `try`

2017-11-03 Thread Ian Kelly
On Fri, Nov 3, 2017 at 3:25 PM, Stefan Ram wrote: > Jon Ribbens writes: >>No, it's an obvious bug. You have a 'for...else' with no 'break'. >>Like I said, that should probably be a syntax error. > > It should make the syntax of Python much more complicated, > when one would try to encode this

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

2017-11-07 Thread Ian Kelly
On Fri, Nov 3, 2017 at 11:55 PM, Ben Finney wrote: > Ian Kelly writes: > >> Please stop defending the use of incivility on this list. > > Please stop conflating people, who deserve civility, with ideas. We must > not allow the civility deserved by people, to prevent us f

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

2017-11-07 Thread Ian Kelly
On Sat, Nov 4, 2017 at 6:40 AM, Chris Angelico wrote: > On Sat, Nov 4, 2017 at 11:25 PM, Jon Ribbens > wrote: >> On 2017-11-04, Ben Finney wrote: >>> To respond to the criticism of an idea – criticism containing no mention >>> of the person – as though it “clearly refers to the [person]”, is of

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

2017-11-07 Thread Ian Kelly
On Tue, Nov 7, 2017 at 12:10 PM, Chris Angelico wrote: > On Wed, Nov 8, 2017 at 4:28 AM, Ian Kelly wrote: >> On Sat, Nov 4, 2017 at 6:40 AM, Chris Angelico wrote: >>> Maybe we're not defending the abuse of other contributors. Maybe we're >>> defending a legi

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

2017-11-07 Thread Ian Kelly
On Tue, Nov 7, 2017 at 4:28 PM, Steve D'Aprano wrote: > On Wed, 8 Nov 2017 04:28 am, Ian Kelly wrote: > >> Steve's manufactured interactive example ("manufactured" because >> who really uses for-else interactively? If I really care that much >> abou

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

2017-11-08 Thread Ian Kelly
On Tue, Nov 7, 2017 at 2:42 PM, Chris Angelico wrote: > On Wed, Nov 8, 2017 at 8:16 AM, Ian Kelly wrote: >>> Not one of these is syntactically invalid. Why should "else without >>> break" be trapped by the parser? Your other examples mostly have good >>&g

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