Re: problems with shelve(), collections.defaultdict, self

2012-02-11 Thread Ian Kelly
On Fri, Feb 10, 2012 at 7:48 PM, 7stud <7s...@excite.com> wrote: > But I cannot get a class that inherits from collections.defaultdict to > shelve itself: > > > import collections as c > import shelve > > class Dog(c.defaultdict): >    def __init__(self): >        super().__init__(int, Joe=0) >    

Re: problems with shelve(), collections.defaultdict, self

2012-02-11 Thread Ian Kelly
On Sat, Feb 11, 2012 at 10:46 AM, Ian Kelly wrote: > The problem is that defaultdict defines a custom __reduce__ method > which is used by the pickle protocol to determine how the object > should be reconstructed.  It uses this to reconstruct the defaultdict > with the same default

Re: problems with shelve(), collections.defaultdict, self

2012-02-11 Thread Ian Kelly
On Sat, Feb 11, 2012 at 10:54 AM, Ian Kelly wrote: > class Dog(dict): > >    def __missing__(self): >        return 0 Sorry, that should have been: class Dog(dict): def __missing__(self, key): return 0 Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: OT: Entitlements [was Re: Python usage numbers]

2012-02-13 Thread Ian Kelly
I hate being suckered in by trolls, but this paragraph demands a response. On Mon, Feb 13, 2012 at 9:01 AM, Rick Johnson wrote: > You are born with rights. Life, Liberty, and the pursuit of happiness. > Healthcare care is NOT a right, healthcare is a privileged. If you deprive a person of access

Re: OT: Entitlements [was Re: Python usage numbers]

2012-02-13 Thread Ian Kelly
[Reply sent off-list, partly because this is way off-topic, but also because python-list rejected my response as spam] -- http://mail.python.org/mailman/listinfo/python-list

Re: name of a sorting algorithm

2012-02-14 Thread Ian Kelly
On Tue, Feb 14, 2012 at 9:55 AM, Den wrote: > On Feb 14, 8:22 am, Arnaud Delobelle wrote: >> On 14 February 2012 15:31, Dennis Lee Bieber wrote: >> >> > On Tue, 14 Feb 2012 16:01:05 +0100, Jabba Laci >> > wrote: >> >> >>Could someone please tell me what the following sorting algorithm is >> >>

Re: name of a sorting algorithm

2012-02-14 Thread Ian Kelly
On Tue, Feb 14, 2012 at 11:10 AM, Jabba Laci wrote: > Hi, > >> Either you're misremembering, or the algorithm you programmed 43 years >> ago was not actually bubble sort.  Quoting from Wikipedia: >> >> """ >> Bubble sort, also known as sinking sort, is a simple sorting algorithm >> that works by r

Re: Complexity question on Python 3 lists

2012-02-15 Thread Ian Kelly
On Wed, Feb 15, 2012 at 11:20 AM, Franck Ditter wrote: > What is the cost of calling primes(n) below ? I'm mainly interested in > knowing if the call to append is O(1), even amortized. Yes, it's amortized O(1). See: http://wiki.python.org/moin/TimeComplexity >From a relatively shallow analysis

Re: writing to a file from within nested loops

2012-02-15 Thread Ian Kelly
On Wed, Feb 15, 2012 at 1:12 PM, Rituparna Sengupta wrote: > Hi, > > I'm working on this code and I keep getting an error. It might be some very > basic thing but I was wondering if someone could help. Its a loop within a > loop. The part outside the innermost loop gets printed fine, but the par

Re: Complexity question on Python 3 lists

2012-02-15 Thread Ian Kelly
On Wed, Feb 15, 2012 at 1:28 PM, Dennis Lee Bieber wrote: > On Wed, 15 Feb 2012 11:11:27 -0800, Chris Rebert > wrote: > > >>"The growth pattern is: 0, 4, 8, 16, 25, 35, 46, 58, 72, 88, …" >>    -- list_resize() >> >        Rather perverse, is it not? The first set is plain doubling, but > then yo

Re: Wanted: Criticism of code for a Python module, plus a Mac tester

2012-02-15 Thread Ian Kelly
On Wed, Feb 15, 2012 at 4:33 PM, HoneyMonster wrote: > Secondly, as a more general point I would welcome comments on code > quality, adherence to standards and so forth. The code is at: Looks pretty nice overall. To reduce repetition, I would have constructed the CONDITIONS list by iteration lik

Re: format a measurement result and its error in "scientific" way

2012-02-15 Thread Ian Kelly
On Wed, Feb 15, 2012 at 5:18 PM, Daniel Fetchinson wrote: > Hi folks, often times in science one expresses a value (say > 1.03789291) and its error (say 0.00089) in a short way by parentheses > like so: 1.0379(9) > > One can vary things a bit, but let's take the simplest case when we > only keep 1

Re: Wanted: Criticism of code for a Python module, plus a Mac tester

