Re: In List Query -> None Case Sensitive?

2011-03-31 Thread Ian Kelly
On Thu, Mar 31, 2011 at 3:14 PM, Wehe, Marco wrote: > Hi, > > > > I am doing a search through a list of files but the text the casing doesn't > match. My list is all upper case but the real files are all different. Is > there a smooth way of searching through the list without going full on > reg

Re: newbie question

2011-04-01 Thread Ian Kelly
On Fri, Apr 1, 2011 at 1:52 PM, Karl <8213543ggxnvjx...@kabelmail.de> wrote: > Hello, > > one beginner question: > > aList = [0, 1, 2, 3, 4] > > bList = [2*i for i in aList] > > sum = 0 > > for j in bList: > > sum = sum + bList[j] > >     print j > > 0 > > 2 > > 4 > > IndexError: 'list index out of

Re: Extracting repeated words

2011-04-01 Thread Ian Kelly
On Fri, Apr 1, 2011 at 2:54 PM, candide wrote: > Another question relative to regular expressions. > > How to extract all word duplicates in a given text by use of regular > expression methods ?  To make the question concrete, if the text is > > -- > Now is better than never. > Alt

Re: Problem regarding returning list

2011-04-03 Thread Ian Kelly
On Sun, Apr 3, 2011 at 1:12 AM, sl33k wrote: > I am trying to return a list of items modified with each item also > showing like the number of modifications. > > Returning a list of user modified items was done easily but I would > also like to display the item modified by the user and the > modif

Re: a better way to invert a list?

2011-04-05 Thread Ian Kelly
On Tue, Apr 5, 2011 at 3:17 PM, scattered wrote: > Greetings, > > I've been playing around (in Python 3.1) with permutations of > 0,1,...,n-1, represented by lists, p, of length n, where p[i] = the > image of i under the permutation. I wanted to be able to calculate the > inverse of such a permuta

Re: a better way to invert a list?

2011-04-06 Thread Ian Kelly
On Wed, Apr 6, 2011 at 1:51 PM, Paul Rubin wrote: >    In Haskell or ML, you can use patterns that contain wild >    cards that play a role in the pattern-matching but don't establish any >    binding. Can that be done in Python? > > Not as much.  You could say something like > >         sorted(en

Re: Generators and propagation of exceptions

2011-04-08 Thread Ian Kelly
On Fri, Apr 8, 2011 at 9:55 AM, r wrote: > I had a problem for which I've already found a "satisfactory" > work-around, but I'd like to ask you if there is a better/nicer > looking solution. Perhaps I'm missing something obvious. > > The code looks like this: > > stream-of-tokens = token-generator

Re: Argument of the bool function

2011-04-08 Thread Ian Kelly
On Fri, Apr 8, 2011 at 10:26 AM, candide wrote: x=42 bool(x=5) > True > > > but _expression_ : > > x=42 > > > has no value. "x=42" is an assignment statement, not an expression. In "bool(x=5)", "x=5" is also not an expression. It's passing the expression "5" in as the parameter x,

Re: [OT] Free software versus software idea patents

2011-04-11 Thread Ian Kelly
On Sun, Apr 10, 2011 at 6:04 PM, harrismh777 wrote: > The deal with motive number (2) is that there are fewer and fewer teams who > are concerned with interoperability. For instance (my team), we moved our > stuff to gnulinux based systems and dumped Microsoft completely... we have > no need for t

Re: Feature suggestion -- return if true

2011-04-12 Thread Ian Kelly
On Tue, Apr 12, 2011 at 12:00 PM, Teemu Likonen wrote: > I'm a simple Lisp guy who wonders if it is be possible to add some kind > of macros to the language. Then features like this could be added by > anybody. Lisp people do this all the time and there is no need for > feature requests or any dis

Re: Feature suggestion -- return if true

2011-04-12 Thread Ian Kelly
On Tue, Apr 12, 2011 at 12:25 PM, Ian Kelly wrote: > On Tue, Apr 12, 2011 at 12:00 PM, Teemu Likonen wrote: >> I'm a simple Lisp guy who wonders if it is be possible to add some kind >> of macros to the language. Then features like this could be added by >> anybody. L

Re: [OT] Free software versus software idea patents