2012-02-15 Thread Ian Kelly
On Wed, Feb 15, 2012 at 6:11 PM, HoneyMonster wrote: > As to your first suggestion though, I am having some difficulty. Note > that the vulnerability rotates; i.e. CONDITIONS[4] is not the same as > CONDITIONS[0]. > Is there a better way of doing it than a simple list.append()? Ah, it's more comp

Re: OT: Entitlements [was Re: Python usage numbers]

2012-02-16 Thread Ian Kelly
On Wed, Feb 15, 2012 at 8:04 AM, Rick Johnson wrote: > I have PROVEN that when people FIGHT back, they will NOT be subjects > to tyranny; race has NOTHING to do with it. I gave one example in > history where people would rather die than be subjected to tyranny, > there are many more. "GIVE ME FREE

Re: format a measurement result and its error in "scientific" way

2012-02-16 Thread Ian Kelly
On Thu, Feb 16, 2012 at 1:36 AM, Daniel Fetchinson wrote: >>> Hi folks, often times in science one expresses a value (say >>> 1.03789291) and its error (say 0.00089) in a short way by parentheses >>> like so: 1.0379(9) >>> >>> One can vary things a bit, but let's take the simplest case when we >>>

Re: format a measurement result and its error in "scientific" way

2012-02-16 Thread Ian Kelly
On Thu, Feb 16, 2012 at 3:21 PM, Daniel Fetchinson wrote: > Thanks, it's simpler indeed, but gives me an error for value=1.267, > error=0.08: > > Traceback (most recent call last): >  File "/home/fetchinson/bin/format_error", line 26, in >    print format_error( sys.argv[1], sys.argv[2] ) >  Fil

Re: Python code file prototype

2012-02-17 Thread Ian Kelly
On Fri, Feb 17, 2012 at 9:20 AM, John Gordon wrote: > Here's what PyScripter inserts in a new python file: > >  #- >  # Name:        module1 >  # Purpose: >  # >  # Author:      $USERNAME >  # >  # Created:     $DATE >  # Copyrigh

Re: OT: Entitlements [was Re: Python usage numbers]

2012-02-17 Thread Ian Kelly
On Fri, Feb 17, 2012 at 6:13 PM, Rick Johnson wrote: > > On Mon, Feb 13, 2012 at 7:23 PM, Ian Kelly > wrote: >> On Mon, Feb 13, 2012 at 2:01 PM, Rick Johnson >> I make a middle-class income and do not feel that I am anywhere near >> being "enslaved" by my in

Re: Python math is off by .000000000000045

2012-02-22 Thread Ian Kelly
On Wed, Feb 22, 2012 at 11:13 AM, Alec Taylor wrote: > Simple mathematical problem, + and - only: > 1800.00-1041.00-555.74+530.74-794.95 > -60.9500045 > > That's wrong. > > Proof > http://www.wolframalpha.com/input/?i=1800.00-1041.00-555.74%2B530.74-794.95 > -60.95 aka (-(1219/20)) >

Re: sum() requires number, not simply __add__

2012-02-23 Thread Ian Kelly
On Thu, Feb 23, 2012 at 2:38 PM, Buck Golemon wrote: > My proposal is still *slightly* superior in two ways: > > 1) It reduces the number of __add__ operations by one > 2) The second argument isn't strictly necessary, if you don't mind > that the 'null sum' will produce zero. It produces the wron

Re: sum() requires number, not simply __add__

2012-02-23 Thread Ian Kelly
On Thu, Feb 23, 2012 at 2:53 PM, Chris Angelico wrote: > On Fri, Feb 24, 2012 at 8:41 AM, Arnaud Delobelle wrote: >> _sentinel = object() >> >> def sum(iterable, start=_sentinel): >>    if start is _sentinel: >> >> del _sentinel > > Somewhat off-topic: Doesn't the if statement there do a lookup f

Re: PyWart: Language missing maximum constant of numeric types!

2012-02-24 Thread Ian Kelly
On Fri, Feb 24, 2012 at 10:32 AM, Devin Jeanpierre wrote: > On Fri, Feb 24, 2012 at 9:25 AM, Neil Cerutti wrote: >> The only time I've naively pined for such a thing is when >> misapplying C idioms for finding a minimum value. >> >> Python provides an excellent min implementation to use instead.

Re: pickle handling multiple objects ..

2012-02-27 Thread Ian Kelly
On Sun, Feb 26, 2012 at 6:00 AM, Chris Angelico wrote: > Additionally, you'll get a weird crash out of your program if load() > returns something other than a sequence of length 3. Remember, > everything that comes from outside your code is untrusted, even if you > think you made it just two secon

Re: Question about circular imports

2012-02-27 Thread Ian Kelly
On Sun, Feb 26, 2012 at 3:42 AM, Frank Millman wrote: > Hi all > > I seem to have a recurring battle with circular imports, and I am trying to > nail it once and for all. > > Let me say at the outset that I don't think I can get rid of circular > imports altogether. It is not uncommon for me to fi

Re: Question about circular imports

2012-02-27 Thread Ian Kelly
On Mon, Feb 27, 2012 at 6:01 PM, Terry Reedy wrote: > On 2/27/2012 1:16 AM, Frank Millman wrote: >>> >>> >>> To avoid the tedious reference, follow this with >>> read = sound.formats.wavread # choose the identifier you prefer > > > I tested something like this with stdlib, but there must be some i

Re: America's CONTEMPTUOUS KANGAROO courts VERSUS ISRAELI courts (in JEW-vs-JEW case)

2012-02-27 Thread Ian Kelly
On Mon, Feb 27, 2012 at 8:13 PM, Tonico wrote: > Idiot Please don't reply to spam. You're just making it show up in the inboxes of those of us who already have these idiots kill-filed. -- http://mail.python.org/mailman/listinfo/python-list

Re: Is this the proper way to use a class method?

2012-03-02 Thread Ian Kelly
On Fri, Mar 2, 2012 at 12:16 AM, John Salerno wrote: >> That's just a coincidence. Your supercall is ought to be: super().move() >> In contrast, super().move(self) calls the superclass instance method >> `move` with 2 arguments, both `self`, which just happens to work given >> your move() method,

Re: What's the best way to write this regular expression?

2012-03-06 Thread Ian Kelly
On Tue, Mar 6, 2012 at 4:05 PM, John Salerno wrote: >> Anything that allows me NOT to use REs is welcome news, so I look forward to >> learning about something new! :) > > I should ask though...are there alternatives already bundled with Python that > I could use? Now that you mention it, I reme

Re: Python recursive tree, linked list thingy

2012-03-07 Thread Ian Kelly
On Wed, Mar 7, 2012 at 12:49 PM, Wanderer wrote: > I have a list of defective CCD pixels and I need to find clusters > where a cluster is a group of adjacent defective pixels. This seems to > me to be a classic linked list tree search.I take a pixel from the > defective list and check if an adjace

Re: Python recursive tree, linked list thingy

2012-03-07 Thread Ian Kelly
On Wed, Mar 7, 2012 at 1:03 PM, Ian Kelly wrote: > A set of defective pixels would be the probable choice, since it > offers efficient membership testing. Some actual code, using a recursive generator: def get_cluster(defective, pixel): yield pixel (row, column) = pixel for ad

Re: What's the best way to write this regular expression?

2012-03-07 Thread Ian Kelly
On Wed, Mar 7, 2012 at 1:39 PM, John Salerno wrote: > Ok, first major roadblock. I have no idea how to install Beautiful > Soup or lxml on Windows! All I can find are .tar files. Based on what > I've read, I can use the easy_setup module to install these types of > files, but when I went to downlo

Re: What's the best way to write this regular expression?

2012-03-07 Thread Ian Kelly
On Wed, Mar 7, 2012 at 2:11 PM, John Salerno wrote: > The only files included in the .tar.gz file is a .tar file of the same > name. So I guess the setup option doesn't exist for these particular > packages. The setup.py file (as well as the other files) would be inside the .tar file. Unlike a W

Re: Invalid syntax error

2012-03-10 Thread Ian Kelly
On Sat, Mar 10, 2012 at 6:17 AM, Günther Dietrich wrote: > In article > <46758542-1bd6-43fe-8e80-bcf14b7d8...@pi6g2000pbc.googlegroups.com>, >  sl33k wrote: > >>I'm trying project euler problem 3 and I've hit the wall with this >>error. What could be the problem here? >> >> l=[] > num=6008514

Re: newb __init__ inheritance

2012-03-11 Thread Ian Kelly
On Sun, Mar 11, 2012 at 4:56 AM, hyperboogie wrote: > 1. What do you mean by "subclassing `object`"? In Python 2 there are two different types of classes: classic classes, which are retained for backward compatibility, and new-style classes, which were introduced in Python 2.2. Classic classes a

Re: newb __init__ inheritance

2012-03-11 Thread Ian Kelly
On Sun, Mar 11, 2012 at 5:40 AM, Ian Kelly wrote: >> 2. Is the mro function available only on python3? > > No, but it is available only on new-style classes.  If you try it on a > classic class, you'll get an AttributeError. And by the way, you probably shouldn't cal

Re: concatenate function

2012-03-13 Thread Ian Kelly
On Tue, Mar 13, 2012 at 8:35 AM, ferreirafm wrote: > Hi List, > I've coded three functions that I would like to concatenate. I mean, run > them one after another. The third function depends on the results of the > second function, which depends on the results of the first one. When I call > one fu

Re: Enchancement suggestion for argparse: intuit type from default

2012-03-14 Thread Ian Kelly
On Wed, Mar 14, 2012 at 7:30 AM, Roy Smith wrote: > It's already inferred that the type is a string if you don't give it any > value.  What possible meaning could: > > parser.add_argument('--foo', default=100) > > have?  If I run the program with: > > $ prog > > then foo defaults to the integer 10

Re: Questions about the use of descriptors.

2012-03-15 Thread Ian Kelly
On Thu, Mar 15, 2012 at 11:32 AM, Steven W. Orr wrote: > Question 1: > > I have a class A with one attribute and I define __get__ and __set__ for > that class. Then I create another class B that uses it. > > Why does B require that the instance of A be a class variable in B and not > created as an