2011-04-12 Thread Ian Kelly
On Tue, Apr 12, 2011 at 3:22 AM, harrismh777 wrote: >    This is very difficult... and I'm not dodging the ball here... its just > the truth. The 'market share' data are bogus. Reason? ... because the free > software 'market' is not a market. This is just word-play. It has no bearing on the accu

Re: [OT] Free software versus software idea patents

2011-04-12 Thread Ian Kelly
On Tue, Apr 12, 2011 at 2:51 PM, Dan Stromberg wrote: > This data is of course skewed a bit toward computers that people are > using web browsers on. Right, Linux servers are most likely underrepresented. At best the data indicates what the population at large is using on their desktops. > Also

Re: [OT] Free software versus software idea patents

2011-04-14 Thread Ian Kelly
On Thu, Apr 14, 2011 at 12:04 AM, harrismh777 wrote: >    How mamy times have you altered the identity of your web browser so that > the web site would 'work'? You know, stupid messages from the server that > say, "We only support IE 6+, upgrade your browser...",  so you tell it > you're using IE

Re: Python IDE/text-editor

2011-04-15 Thread Ian Kelly
On Fri, Apr 15, 2011 at 9:20 PM, Alec Taylor wrote: > Good Afternoon, > > I'm looking for an IDE which offers syntax-highlighting, > code-completion, tabs, an embedded interpreter and which is portable > (for running from USB on Windows). > > Here's a mockup of the app I'm looking for: http://i52.

Re: How to create a (transparent) decorator with status information?

2011-04-18 Thread Ian Kelly
On Mon, Apr 18, 2011 at 6:47 AM, Timo Schmiade wrote: > Hi all, > > I'm currently occupying myself with python's decorators and have some > questions as to their usage. Specifically, I'd like to know how to > design a decorator that maintains a status. Most decorator examples I > encountered use a

Re: How to create a (transparent) decorator with status information?

2011-04-19 Thread Ian Kelly
On Tue, Apr 19, 2011 at 1:12 AM, Timo Schmiade wrote: > Just one question remains now: What is a "Borg" in this context? http://code.activestate.com/recipes/66531/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Namespaces in functions vs classes

2011-04-19 Thread Ian Kelly
On Tue, Apr 19, 2011 at 10:31 AM, Ethan Furman wrote: > Gerald Britton wrote: >> >> I now understand the Python does >> not consider a class definition as a separate namespace as it does for >> function definitions.  That is a helpful understanding. > > That is not correct.  Classes are separate n

Re: List comprehension vs filter()

2011-04-19 Thread Ian Kelly
On Tue, Apr 19, 2011 at 9:59 PM, Chris Angelico wrote: > On Wed, Apr 20, 2011 at 1:45 PM, Chris Rebert wrote: >> Built-ins aren't quite the same as globals, but essentially yes: > > Sure. That might explain some of the weirdness, but it doesn't explain > why things were still weird with the varia

Re: List comprehension vs filter()