Re: Context Manager getting str instead of AttributeError instance

2012-03-15 Thread Ian Kelly
On Thu, Mar 15, 2012 at 1:10 PM, Prasad, Ramit wrote: >> Prasad, Ramit wrote: >> >> > So I have a context manager used to catch errors >> > >> > def __exit__( self, exceptionClass, exception, tracebackObject ): >> >     if isinstance( exception, self.exceptionClasses ): >> >          #do something

Re: Context Manager getting str instead of AttributeError instance

2012-03-15 Thread Ian Kelly
On Thu, Mar 15, 2012 at 2:25 PM, Prasad, Ramit wrote: >> > ... >> > (, "'A' object has no attribute 'x'", >> ) >> > AttributeError: 'A' object has no attribute 'x' >> > >> > As you can see, I am

Re: Why not use juxtaposition to indicate function application

2012-03-16 Thread Ian Kelly
On Fri, Mar 16, 2012 at 10:45 AM, Steven D'Aprano wrote: > On Fri, 16 Mar 2012 17:31:06 +0100, Kiuhnm wrote: > >> You wouldn't, because Haskel's way is more regular and makes a lot of >> sense: parentheses are for grouping and that's it. > > If f is a function which normally takes (for the sake of

Re: avoid import short-circuiting

2012-03-16 Thread Ian Kelly
On Fri, Mar 16, 2012 at 4:04 PM, Andrea Crotti wrote: >> You want to monkeypatch __builtin__.__import__() instead. It always gets >> called. >> > > Seems like a good idea :) > > My first attempt failes though > > > def full(module): >    from __builtin__ import __import__ >    ls = [] >    orig =

Re: How to get a reference of the 'owner' class to which a method belongs in Python 3.X?