2011-04-20 Thread Ian Kelly
On Wed, Apr 20, 2011 at 4:41 AM, Peter Otten <__pete...@web.de> wrote: > The assignment writes to the local namespace, the lambda function reads from > the global namespace; this will only work as expected if the two namespaces > are the same: > exec """type = 42; print filter(lambda x: x == t

Re: List comprehension vs filter()

2011-04-20 Thread Ian Kelly
On Wed, Apr 20, 2011 at 12:03 PM, Chris Angelico wrote: > On Thu, Apr 21, 2011 at 12:44 AM, Ian Kelly wrote: >> So, the question for the OP:  Is this file being run with execfile? >> > > Not execfile per se; the code is fetched from the database and then > execut

Re: Hello Sweet Friends

2011-04-21 Thread Ian Kelly
On Thu, Apr 21, 2011 at 12:28 AM, harrismh777 wrote: >   I don't like SPAM with my eggs and ham... Nor do the rest of us, so please don't help it circumvent our spam filters by reposting it. -- http://mail.python.org/mailman/listinfo/python-list

Re: A question about Python Classes

2011-04-22 Thread Ian Kelly
On Fri, Apr 22, 2011 at 7:49 AM, Kyle T. Jones wrote: >> You don't need to create an instance of BaseHandler.  You have the >> class, Python knows you have the class -- Python will look there if the >> subclasses lack an attribute. >> >> ~Ethan~ >> > > Really?  That's not at all how I thought it w

Re: Argument of the bool function

2011-04-25 Thread Ian Kelly
On Mon, Apr 25, 2011 at 3:28 PM, Thomas Rachel wrote: > Am 25.04.2011 16:29, schrieb Thomas Rachel: > >> or maybe even better (taking care for closures): >> >> function = bool >> value = 'the well at the end of the world' >> ## ... >> actions.append(lambda val=value: function(val)) >> ## ... >> fo

Re: Composition instead of inheritance

2011-04-28 Thread Ian Kelly
On Thu, Apr 28, 2011 at 11:15 AM, Ethan Furman wrote: > For anybody interested in composition instead of multiple inheritance, I > have posted this recipe on ActiveState (for python 2.6/7, not 3.x): > > http://code.activestate.com/recipes/577658-composition-of-classes-instead-of-multiple-inherit/

Re: Composition instead of inheritance

2011-04-29 Thread Ian Kelly
On Fri, Apr 29, 2011 at 3:09 PM, Carl Banks wrote: > Here is my advice on mixins: > > Mixins should almost always be listed first in the bases.  (The only > exception is to work around a technicality.  Otherwise mixins go first.) > > If a mixin defines __init__, it should always accept self, *arg

Re: Composition instead of inheritance

2011-04-29 Thread Ian Kelly
On Fri, Apr 29, 2011 at 5:54 PM, Carl Banks wrote: >> Really, *any* class that uses super().__init__ should take its >> arguments and pass them along in this manner. > > If you are programming defensively for any possible scenario, you might try > this (and you'd still fail). > > In the real worl

Re: Fibonacci series recursion error

2011-04-29 Thread Ian Kelly
On Fri, Apr 29, 2011 at 9:57 PM, Jason Friedman wrote: > The first call to fib() recursively calls fib() twice.  Each of those > will call fib() twice.  Each of those will call fib() twice.  Pretty > soon, you've got a lot of calls. Which is hell for the running time, but doesn't answer the quest

Re: "raise (type, value, traceback)" and "raise type, value, traceback"

2011-05-02 Thread Ian Kelly
On Mon, May 2, 2011 at 11:23 AM, Jack Bates wrote: > Hi, anyone know why these two statements aren't equivalent? > > raise (type, value, traceback) > > raise type, value, traceback The latter is the syntax of the raise statement: up to 3 expressions, separated by commas. The former has a single

Re: Coolest Python recipe of all time

2011-05-02 Thread Ian Kelly
On Mon, May 2, 2011 at 2:48 PM, David Monaghan wrote: > On Mon, 2 May 2011 10:33:31 -0700 (PDT), Raymond Hettinger > wrote: > >>I think it is time to give some visibility to some of the instructive >>and very cool recipes in ActiveState's python cookbook. >> >>My vote for the coolest recipe of al

Re: Fibonacci series recursion error

2011-05-02 Thread Ian Kelly
On Mon, May 2, 2011 at 3:50 PM, harrismh777 wrote: > Thomas Rachel wrote: >>> >>> ... because each recursion level 'return' calls fib() twice, and each of >>> those calls fib() twice, and you get the point... >> >> yes - but they are called one after the other, so the "twice" call >> counts only f

Re: Coolest Python recipe of all time

2011-05-02 Thread Ian Kelly
On Mon, May 2, 2011 at 11:04 PM, Stefan Behnel wrote: > The bad thing about this recipe is that it requires quite a bit of > background knowledge in order to infer that the code the developer is > looking at is actually correct. At first sight, it looks like an evil hack, > and the lack of documen

Re: Recursion or iteration (was Fibonacci series recursion error)

2011-05-02 Thread Ian Kelly
On Mon, May 2, 2011 at 11:27 PM, Dan Stromberg wrote: > But the recursive solution has time complexity of O(logn).  The iterative > solution has time complexity of O(n).  That's a significant difference for > large n - a significant benefit of the recursive version. It's linear as written. I th

Re: Coolest Python recipe of all time

2011-05-03 Thread Ian Kelly
On Tue, May 3, 2011 at 3:54 PM, Chris Angelico wrote: > On Wed, May 4, 2011 at 2:43 AM, Raymond Hettinger wrote: >> We should have a separate thread for the most practical, best >> documented, least surprising, and most boring recipe ;-) > > a += b   # Adds b to a in-place. Polymorphic - works on

Re: Fibonacci series recursion error

2011-05-03 Thread Ian Kelly
On Tue, May 3, 2011 at 3:41 PM, Chris Angelico wrote: > On Wed, May 4, 2011 at 3:10 AM, harrismh777 wrote: >> If your point is that the infinite process is the problem, I agree. But my >> point is that the cpu crunch and the rate at which the call stack is filled >> has to do with the double call

Re: Basic interaction with another program

2011-05-04 Thread Ian Kelly
On Wed, May 4, 2011 at 10:52 AM, Grant Edwards wrote: > On 2011-05-04, Matty Sarro wrote: >> On Wed, May 4, 2011 at 12:34 PM, ETP wrote: >>> I have a dos program (run in a window) that I would like to control >>> with a script. > >> Look into the pexpect library, it'll make this easy as punch. >

Re: Embedding Python's library as zip file

2011-05-04 Thread Ian Kelly
On Wed, May 4, 2011 at 3:09 PM, Wojtek Mamrak wrote: > Hello, > > I spent a lot of time googling for a solution of this problem, with no > result. > > I have a C++ application, in which I would like to embed Python interpreter. > I don't want to rely on an interpreter being installed on user machi

Re: What other languages use the same data model as Python?

2011-05-04 Thread Ian Kelly
On Wed, May 4, 2011 at 3:35 PM, harrismh777 wrote: > Grant Edwards wrote: >>> >>> We do not consider passing a pointer as*by value*  because its an >>> >  address; by definition, that is pass-by-reference. >> >> No, it isn't.  It's pass by value.  The fact that you are passing a >> value that is a

Re: Embedding Python's library as zip file

2011-05-05 Thread Ian Kelly
On Thu, May 5, 2011 at 4:55 AM, Wojtek Mamrak wrote: > Thanks for the reply! > >> Can you import from zip files when running the Python.exe interpreter? > When I zip the folder "Lib" into Python27.zip and later rename it and > try to run the python.exe, I receive an error: > "Import error: no modu

Re: What other languages use the same data model as Python?

2011-05-05 Thread Ian Kelly
On Thu, May 5, 2011 at 9:41 AM, John Nagle wrote: > On 5/5/2011 3:06 AM, Gregory Ewing wrote: >> >> John Nagle wrote: >> >>> A reasonable compromise would be that "is" is treated as "==" on >>> immutable objects. >> >> That wouldn't work for tuples, which can contain references >> to other objects

Re: Need to solve the "Stateless HTTP" problem

2011-05-05 Thread Ian Kelly
On Thu, May 5, 2011 at 8:22 AM, Gnarlodious wrote: > My scripting has grown to the point where the Apache server is a > problem. My Python websites run and quit, which means I need to save > data and recreate everything next page load. Bulky and slow. What is > the simplest solution? > > I am runn

Re: What other languages use the same data model as Python?

2011-05-05 Thread Ian Kelly
On Thu, May 5, 2011 at 10:58 AM, harrismh777 wrote: > Grant Edwards wrote: >> >> That's what I was trying to say, but probably not as clearly.  The "&" >> operatore returnas a_value_  that the OP passes_by_value_  to a >> function.  That function then uses the "*" operator to use that value >> to

Re: Embedding Python's library as zip file

2011-05-05 Thread Ian Kelly
On Thu, May 5, 2011 at 2:34 PM, Wojtek Mamrak wrote: > Maybe I am missing the point, but I think I am not able to do this. > When I remove the "Lib" folder and try to run Python.exe, the python > console window closes rapidly, so that it is hard to read any message > displayed in it and obvioulsy

Re: seems like a bug in isinstance()

2011-05-06 Thread Ian Kelly
On Fri, May 6, 2011 at 4:20 AM, dmitrey wrote: > Thanks Cris, however, I had understood reason of the bug and mere > informed Python developers of the bug to fix it. No you haven't. Few if any Python developers make a habit of reading this newsgroup. To actually report the issue so that it migh

Re: Coolest Python recipe of all time

2011-05-06 Thread Ian Kelly
On Fri, May 6, 2011 at 10:59 AM, Steven D'Aprano wrote: > As written, amb is just a brute-force solver using more magic than is > good for any code, but it's fun to play with. This isn't really amb; as you said it's just a brute-force solver with some weird syntax. The whole point of amb is to e

Re: Coolest Python recipe of all time

2011-05-06 Thread Ian Kelly
On Fri, May 6, 2011 at 12:36 PM, Ian Kelly wrote: > This is typically implemented using continuations, and I'm not sure > whether a true amb could actually be achieved in Python without adding > continuations or flow-control macros to the language. I stand corrected. After pokin

Re: string formatting

2011-05-06 Thread Ian Kelly
On Fri, May 6, 2011 at 1:39 PM, harrismh777 wrote: > harrismh777 wrote:    OP wrote: > >> (1) "the %s is %s" % ('sky', 'blue') >> >> (2) "the {0} is {1}".format('sky', 'blue') >> >> (3) "the {} is {}".format('sky', 'blue') > >   On the other hand, consider this 3.x code snip: > >   print("the %s i

Re: Python 3 dict question

2011-05-06 Thread Ian Kelly
On Fri, May 6, 2011 at 1:51 PM, Chris Rebert wrote: > On Fri, May 6, 2011 at 12:40 PM, dmitrey wrote: >> hi all, >> suppose I have Python dict myDict and I know it's not empty. >> I have to get any (key, value) pair from the dict (no matter which >> one) and perform some operation. >> In Python 2

Re: Python 3 dict question

2011-05-06 Thread Ian Kelly
On Fri, May 6, 2011 at 1:57 PM, dmitrey wrote: > Unfortunately, it doesn't work, it turn out to be dict_items: next({1:2}.items()) > Traceback (most recent call last): >  File "", line 1, in > TypeError: dict_items object is not an iterator So call iter() on it first: next(iter(myDict.item

Re: checking if a list is empty

2011-05-06 Thread Ian Kelly
On Fri, May 6, 2011 at 4:21 PM, Philip Semanchuk wrote: > What if it's not a list but a tuple or a numpy array? Often I just want to > iterate through an element's items and I don't care if it's a list, set, etc. > For instance, given this function definition -- > > def print_items(an_iterable):

Re: Dictionary Views -- good examples? [was Re: Python 3 dict question]

2011-05-06 Thread Ian Kelly
On Fri, May 6, 2011 at 4:49 PM, Ethan Furman wrote: > Ian Kelly wrote: >> >> On Fri, May 6, 2011 at 1:57 PM, dmitrey wrote: >>> >>> Unfortunately, it doesn't work, it turn out to be dict_items: >>>>>> >>>>>> next({1:2}.it

Re: Coolest Python recipe of all time

2011-05-07 Thread Ian Kelly
On Sat, May 7, 2011 at 2:29 AM, Steven D'Aprano wrote: >> This isn't really amb; as you said it's just a brute-force solver with >> some weird syntax.  The whole point of amb is to enable >> non-deterministic programming, such as this: > [...] >> The amb engine would conceptually execute this func

Re: Python3: imports don't see files from same directory?

2011-05-07 Thread Ian Kelly
On Sat, May 7, 2011 at 4:02 AM, dmitrey wrote: > hi all, > I try to port my code to Python 3 and somehow files don't see files > from same directory, so I have to add those directories explicitly, > e.g. > import sys > sys.path += [...] > > Also, it leads to bugs like this one: > http://groups.goo

Re: checking if a list is empty

2011-05-08 Thread Ian Kelly
On Sun, May 8, 2011 at 9:33 PM, harrismh777 wrote: >   Why should the negation of a list imply that the list empty?  ... nor any > other abstract condition which is not well suited to 'not' ? (forget python > for a moment... then move on to my argument...) > >   What made the python development te

Re: Inconsistency with split() - Script, OS, or Package Problem?

2011-05-09 Thread Ian Kelly
On Mon, May 9, 2011 at 12:10 PM, James Wright wrote: > Hello, > > I have been using a script on several boxes that have been around for > a while, and everything works just fine.  I am finding though, that on > some new OS installs the script fails with: > > Traceback (most recent call last): >  F

Re: Inconsistency with split() - Script, OS, or Package Problem?

2011-05-09 Thread Ian Kelly
On Mon, May 9, 2011 at 1:29 PM, James Wright wrote: > It does not appear to show a key: > > D4[] = vsr > Traceback (most recent call last): >  File "render4.py", line 115, in >    create_report_index(each_item) >  File "render4.py", line 26, in create_report_index >    [clean_name, _] = each_valu

Re: Custom string joining

2011-05-09 Thread Ian Kelly
On Mon, May 9, 2011 at 1:26 PM, Martineau wrote: > Instead of join() here's a function that does something similar to > what the string join() method does. The first argument can be a list > of any type of objects and the second separator argument can likewise > be any type. The result is list of

Re: checking if a list is empty

2011-05-11 Thread Ian Kelly
On Wed, May 11, 2011 at 8:34 AM, Hans Georg Schaathun wrote: > E.g. Anyone who has used list/set comprehension in Z, haskell, set theory, > or whereever will understand python list comprehension immediately. They would understand the underlying concept. But would somebody who is not a Python pr

Re: unicode by default

2011-05-11 Thread Ian Kelly
On Wed, May 11, 2011 at 3:37 PM, harrismh777 wrote: > hi folks, >   I am puzzled by unicode generally, and within the context of python > specifically. For one thing, what do we mean that unicode is used in python > 3.x by default. (I know what default means, I mean, what changed?) The `unicode'

Re: unicode by default

2011-05-12 Thread Ian Kelly
On Thu, May 12, 2011 at 1:58 AM, John Machin wrote: > On Thu, May 12, 2011 4:31 pm, harrismh777 wrote: > >> >> So, the UTF-16 UTF-32 is INTERNAL only, for Python > > NO. See one of my previous messages. UTF-16 and UTF-32, like UTF-8 are > encodings for the EXTERNAL representation of Unicode charac

Re: unicode by default

2011-05-12 Thread Ian Kelly
On Thu, May 12, 2011 at 2:42 PM, Terry Reedy wrote: > On 5/12/2011 12:17 PM, Ian Kelly wrote: >> Right.  *Under the hood* Python uses UCS-2 (which is not exactly the >> same thing as UTF-16, by the way) to represent Unicode strings. > > I know some people say that,

Re: Recursion or iteration (was Fibonacci series recursion error)

2011-05-13 Thread Ian Kelly
On Fri, May 13, 2011 at 5:11 AM, rusi wrote: > The tightest way I knew so far was this: > The 2x2 matrix > 0 1 > 1 1 > raised to the nth power gives the nth fibonacci number. [And then use > a logarithmic matrix mult] > Your version is probably tighter than this. Oh, nice! I did it this way once

Re: how to install easy_install

2011-05-13 Thread Ian Kelly
On Fri, May 13, 2011 at 11:40 AM, rusi wrote: > I tried to install easy_install (This is on windows) > I downloaded the executable and ran it. It claimed to have done its > job. > > But now when I type easy_install at a cmd prompt I get > easy_install is not a command... > > [I guess I am a perenn

Re: checking if a list is empty

2011-05-13 Thread Ian Kelly
On Fri, May 13, 2011 at 1:41 PM, harrismh777 wrote: > On the other hand, kids today are dumped into a first comp sci course in > programming and plopped in-front of a Hugs interactive shell and then are > expected to learn programming and be successful by trying to grasp pure > functional programm

Re: checking if a list is empty

2011-05-13 Thread Ian Kelly
On Fri, May 13, 2011 at 6:48 PM, harrismh777 wrote: > Ian Kelly wrote: >> >> Well, at least Haskell is probably better as an introductory language >> than Lisp or Scheme.  But what schools actually do this? > > http://www.cs.kent.ac.uk/teaching/resources/haskel

Re: checking if a list is empty

2011-05-13 Thread Ian Kelly
On Fri, May 13, 2011 at 10:47 PM, harrismh777 wrote: > http://www.inf.ed.ac.uk/teaching/courses/inf1/fp/ > > http://www.cs.ou.edu/~rlpage/fpclassSpring97/ > > > There are lots of these...   the two above afaik are still doing this at the > entry level...    ... supposedly, these kids are 'mostly'

Re: Recursion or iteration (was Fibonacci series recursion error)

2011-05-14 Thread Ian Kelly
On Sat, May 14, 2011 at 11:24 AM, rusi wrote: > def fib(n): >    if n==1 or n==2: >        return 1 >    elif even(n): >        return sq(fib (n//2)) + 2 * fib(n//2) * fib(n//2 - 1) >    else: >        return sq(fib (n//2 + 1)) + sq(fib(n // 2)) > > This is a strange algo  -- logarithmic because i

Re: I don't understand generator.send()

2011-05-14 Thread Ian Kelly
On Sat, May 14, 2011 at 6:08 PM, Victor Eijkhout wrote: > I thought the send call would push the value "2" at the front of the > queue. Instead it coughs up the 2, which seems senseless to me. > > 1/ How should I view the send call? I'm reading the manual and dont' get > it There is no queue unle

Re: I don't understand generator.send()

2011-05-14 Thread Ian Kelly
On Sat, May 14, 2011 at 6:47 PM, Chris Angelico wrote: > def ints(): >    i=0 >    queue=[] >    while True: >        if queue:  # see other thread, this IS legal and pythonic and > quite sensible >            sent=(yield queue.pop(0)) >        else: >            sent=(yield i) >            i+=1 >

Re: I don't understand generator.send()

2011-05-14 Thread Ian Kelly
On Sat, May 14, 2011 at 7:17 PM, Chris Angelico wrote: > You're right. It needs a while loop instead of the if (and some slight > reordering): > > def ints(): >   i=0 >   queue=[] >   while True: >       if queue:  # see other thread, this IS legal and pythonic and > quite sensible >           sen

Re: dict: retrieve the original key by key

2011-05-15 Thread Ian Kelly
On Sun, May 15, 2011 at 4:18 AM, Steven D'Aprano wrote: > On Sun, 15 May 2011 11:11:41 +0200, Christoph Groth wrote: > >> I would like to avoid having _multiple_ objects which are equal (a == b) >> but not the same (a is not b).  This would save a lot of memory. > > Based on the idea of interning,

Re: TypeError: __init__() takes exactly 1 positional argument (2 given)

2011-05-15 Thread Ian Kelly
On Sun, May 15, 2011 at 9:53 PM, Gnarlodious wrote: > class GnomonBase(object): >    def __init__(self, bench): >        # do stuff > > But all I get is: > TypeError: __init__() takes exactly 1 positional argument (2 given) > > I don't understand, I am only sending one variable. What does it think

Re: TypeError: __init__() takes exactly 1 positional argument (2 given)

2011-05-15 Thread Ian Kelly
On Sun, May 15, 2011 at 10:30 PM, Gnarlodious wrote: > I don't have a trace because I am using mod_wsgi under Apache. Maybe > there is a way to debug using mod_wsgi but I haven't been able to > figure out how. http://code.google.com/p/modwsgi/wiki/DebuggingTechniques > My problem is that in orde

Re: obviscating python code for distribution

2011-05-16 Thread Ian Kelly
On Mon, May 16, 2011 at 12:17 AM, Littlefield, Tyler wrote: >>Write your "game" for the "web". >>Write is as a SaaS (Software as a Service) - even if it's free and open >> source. > I understood you loud and clear. And that makes a lot of assumptions on my > game and the design. I don't really car

Re: Faster Recursive Fibonacci Numbers

2011-05-17 Thread Ian Kelly
On Tue, May 17, 2011 at 9:50 AM, RJB wrote: > I noticed some discussion of recursion. the trick is to find a > formula where the arguments are divided, not decremented. > I've had a "divide-and-conquer" recursion for the Fibonacci numbers > for a couple of years in C++ but just for fun rewrote

Re: in search of graceful co-routines

2011-05-17 Thread Ian Kelly
On Tue, May 17, 2011 at 11:04 AM, Chris Withers wrote: > Now, since the sequence is long, and comes from a file, I wanted the > provider to be an iterator, so it occurred to me I could try and use the new > 2-way generator communication to solve the "communicate back with the > provider", with som

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

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