2012-03-18 Thread Ian Kelly
On Sun, Mar 18, 2012 at 3:42 AM, Cosmia Luna wrote: > But it seems that the last line(#ref2) in the Py2Type.__init__ does not work > at > all. I'm not sure what you're expecting it to do, but type.__init__ does not actually do anything > It seems really weird, 'type' is an instance of 'type' it

Re: Currying in Python

2012-03-19 Thread Ian Kelly
I hope you don't mind if I critique your code a bit! On Fri, Mar 16, 2012 at 7:21 PM, Kiuhnm wrote: > Here we go. > > ---> > def genCur(f, unique = True, minArgs = -1): It is customary in Python for unsupplied arguments with no default to use the value None, not -1. That's what it exists for.

Re: List comprehension/genexp inconsistency.

2012-03-20 Thread Ian Kelly
On Tue, Mar 20, 2012 at 3:16 PM, Dennis Lee Bieber wrote: > On Tue, 20 Mar 2012 16:23:22 -0400, "J. Cliff Dyer" > declaimed the following in > gmane.comp.python.general: > >> >> When trying to create a class with a dual-loop generator expression in a >> class definition, there is a strange scopin

Re: Odd strip behavior

2012-03-22 Thread Ian Kelly
On Thu, Mar 22, 2012 at 1:48 PM, Rodrick Brown wrote: > Why wasnt the t removed ? Because str.strip() only removes leading or trailing characters. If you want to remove all the t's, use str.replace: 'this is a test'.replace('t', '') Cheers, Ian -- http://mail.python.org/mailman/listinfo/pytho

Re: random number

2012-03-26 Thread Ian Kelly
On Mon, Mar 26, 2012 at 3:24 AM, Michael Poeltl wrote: import random, string def random_number(id): > ...     characters = list(string.ascii_lowercase + > ...                       string.ascii_uppercase + > ...                       string.digits) > ...     coll_rand = [] > ...     for

Re: "convert" string to bytes without changing data (encoding)

2012-03-28 Thread Ian Kelly
On Wed, Mar 28, 2012 at 11:43 AM, Peter Daum wrote: > ... I was under the illusion, that python (like e.g. perl) stored > strings internally in utf-8. In this case the "conversion" would simple > mean to re-label the data. Unfortunately, as I meanwhile found out, this > is not the case (nor the "a

Re: No os.copy()? Why not?

2012-04-02 Thread Ian Kelly
On Wed, Mar 28, 2012 at 2:12 PM, John Ladasky wrote: > I'm looking for a Python (2.7) equivalent to the Unix "cp" command. > Since the equivalents of "rm" and "mkdir" are in the os module, I > figured I look there.  I haven't found anything in the documentation. > I am also looking through the Pyt

Re: Number of languages known [was Re: Python is readable] - somewhat OT

2012-04-03 Thread Ian Kelly
On Tue, Apr 3, 2012 at 6:39 AM, Nathan Rice wrote: > Did you miss the part where I said that most people who learn to > program are fascinated by computers and highly motivated to do so? > I've never met a BROgrammer, those people go into sales.  It isn't > because there aren't smart BROmosapiens

Re: No os.copy()? Why not?

2012-04-03 Thread Ian Kelly
On Tue, Apr 3, 2012 at 12:24 AM, Thomas Rachel wrote: > Am 02.04.2012 23:11 schrieb HoneyMonster: > > >> One way: >> import os >> >> os.system ("cp src sink") > > > Yes. The worst way you could imagine. > > Why not the much much better > > from subprocess > subprocess.call(['cp', 'src', 'sink'])

Re: Run once while loop

2012-04-03 Thread Ian Kelly
On Tue, Apr 3, 2012 at 2:36 PM, Anatoli Hristov wrote: > Hi, > > I'm trying to do a while loop with condition of time if time is > 12:00:00 print text, but for this one second the text is printed at > least 50 times, how can I print only once? Set a flag when you print the text to indicate that y

Re: Run once while loop

2012-04-03 Thread Ian Kelly
On Tue, Apr 3, 2012 at 3:00 PM, Anatoli Hristov wrote: > On 03 Apr 2012, at 22:45, Ian Kelly wrote: > >> On Tue, Apr 3, 2012 at 2:36 PM, Anatoli Hristov wrote: >>> Hi, >>> >>> I'm trying to do a while loop with condition of time if time is >>

Re: igraph and usage of Read(klass, f, format=None, *args, **kwds) question

2012-04-04 Thread Ian Kelly
On Tue, Apr 3, 2012 at 9:45 PM, wrote: > I have a file with with adjacency list of an undirected graph one vertex list > per input line [0 1, 1 2 3, 2 1, 3 1] assume a newline for commas (file is > named adjl.txt). Can some one give an example of loading this into graph of 4 > vertices? > > im

Re: inheritance

2012-04-05 Thread Ian Kelly
On Thu, Apr 5, 2012 at 10:50 AM, yag wrote: > three classes A,B,C and instance x. > > now how can I call methods foo in class A and B using 'x' instance. (I hope I > could pronounce the terminology correct) Do you mean that you want C.foo to call B.foo, and B.foo to call A.foo? If that is the ca

Re: inheritance

2012-04-05 Thread Ian Kelly
On Thu, Apr 5, 2012 at 11:50 AM, Yagnesh Raghava Yakkala wrote: >>>you will have >>> to pass the instance in explicitly as the self argument.  For example: >> >>> B.foo(x)  # calls B.foo directly with instance x > > After follow up, I see one problem(can i say that?) with this. With python > overw

Re: Python Gotcha's?

2012-04-05 Thread Ian Kelly
On Thu, Apr 5, 2012 at 12:52 PM, Michael Hrivnak wrote: > I'm surprised nobody beat me to posting this: The OP beat you to it -- it's in the list at the wiki link. -- http://mail.python.org/mailman/listinfo/python-list

Re: Python Gotcha's?

2012-04-05 Thread Ian Kelly
On Thu, Apr 5, 2012 at 2:06 PM, Emile van Sebille wrote: > On 4/5/2012 11:10 AM Jon Clements said... > >> On Wednesday, 4 April 2012 23:34:20 UTC+1, Miki Tebeka  wrote: >>> >>> Greetings, >>> >>> I'm going to give a "Python Gotcha's" talk at work. >>> If you have an interesting/common "Gotcha" (wa

Re: 'string_escape' in python 3

2012-04-06 Thread Ian Kelly
On Fri, Apr 6, 2012 at 4:19 PM, Terry Reedy wrote: > I actually thought of that, but assumed that adding enclosing quotes would > be safe (or that the OP trusted the string). After sending, I realized that > if Nasty Hacker guessed that the string would be so augmented, then it would > not be safe

Re: 'string_escape' in python 3

2012-04-06 Thread Ian Kelly
On Fri, Apr 6, 2012 at 11:52 AM, Nicholas Cole wrote: > In Python 2 given the following raw string: > s = r"Hello\x3a this is a test" > > the escaping could be removed by use of the following: > s.decode('string_escape') > > In Python 3, however, the only way I can see to achieve the sam

Re: 'string_escape' in python 3

2012-04-07 Thread Ian Kelly
On Sat, Apr 7, 2012 at 8:30 AM, Nicholas Cole wrote: > On Sat, Apr 7, 2012 at 12:10 AM, Ian Kelly wrote: >>>>> import codecs >>>>> codecs.getdecoder('unicode_escape')(s)[0] >> 'Hello: this is a test' >> >> Cheers, >&g

Re: f python?

2012-04-08 Thread Ian Kelly
On Sun, Apr 8, 2012 at 11:32 AM, Peter J. Holzer wrote: > Poul-Henning Kamp nominated the C/Unix guys: > > http://queue.acm.org/detail.cfm?id=2010365 Besides what Kaz and Chris wrote, the suggestion that if they had chosen ptr+len format then we wouldn't have buffer overflows is erroneous. There

Re: red-black tree data structure

2012-04-11 Thread Ian Kelly
On Wed, Apr 11, 2012 at 11:14 AM, Jabba Laci wrote: > Hi, > > It's not really a Python-related question, sorry for that. Does anyone > know why red-black trees got these colors in their names? Why not > blue-orange for instance? I'm just curious. http://programmers.stackexchange.com/questions/116

Re: Deep merge two dicts?

2012-04-12 Thread Ian Kelly
On Thu, Apr 12, 2012 at 11:59 AM, John Nagle wrote: > On 4/12/2012 10:41 AM, Roy Smith wrote: >> >> Is there a simple way to deep merge two dicts?  I'm looking for Perl's >> Hash::Merge (http://search.cpan.org/~dmuey/Hash-Merge-0.12/Merge.pm) >> in Python. > > > def dmerge(a, b) : >   for k in a :

Re: Deep merge two dicts?

2012-04-13 Thread Ian Kelly
On Fri, Apr 13, 2012 at 5:11 AM, John O'Hagan wrote: > I think you also have to check if a[k] is a dict before making the recursive > call, else for example dmerge({'a': 1}, {'a': {'b': 1}}) fails with a > TypeError. In that case the third line above should read: > >    if k in a and isinstance(a[

Re: f python?

2012-04-15 Thread Ian Kelly
On Sat, Apr 14, 2012 at 8:57 PM, Shmuel Metz wrote: > In <87aa2iz3l1@kuiper.lan.informatimago.com>, on 04/11/2012 >   at 05:32 PM, "Pascal J. Bourguignon" said: > >>You're confused. C doesn't have arrays.  Lisp has arrays. C only has >>vectors > > Neither C nor any other programming langua

Re: f python?

2012-04-15 Thread Ian Kelly
On Sun, Apr 15, 2012 at 4:49 PM, Terry Reedy wrote: > On 4/15/2012 12:16 PM, Ian Kelly wrote: >> >> On Sat, Apr 14, 2012 at 8:57 PM, Shmuel  Metz >>  wrote: >>> >>> In<87aa2iz3l1@kuiper.lan.informatimago.com>, on 04/11/2012 >&

Re: pygame: output to file?

2012-04-16 Thread Ian Kelly
On Mon, Apr 16, 2012 at 12:39 PM, Temia Eszteri wrote: > If there's a image-handling library out there for Python that can make > animated GIFs, I might be able to come up with a faster and more > internalized solution using surface.convert() to paletted modes and > image.tostring() functions or s

Re: Python one-liner?

2012-04-16 Thread Ian Kelly
On Mon, Apr 16, 2012 at 3:18 PM, Karl Knechtel wrote: > d = {k: list(v) for k, v in itertools.groupby(sorted(l, key=f), f)} Note that the sorted call would fail if f returns objects of unorderable types: Python 3.2 (r32:88445, Feb 20 2011, 21:29:02) [MSC v.1500 32 bit (Intel)] on win32 Type "hel

Re: Working with Cursors

2012-04-17 Thread Ian Kelly
On Tue, Apr 17, 2012 at 12:11 PM, timlash wrote: > Searched the web and this forum without satisfaction.  Using Python 2.7 and > pyODBC on Windows XP I can get the code below to run and generate two cursors > from two different databases without problems.  Ideally, I'd then like to > join these

Re: how python dir works

2012-04-18 Thread Ian Kelly
On Wed, Apr 18, 2012 at 9:56 AM, cheung wrote: > how does the function  "dir" works, where can I get the python-c  source of > dir in py2.7 project. > > I looked the python_c source for hours, can't find how dir works. http://hg.python.org/cpython/file/67be12ab8948/Objects/object.c#l1957 > for

Re: can I overload operators like "=>", "->" or something like that?

2012-04-19 Thread Ian Kelly
On Thu, Apr 19, 2012 at 1:28 PM, dmitrey wrote: > hi all, > can I somehow overload operators like "=>", "->" or something like > that? (I'm searching for appropriate overload for logical implication > "if a then b") No, because those aren't operators in Python. You could overload ">=" (__ge__) o

Re: with statement

2012-04-19 Thread Ian Kelly
On Thu, Apr 19, 2012 at 3:33 PM, Terry Reedy wrote: > On 4/19/2012 1:15 PM, Kiuhnm wrote: >> >> A with statement is not at the module level only if it appears inside a >> function definition or a class definition. > > > This is true, I believe, of all statements. > >> Am I forgetting something? >

Re: Using arguments in a decorator

2012-04-20 Thread Ian Kelly
On Fri, Apr 20, 2012 at 9:57 AM, Rotwang wrote: > As far as I know, the decorated function will always return the same value > as the original function. The problem is that the dictionary key stored > depends on how the function was called, even if two calls should be > equivalent; hence the origi

Re: Using arguments in a decorator

2012-04-20 Thread Ian Kelly
On Fri, Apr 20, 2012 at 6:07 PM, Ian Kelly wrote: >    (args, varargs, varkw, defaults) = inspect.getargspec(func) >    if varargs: >        args.append(varargs) >    if varkw: >        args.append("tuple(sorted(%s.items()))" % varkw) Note that in Python 3, this would

Re: Newbie, homework help, please.

2012-04-21 Thread Ian Kelly
On Sat, Apr 21, 2012 at 11:28 AM, someone wrote: > for item in userinput: >    openfile=open(textfile,'w');openfile.writelines("%s\n" % item for item in > userinput);openfile.close() The for loop here means that the file will be written and rewritten four times. The end result is the same, but

Re: Appending to []

2012-04-22 Thread Ian Kelly
On Sun, Apr 22, 2012 at 2:29 AM, Bernd Nawothnig wrote: >> But what about 2), the mixed (impure) functional design? Unfortunately, >> it too has a failure mode: by returning a list, it encourages the error >> of assuming the list is a copy rather than the original: >> >> mylist = [1, 2, 3, 4] >> a

Re: why () is () and [] is [] work in other way?

2012-04-23 Thread Ian Kelly
On Mon, Apr 23, 2012 at 11:01 AM, Paul Rubin wrote: > Kiuhnm writes: >> I can't think of a single case where 'is' is ill-defined. > > If I can't predict the output of > >    print (20+30 is 30+20)  # check whether addition is commutative >    print (20*30 is 30*20)  # check whether multiplication

Re: class versions and object deserialization

2012-04-24 Thread Ian Kelly
On Tue, Apr 24, 2012 at 1:02 AM, J. Mwebaze wrote: > We have classes of this form classA version1, classA version2, classA > version3 .. etc. This is same class that has been modified. Each > "modification" creates a new version of a class. Each object has a version > attribute which refers to the

Re: why () is () and [] is [] work in other way?

2012-04-26 Thread Ian Kelly
On Thu, Apr 26, 2012 at 3:10 AM, Steven D'Aprano wrote: > But I was actually referring to something more fundamental than that. The > statement "a is b" is a *direct* statement of identity. "John is my > father." "id(a) == id(b)" is *indirect*: "The only child of John's > grandfather is the parent

Re: Half-baked idea: list comprehensions with "while"

2012-04-26 Thread Ian Kelly
On Thu, Apr 26, 2012 at 11:02 AM, Roy Smith wrote: > I'm not seriously suggesting this as a language addition, just an interesting > idea to simplify some code I'm writing now: > > x = [a for a in iterable while a] > > which equates to: > > x = [] > for a in iterable: >    if not a: >        brea

Re: why () is () and [] is [] work in other way?

2012-04-26 Thread Ian Kelly
On Thu, Apr 26, 2012 at 1:34 PM, Adam Skutt wrote: > What I think you want is what I said above: ValueError raised when > either operand is a /temporary/ object.  Really, it should probably be > a parse-time error, since you could (and should) make the > determination at parse time. I'm not sure

Re: Half-baked idea: list comprehensions with "while"

2012-04-26 Thread Ian Kelly
On Thu, Apr 26, 2012 at 11:57 AM, Kiuhnm wrote: > On 4/26/2012 19:48, Paul Rubin wrote: >> >> Roy Smith  writes: >>> >>> x = [a for a in iterable while a] >> >> >> from itertools import takewhile >> >> x = takewhile(bool, a) > > > I see that as a 'temporary' solution, otherwise we wouldn't need 'i

Re: why () is () and [] is [] work in other way?

2012-04-26 Thread Ian Kelly
On Thu, Apr 26, 2012 at 3:51 PM, Chris Angelico wrote: > On Fri, Apr 27, 2012 at 7:39 AM, Ian Kelly wrote: >> I'm not sure precisely what you mean by "temporary object", so I am >> taking it to mean an object that is referenced only by the VM stack >>

Re: why () is () and [] is [] work in other way?

2012-04-27 Thread Ian Kelly
On Fri, Apr 27, 2012 at 9:39 AM, Adam Skutt wrote: > On Apr 27, 8:07 am, Kiuhnm wrote: >> Useful... maybe, conceptually sound... no. >> Conceptually, NaN is the class of all elements which are not numbers, >> therefore NaN = NaN. > > NaN isn't really the class of all elements which aren't numbers

Re: syntax for code blocks

2012-04-27 Thread Ian Kelly
On Fri, Apr 27, 2012 at 10:07 AM, Steven D'Aprano wrote: > How about you give an actual working example of what you mean by a code > block and how you use it? He wrote a full blog post about it last week: http://mtomassoli.wordpress.com/2012/04/20/code-blocks-in-python/ -- http://mail.python.or

Re: Borg identity [was Re: why () is () and [] is [] work in other way?]

2012-04-27 Thread Ian Kelly
On Fri, Apr 27, 2012 at 11:33 AM, Adam Skutt wrote: > On Apr 27, 12:56 pm, Steven D'Aprano +comp.lang.pyt...@pearwood.info> wrote: >> On Thu, 26 Apr 2012 04:42:36 -0700, Adam Skutt wrote: >> > You're going to have to explain the value of an "ID" that's not 1:1 with >> > an object's identity, for

Re: Borg identity [was Re: why () is () and [] is [] work in other way?]

2012-04-27 Thread Ian Kelly
On Fri, Apr 27, 2012 at 11:38 AM, Chris Angelico wrote: > On Sat, Apr 28, 2012 at 3:33 AM, Adam Skutt wrote: >> I think you misunderstood me.  Define a Borg class where somehow >> identity is the same for all instances.  Inherit from that class and >> add per-instance members.  Now, identity can'

Re: hex to bin 16 bit word

2012-04-27 Thread Ian Kelly
On Fri, Apr 27, 2012 at 12:56 PM, Paul Rubin wrote: > python writes: >> What to decode hex '0xC0A8'  and return signed short int. > > Is this right? > >    n = int('0xC0A8', 16) >    if n >= 0x: >       n -= 0x1 No. n = int('0xC0A8', 16) if n >= 0x8000: n -= 0x1 -- http://mail.

Re: Sort comparison

2012-05-01 Thread Ian Kelly
On Mon, Apr 30, 2012 at 11:25 PM, Dan Stromberg wrote: > > A while back I did a sort algorithm runtime comparison for a variety of > sorting algorithms, and then mostly sat on it. > > Recently, I got into a discussion with someone on stackoverflow about the > running time of radix sort. > > I real

Re: Sort comparison

2012-05-01 Thread Ian Kelly
On Tue, May 1, 2012 at 12:00 PM, Dan Stromberg wrote: > > On Tue, May 1, 2012 at 12:21 AM, Ian Kelly wrote: >> >> On Mon, Apr 30, 2012 at 11:25 PM, Dan Stromberg >> wrote: >> > >> > A while back I did a sort algorithm runtime comparison for a variety o

Re: pyjamas / pyjs

2012-05-03 Thread Ian Kelly
On Thu, May 3, 2012 at 5:52 AM, alex23 wrote: > Anyone else following the apparent hijack of the pyjs project from its > lead developer? I've been following it but quietly since I don't use pyjs. It surprises me that nobody is talking much about it outside of the thread on pyjamas-dev. Seems to

Re: syntax for code blocks

2012-05-03 Thread Ian Kelly
On Thu, May 3, 2012 at 10:17 AM, Kiuhnm wrote: > On 5/3/2012 2:20, alex23 wrote: >> >> On May 2, 8:52 pm, Kiuhnm  wrote:      func(some_args, locals()) >>> >>> >>> I think that's very bad. It wouldn't be safe either. What about name >>> clashing >> >> >> locals() is a dict. It's not inje

Re: Lack of whitespace between contain operator ("in") and other expression tokens doesn't result in SyntaxError: bug or feature?

2012-05-03 Thread Ian Kelly
On Thu, May 3, 2012 at 12:49 PM, Garrett Cooper wrote: >    I was wondering whether this was a parser bug or feature (seems > like a bug, in particular because it implicitly encourages bad syntax, > but I could be wrong). The grammar notes (for 2.7 at least [1]) don't > seem to explicitly require

Re: "

2012-05-03 Thread Ian Kelly
On Thu, May 3, 2012 at 1:59 PM, John Nagle wrote: >  An HTML page for a major site (http://www.chase.com) has > some incorrect HTML.  It contains > >         > which is not valid HTML, XML, or SMGL.  However, most browsers > ignore it.  BeautifulSoup treats it as the start of a CDATA section, > an

Re: "

2012-05-04 Thread Ian Kelly
On Fri, May 4, 2012 at 12:57 AM, Stefan Behnel wrote: > Ian Kelly, 04.05.2012 01:02: >> BeautifulSoup is supposed to parse like a browser would > > Not at all, that would be html5lib. Well, I guess that depends on whether we're talking about BeautifulSoup 3 (a regex-based

Re: indexed property? Can it be done?

2012-05-07 Thread Ian Kelly
On Mon, May 7, 2012 at 9:15 PM, Charles Hixson wrote: > class Node: > >    def    __init__(self, nodeId, key, value, downRight, downLeft, parent): >        dirty    =    True >        dlu    =    utcnow() >        self.node    =    [nodeId, downLeft, [key], [value], [downRight], > parent, dirty, d

Re: sorting 1172026 entries

2012-05-07 Thread Ian Kelly
On Mon, May 7, 2012 at 3:52 PM, Cameron Simpson wrote: > | (or add 50% or something) each > | time, meaning that as n increases, the frequency of reallocations > | decreases - hence the O(1) amortized time. > > Hmm, yes. But it is only O(1) for doubling. If one went with a smaller > increment (to

Re: indexed property? Can it be done?

2012-05-08 Thread Ian Kelly
On Tue, May 8, 2012 at 10:30 AM, Charles Hixson wrote: > That depends on what you're doing.  For many, perhaps most, purposes I would > agree.  Not for this one.  And I couldn't use an internal dict, as the order > in which the items of the sub-lists occur is significant.  The sub-lists > need to

Re: pickle question: sequencing of operations

2012-05-08 Thread Ian Kelly
On Tue, May 8, 2012 at 1:19 PM, Russell E. Owen wrote: > In article , >  "Russell E. Owen" wrote: > >> What is the sequence of calls when unpickling a class with __setstate__? I believe it just calls object.__new__ followed by yourclass.__setstate__. So at the point __setstate__ is called, you

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