Re: Standard Deviation One-liner

2011-06-03 Thread Raymond Hettinger
On Jun 3, 10:55 am, Billy Mays wrote: > I'm trying to shorten a one-liner I have for calculating the standard > deviation of a list of numbers.  I have something so far, but I was > wondering if it could be made any shorter (without imports). > > Here's my function: > > a=lambda d:(sum((x-1.*sum(d

Bloom Filter in 22 lines of Python (updated)

2011-06-03 Thread Raymond Hettinger
Thanks for all the feedback on the earlier post. I've updated the recipe to use a cleaner API, simpler code, more easily subclassable, and with optional optimizations for better cache utilization and speed: http://code.activestate.com/recipes/577684-bloom-filter/ Raymond -

Re: Bloom Filter in 22 lines of Python (updated)

2011-06-08 Thread Raymond Hettinger
On Jun 6, 10:47 am, geremy condra wrote: > On Fri, Jun 3, 2011 at 1:17 PM, Raymond Hettinger wrote: > > Thanks for all the feedback on the earlier post. > > > I've updated the recipe to use a cleaner API, simpler code, > > more easily subclassable, and with optional

Re: Is there any advantage or disadvantage to using sets over list comps to ensure a list of unique entries?

2011-06-25 Thread Raymond Hettinger
On Jun 20, 9:43 pm, deathweaselx86 wrote: > Howdy guys, I am new. > > I've been converting lists to sets, then back to lists again to get > unique lists. > e.g > > Python 2.5.2 (r252:60911, Jan 20 2010, 21:48:48) > [GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)] on linux2 > Type "help", "copyright", "credits"

Re: Dictionaries and incrementing keys

2011-06-25 Thread Raymond Hettinger
On Jun 14, 12:57 pm, Steve Crook wrote: > Today I spotted an alternative: > > dict[key] = dict.get(key, 0) + 1 > > Whilst certainly more compact, I'd be interested in views on how > pythonesque this method is. It is very pythonesque in the it was the traditional one way to do it (also one of the

Re: blist question

2011-07-07 Thread Raymond Hettinger
On Jul 7, 5:08 am, dmitrey wrote: > hi all, > I feel lack of native Python lists operations (e.g. taking N greatest > elements with the involved key function and O(n) speed) Take a look at heapq.nlargest()... > and > occasionally found blisthttp://pypi.python.org/pypi/blist/ > Its entry says it

Re: a little parsing challenge ☺

2011-07-17 Thread Raymond Hettinger
On Jul 17, 12:47 am, Xah Lee wrote: > i hope you'll participate. Just post solution here. Thanks. http://pastebin.com/7hU20NNL Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: a little parsing challenge ☺

2011-07-17 Thread Raymond Hettinger
On Jul 17, 7:15 am, Thomas 'PointedEars' Lahn wrote: > Did you notice the excessive crosspost?  Please do not feed the troll. IMO, this was a legitimate cross post since it is for a multi-language programming challenge and everyone can learn from comparing the results. Raymond -- http://mail.p

Re: a little parsing challenge ☺

2011-07-17 Thread Raymond Hettinger
On Jul 17, 8:49 am, Thomas Boell wrote: > But why do you enumerate with start=1? Shouldn't you start with index 0? The problem specification says that the the char number should match the emacs goto-char function which is indexed from one, not from zero. This is testable by taking the output of

Re: list(), tuple() should not place at "Built-in functions" in documentation

2011-07-19 Thread Raymond Hettinger
On Jul 14, 6:21 pm, Inside wrote: > As telling in the subject,because "list" and "tuple" aren't functions,they > are types.Is that right? list() and tuple() are in the right place in the documentation because they would be harder to find if listed elsewhere. Tools like str(), int(), list(), tu

Re: Guido rethinking removal of cmp from sort method

2011-03-26 Thread Raymond Hettinger
On Mar 26, 4:39 am, Mark Dickinson wrote: > On Mar 25, 2:00 pm, Stefan Behnel wrote: > > > > > > > > > > > Westley Martínez, 25.03.2011 14:39: > > > > On Fri, 2011-03-25 at 07:11 +0100, Stefan Behnel wrote: > > >> Steven D'Aprano, 25.03.2011 06:46: > > >>> On Thu, 24 Mar 2011 18:32:11 -0700, Carl

Re: Understanding the Pystone measurement

2011-03-26 Thread Raymond Hettinger
On Mar 24, 9:21 pm, "tleeuwenb...@gmail.com" wrote: > Hi there, > > Is there a good writeup of what the pystone measurement actually > means? I'm working on benchmarking of some Python code at work, and > I'm interested in how Pystone might be relevant to me. I've tried > googling, but I can't fin

Re: Understanding the Pystone measurement

2011-03-26 Thread Raymond Hettinger
I forgot to mention that PyStone is just a Python translation from C of the venerable Dhrystone benchmark. See http://en.wikipedia.org/wiki/Dhrystone for a short write-up on the history, purposes, and limitations of the benchmark. Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: FW: ciao

2011-03-26 Thread Raymond Hettinger
On Mar 26, 11:34 am, MRAB wrote: > On 26/03/2011 18:07, bledar seferi wrote: > > >     3.Scrivere unafunsioncheprende comeargomentouna lista > >     diinterierestituisce uninsieme contenentequei numerichesono2 o più > >     voltenellalista fornita.Per esempio,seservecomelista di > >     input=[1,2

Re: Guido rethinking removal of cmp from sort method

2011-03-28 Thread Raymond Hettinger
On Mar 28, 8:43 am, Steven D'Aprano wrote: > Thank you for spending the time to get some hard data, but I can't > replicate your results since you haven't shown your code. Rather than > attempt to guess what you did and duplicate it, I instead came up with my > own timing measurements. Results are

Fun python 3.2 one-liner

2011-03-29 Thread Raymond Hettinger
from collections import Counter from itertools import product print('\n'.join('*'*(c//2000) for _,c in sorted(Counter(map(sum, product(range(6), repeat=8))).items( almost-normally-yours, Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Fun python 3.2 one-liner

2011-03-29 Thread Raymond Hettinger
>>> print('\n'.join('*'*(c//2000) for _,c in sorted(Counter(map(sum, >>> product(range(6), repeat=8))).items( * *** * ** * * **

Re: delete namespaces

2011-03-29 Thread Raymond Hettinger
On Mar 29, 6:14 pm, monkeys paw wrote: > How do i delete a module namespace once it has been imported? . . . > Then i make a modification to banner.py. When i import it again, > the new changes are not reflected. Is there a global variable i can > modify? In Python2.x, you can use the reload() f

Dictionary Descriptors

2011-03-30 Thread Raymond Hettinger
On the python-ideas list, someone made a wild proposal to add descriptors to dictionaries. None of the respondents seemed to realize that you could (not should, just could) already implement this using hooks already present in the language. I'm posting an example here because I thought you all mi

Re: Fun python 3.2 one-liner

2011-03-30 Thread Raymond Hettinger
On Mar 30, 2:19 am, Martin De Kauwe wrote: > what is the character limit on a one liner :P. Very interesting > jesting apart, any more? Sure, here are three one-liners using itertools.groupby() to emulate some Unix pipelines: sort letters | uniq # list unique values sort letters | uniq

Re: learn python the hard way exercise 42 help

2011-03-30 Thread Raymond Hettinger
On Mar 30, 6:48 am, neil harper wrote: > http://pastie.org/1735028 > hey guys play is confusing me, i get how next gets the first room, which > is passed when the instance of Game() is created, but how does it get > the next room? It might help show calling patterns if you added print statements

Re: popular programs made in python?

2011-03-30 Thread Raymond Hettinger
On Mar 29, 7:32 am, Neil Alt wrote: > i mean made with python only, not just a small part of python. BitTorrent was a huge success. Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: delete namespaces

2011-03-30 Thread Raymond Hettinger
[monkeys paw] > > How do i delete a module namespace once it has been imported? . . . > > Then i make a modification to banner.py. When i import it again, > > the new changes are not reflected. [Terry Reedy] > The best thing, if possible, is to restart the program. > If you develop banner.py with

Re: Directly Executable Files in Python

2011-03-30 Thread Raymond Hettinger
On Mar 28, 8:37 pm, Jordan Meyer wrote: > Is it possible to make a directly executable (such as .exe on Windows) file > from scripts written in Python? So as to prevent the end-user from having to > download an interpreter to run the program. http://docs.python.org/faq/programming.html#how-can-

Re: Why aren't copy and deepcopy in __builtins__?

2011-03-30 Thread Raymond Hettinger
On Mar 27, 8:29 pm, John Ladasky wrote: > Simple question.  I use these functions much more frequently than many > others which are included in __builtins__.  I don't know if my > programming needs are atypical, but my experience has led me to wonder > why I have to import these functions. I aske

Re: best python games?

2011-03-30 Thread Raymond Hettinger
On Mar 25, 7:39 pm, sogeking99 wrote: > hey guys, what are some of the best games made in python? free games > really. like pygames stuff. i want to see what python is capable of. > > cant see any good one on pygames site really, though they have nothing > like sort by rating or most downloaded as

Re: Alias for an attribute defined in a superclass

2011-03-31 Thread Raymond Hettinger
On Mar 31, 3:14 pm, Ben Finney wrote: > Howdy all, > > I want to inherit from a class, and define aliases for many of its > attributes. How can I refer to “the attribute that will be available by > name ‘spam’ once this class is defined”? > >     class Foo(object): >         def spam(self): >    

Re: a better way to invert a list?

2011-04-05 Thread Raymond Hettinger
[Ian Kelly] > Which is O(n).  If that is too verbose, you could also use a dictionary: > > def invert(p): >     return dict(map(reversed, enumerate(p))) def inv(p): return dict(zip(p, itertools.count())) Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Fun python 3.2 one-liner

2011-04-05 Thread Raymond Hettinger
On Apr 5, 6:38 am, Daniel Fetchinson wrote: > >> what is the character limit on a one liner :P. > > > For PEP 8 compliance, 80 characters. :-) > > Yeah, but we don't live in the 80's or 90's anymore and our screens > can support xterms (or let alone IDE widows) much wider than 80 > characters. I'm

Re: Why is __root checked for in OrderedDict?

2011-04-07 Thread Raymond Hettinger
On Apr 7, 4:13 am, andrew cooke wrote: > If you look at the code > inhttp://hg.python.org/cpython/file/6adbf5f3dafb/Lib/collections/__init...the > attribute __root is checked for, and only created if missing.  Why? > > I ask because, from what I understand, the __init__ method will only be > ca

Re: Why is __root checked for in OrderedDict?

2011-04-07 Thread Raymond Hettinger
On Apr 7, 2:40 pm, andrew cooke wrote: > Is that normal?  I mean, OK, it's possible (and yes I forgot it could be > called directly), but is there any usual reason to do so? It's common for subclasses to call their parent's __init__ method, so that should emulate dict as nearly as possible to he

Re: Tips on Speeding up Python Execution

2011-04-08 Thread Raymond Hettinger
On Apr 8, 12:25 am, Chris Angelico wrote: > On Fri, Apr 8, 2011 at 5:04 PM, Abhijeet Mahagaonkar > > wrote: > > I was able to isolate that major chunk of run time is eaten up in opening a > > webpages, reading from them and extracting text. > > I wanted to know if there is a way to concurrently c

Re: Generators and propagation of exceptions

2011-04-08 Thread Raymond Hettinger
On Apr 8, 8: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(stream-of-ch

Re: Generators and propagation of exceptions

2011-04-08 Thread Raymond Hettinger
On Apr 8, 8: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(stream-of-ch

Re: Generators and propagation of exceptions

2011-04-08 Thread Raymond Hettinger
On Apr 8, 12:47 pm, r wrote: > Anyway, thank you all for helping me out and bringing some ideas to > the table. I was hoping there might be some pattern specifically > designed for thiskind of job (exception generators anyone?), which > I've overlooked. If not anything else, knowing that this isn'

Re: Creating unit tests on the fly

2011-04-08 Thread Raymond Hettinger
On Apr 8, 12:10 pm, Roy Smith wrote: > I can even create new test cases from these on the fly with something > like: > >  newClass = type("newClass", (BaseSmokeTest,), {'route': '/my/newly/ > discovered/anchor'}) > > (credit > tohttp://jjinux.blogspot.com/2005/03/python-create-new-class-on-fly.ht

Re: python on iPad (PyPad)

2011-04-09 Thread Raymond Hettinger
On Apr 8, 10:13 pm, Jon Dowdall wrote: > Hi All, > > Sorry for the blatant advertising but hope some of you may be interested > to know that I've created an iPad application containing the python > interpreter and a simple execution environment. It's available in iTunes > athttp://itunes.apple.com

Re: dict.setdefault()

2011-04-11 Thread Raymond Hettinger
On Apr 11, 2:35 pm, rantingrick wrote: > setdefault should take **kw args in the case of needing to set > multiple defaults at one time. I would even settle for an *arg list if > i had to. Anything is better than... > > d.setdefault(blah, blah) > d.setdefault(blah, blah) > d.setdefault(blah, blah)

Re: dict.setdefault()

2011-04-11 Thread Raymond Hettinger
On Apr 11, 4:25 pm, Tim Chase wrote: > Finally, if it were added, I'd call it something like merge() Guido rejected merge() a long time ago. Anyway, there is a new ChainMap() tool in the collections module for Py3.3 that should address a number of use cases for handling default values. Raymond

Re: Questions about GIL and web services from a n00b

2011-04-15 Thread Raymond Hettinger
> > Is the limiting factor CPU? > > > If it isn't (i.e. you're blocking on IO to/from a web service) then the > > GIL won't get in your way. > > > If it is, then run as many parallel *processes* as you have cores/CPUs > > (assuming you're designing an application that can have multiple > > instance

Re: Equivalent code to the bool() built-in function

2011-04-18 Thread Raymond Hettinger
On Apr 16, 1:24 pm, candide wrote: > Consider the following code : > > # -- > def bool_equivalent(x): >      return True if x else False It's faster to write: def bool_equivalent(x): return not not x Raymond -- http://mail.python.org/mailman/listinfo/py

Re: suggestions, comments on an "is_subdict" test

2011-04-23 Thread Raymond Hettinger
On Apr 22, 8:18 am, MRAB wrote: > On 22/04/2011 15:57, Irmen de Jong wrote: > > > > > > > > > On 22-4-2011 15:55, Vlastimil Brom wrote: > >> Hi all, > >> I'd like to ask for comments or advice on a simple code for testing a > >> "subdict", i.e. check whether all items of a given dictionary are > >

Simple map/reduce utility function for data analysis

2011-04-25 Thread Raymond Hettinger
Here's a handy utility function for you guys to play with: http://code.activestate.com/recipes/577676/ Raymond twitter: @raymondh -- http://mail.python.org/mailman/listinfo/python-list

Re: Simple map/reduce utility function for data analysis

2011-04-26 Thread Raymond Hettinger
On Apr 25, 7:42 pm, Paul Rubin wrote: > Raymond Hettinger writes: > > Here's a handy utility function for you guys to play with: > >    http://code.activestate.com/recipes/577676/ > > Cute, but why not use collections.defaultdict for the return dict? > Untested: My

Re: Case study: debugging failed assertRaises bug

2011-04-26 Thread Raymond Hettinger
On Apr 25, 11:05 pm, Steven D'Aprano wrote: > I've just spent two hours banging my head against what I *thought* > (wrongly!) was a spooky action-at-a-distance bug in unittest, so I > thought I'd share it with anyone reading. Thanks for telling your story. I'm sure the lessons learned will be hel

Re: De-tupleizing a list

2011-04-26 Thread Raymond Hettinger
On Apr 25, 8:28 pm, Gnarlodious wrote: > I have an SQLite query that returns a list of tuples: > > [('0A',), ('1B',), ('2C',), ('3D',),... > > What is the most Pythonic way to loop through the list returning a > list like this?: > > ['0A', '1B', '2C', '3D',... You could unpack the 1-tuple the sam

Have you read the Python docs lately?

2011-04-27 Thread Raymond Hettinger
A number of developers have been working on adding examples and useful advice to the docs. To sharpen your skills, here are some pieces of recommended reading: http://docs.python.org/dev/library/heapq.html#priority-queue-implementation-notes http://docs.python.org/dev/library/bisect.html#searchi

Re: Have you read the Python docs lately?

2011-04-28 Thread Raymond Hettinger
On Apr 27, 11:28 pm, Paul Rubin wrote: > Raymond Hettinger writes: > > A number of developers have been working on adding examples and useful > > advice to the docs.  To sharpen your skills, here are some pieces of > > recommended reading: > > Thanks, those are n

Coolest Python recipe of all time

2011-05-02 Thread Raymond Hettinger
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 all time is: http://code.activestate.com/recipes/365013-linear-equations-solver-in-3-lines/ What are your favorites? Raymond twit

Re: Coolest Python recipe of all time

2011-05-03 Thread Raymond Hettinger
On May 2, 11:29 pm, Gregory Ewing wrote: > Terry Reedy wrote: > > The trick is that replacing x with j and evaluating > > therefore causes (in Python) all the coefficients of x (now j) to be > > added together separately from all the constant terms to reduce the > > linear equation to a*x+b (= 0 i

Re: Coolest Python recipe of all time

2011-05-03 Thread Raymond Hettinger
On May 2, 10: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 documentation doesn'

Re: Coolest Python recipe of all time

2011-05-03 Thread Raymond Hettinger
On May 2, 11:23 pm, Stefan Behnel wrote: > Terry Reedy, 03.05.2011 08:00: > > > On 5/3/2011 1:04 AM, 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

Today's fun and educational Python recipe

2011-05-04 Thread Raymond Hettinger
Here's a 22-line beauty for a classic and amazing algorithm: http://bit.ly/bloom_filter The wiki article on the algorithm is brief and well-written: http://en.wikipedia.org/wiki/Bloom_filter It turns out that people in the 1970's were pretty smart :-) Raymond --- follow my other python tip

Re: Today's fun and educational Python recipe

2011-05-04 Thread Raymond Hettinger
> > It turns out that people in the 1970's were pretty smart :-) > > I think that often, the cleverness of people is inversely proportional > to the amount of CPU power and RAM that they have in their computer. The Google guys have plenty of CPU power *and* plenty of cleverness :-) According to t

Re: Today's fun and educational Python recipe

2011-05-04 Thread Raymond Hettinger
On May 4, 12:42 pm, Terry Reedy wrote: > On 5/4/2011 2:17 PM, Raymond Hettinger wrote: > > > Here's a 22-line beauty for a classic and amazing algorithm: > >http://bit.ly/bloom_filter > > > The wiki article on the algorithm is brief and well-written: > >htt

Re: Today's fun and educational Python recipe

2011-05-04 Thread Raymond Hettinger
On May 4, 12:27 pm, Paul Rubin wrote: > Raymond Hettinger writes: > > Here's a 22-line beauty for a classic and amazing algorithm: > >http://bit.ly/bloom_filter > > The use of pickle to serialize the keys is a little bit suspicious if > there might be a reason to d

Re: Today's fun and educational Python recipe

2011-05-04 Thread Raymond Hettinger
On May 4, 5:26 pm, Terry Reedy wrote: > The test would be more convincing to many with 10 other geographic > names (hard to come by, I know), or other english names or words or even > with longer random strings that matched the lengths of the state names. > But an average of 5/10 false pos

Re: Coolest Python recipe of all time

2011-05-06 Thread Raymond Hettinger
[Steven D'Aprano]: > 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. With a small change in API, much of the magic isn't needed. from itertools import product def amb(func, *argument_ranges): for args in product(*argument_

Re: checking if a list is empty

2011-05-06 Thread Raymond Hettinger
On May 5, 11:36 pm, Jabba Laci wrote: > Hi, > > If I want to check if a list is empty, which is the more pythonic way? > > li = [] > > (1) if len(li) == 0: > ... > or > (2) if not li: The Python core developers use the second form. See http://www.python.org/dev/peps/pep-0008/ for the official rec

Re: Coolest Python recipe of all time

2011-05-07 Thread Raymond Hettinger
On May 7, 1:29 am, Steven D'Aprano wrote: > On Fri, 06 May 2011 12:36:09 -0600, Ian Kelly wrote: > > The amb engine would conceptually execute this function for every > > possible combination of a, b, and c, > > Which pretty much is the definition of "brute-force solver", no? FWIW, here's one of

Re: Coolest Python recipe of all time

2011-05-09 Thread Raymond Hettinger
On May 9, 2:31 am, Trent Nelson wrote: > > What are your favorites? > > I think I've posted this before, but I love my > 3-lines-if-you-ignore-the-scaffolding language translator.  Not because it's > clever code -- quite the opposite, the code is dead simple -- but because it > encompasses one

Re: string formatting

2011-05-10 Thread Raymond Hettinger
> Which is the preferred way of string formatting? > > (1) "the %s is %s" % ('sky', 'blue') > > (2) "the {0} is {1}".format('sky', 'blue') > > (3) "the {} is {}".format('sky', 'blue') > > As I know (1) is old style. (2) and (3) are new but (3) is only > supported from Python 2.7+. > > Which one sho

Re: Python 3 dict question

2011-05-10 Thread Raymond Hettinger
On May 6, 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 I used mere > key, val = myDict.items()[0] > but in Python 3 myDict.item

Re: Faster Recursive Fibonacci Numbers

2011-05-24 Thread Raymond Hettinger
On May 17, 8: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 it > in Pyth

Re: super() in class defs?

2011-05-25 Thread Raymond Hettinger
r Python toolkit. If any of the comp.lang.python readers want to review and comment on my latest draft, please email me and I'll send it to you directly. Cheers, Raymond Hettinger my email address is listed at http://users.rcn.com/python/download/Descriptor.htm -- http://mail.pytho

Re: Parse config file and command-line arguments, to get a single collection of options

2011-05-25 Thread Raymond Hettinger
On May 25, 9:38 pm, Ben Finney wrote: > Howdy all, > > Python's standard library has modules for configuration file parsing > (configparser) and command-line argument parsing (optparse, argparse). I > want to write a program that does both, but also: > > * Has a cascade of options: default option

Python's super() considered super!

2011-05-26 Thread Raymond Hettinger
uper-considered-super/ It would also be great if some of you would upvote it on HackerNews. Raymond Hettinger --- follow my python tips on twitter: @raymondh -- http://mail.python.org/mailman/listinfo/python-list

Re: Python's super() considered super!

2011-05-26 Thread Raymond Hettinger
> 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 Raymod -- http://mail.python.org/mailman/listinfo/python-list

Re: Python's super() considered super!

2011-05-27 Thread Raymond Hettinger
On May 26, 6:39 pm, Ben Finney wrote: > We also, though, need *real* URLs. Blind URLs through obfuscation > services have their uses, but surely not in a forum like this. The real > URL is http://news.ycombinator.com/item?id=2588262>. Fair enough. I had copied the link from Jesse's tweet (where

Class decorators might also be super too

2011-05-28 Thread Raymond Hettinger
David Beazley wrote a class decorator blog post that is worth reading: http://dabeaz.blogspot.com/2011/05/class-decorators-might-also-be-super.html Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Class decorators might also be super too

2011-05-29 Thread Raymond Hettinger
On May 28, 11:33 pm, Michele Simionato wrote: > He is basically showing that using mixins for implementing logging is not > such a good idea, i.e. you can get the same effect in a better way by making > use of other Python features. I argued the same thing many times in the past. > I even wrote

Re: float("nan") in set or as key

2011-05-29 Thread Raymond Hettinger
On May 28, 4:41 pm, MRAB wrote: > Here's a curiosity. float("nan") can occur multiple times in a set or as > a key in a dict: Which is by design. NaNs intentionally have multiple possible instances (some implementations even include distinct payload values). Sets and dicts intentionally recogni

Re: 3.1.4 release candidate 1

2011-05-29 Thread Raymond Hettinger
On May 29, 3:44 pm, Benjamin Peterson wrote: > On behalf of the Python development team, I'm happy as a swallow to announce a > release candidate for the fourth bugfix release for the Python 3.1 > series, Python > 3.1.4. The Pi release of Python :-) Raymond P.S. For the most part, if you have

Updated blog post on how to use super()

2011-05-31 Thread Raymond Hettinger
goal is to serve as a reliable guide to using super and how to design cooperative classes in a way that lets subclasses compose and extent them. Raymond Hettinger follow my python tips on twitter: @raymondh -- http://mail.python.org/mailman/listinfo/python-list

Re: Moronicity Xha Lee, Jargonizer

2005-09-29 Thread Raymond Hettinger
James Stroud wrote: > There needs to be an email filter that, when a thread is begun by a specific > user . . . it cans every > message in that thread. The tried-and-true solution is both simple and civil, "Don't feed the trolls." Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Idle bytecode query on apparently unreachable returns

2005-10-11 Thread Raymond Hettinger
[Tom Anderson]: > What puzzles me, though, are bytecodes 17, 39 and 42 - surely these aren't > reachable? Does the compiler just throw in a default 'return None' > epilogue, with routes there from every code path, even when it's not > needed? If so, why? Since unreachable code is never executed, t

Re: random number generator thread safety

2005-11-08 Thread Raymond Hettinger
Mike Brown wrote: > I have questions about thread safety in the 'random' module. > > When using the random.Random class (be it Mersenne Twister or Wichmann-Hill > based), is it sufficiently thread-safe (preserving entropy and guarding > against attack) to just have each thread work with its own ran

Re: random number generator thread safety

2005-11-08 Thread Raymond Hettinger
> > Thread-safety has nothing to do with preserving entropy or guarding > > against attack. All of the entropy in an MT sequence is contained in > > the seed (upto 624 bytes) and that entropy is preserved through all > > subsequent calls. > > I think the concern is that there can be a thread switc

Re: which feature of python do you like most?

2005-11-08 Thread Raymond Hettinger
> which feature of python do you like most? Indentation -- http://mail.python.org/mailman/listinfo/python-list

Re: exception raised by nested iterator being ignored by for loop

2005-11-19 Thread Raymond Hettinger
the whole wrapper as a generator: import gzip def wrapper(filename) : if filename[-3:] == ".gz" : fh = gzip.GzipFile(filename, "r") else : fh = open(filename, "r") for line in fh: if line[:1] != "t": # filter out lines s

Re: Underscores in Python numbers

2005-11-19 Thread Raymond Hettinger
Gustav Hållberg wrote: > I tried finding a discussion around adding the possibility to have > optional underscores inside numbers in Python. This is a popular option > available in several "competing" scripting langauges, that I would love > to see in Python. > > Examples: > 1_234_567 > 0xdead_

Re: hash()

2005-12-05 Thread Raymond Hettinger
[John Marshall] > For strings of > 1 character, what are the chances > that hash(st) and hash(st[::-1]) would return the > same value? Python's string hash algorithm is non-commutative, so a collision with a reversed string is not likely. The exact answer depends on the population of strings bein

Re: PEP 288 ponderings

2005-01-02 Thread Raymond Hettinger
e real issue with PEP 288's idea for generator attributes is that the current C implementation doesn't readily accommodate this change. Major surgery would be required :-( The more important part of the PEP is the idea for generator exceptions. The need arises in the context of flushin

Re: why does UserDict.DictMixin use keys instead of __iter__?

2005-01-04 Thread Raymond Hettinger
__(). Still, if __iter__() is provided, UserDict.DictMixin will take advantage of it. The same is also true for __contains__(), and iteritems(). Raymond Hettinger -- http://mail.python.org/mailman/listinfo/python-list

Re: generator expressions: performance anomaly?

2005-01-16 Thread Raymond Hettinger
tor. It would make me examine how 'a' is being used and check whether the surrounding code can use the iterator or an new object. > Comments, clues, ... please. As a point of interest, note that Py2.4 improved some of its built-in iterators to report their length if req

Re: generator expressions: performance anomaly?

2005-01-16 Thread Raymond Hettinger
[Raymond Hettinger] > >List slice assignment is an example of a tool with a special case optimization > >for inputs that know their own length -- that enables the tool to pre-allocate > >its result rather than growing and resizing in spurts. Other such tools include > &g

Re: generator expressions: performance anomaly?

2005-01-17 Thread Raymond Hettinger
docstring for Lib/test/test_iterlen.py . Raymond Hettinger -- http://mail.python.org/mailman/listinfo/python-list

Re: generator expressions: performance anomaly?

2005-01-19 Thread Raymond Hettinger
[Steve Holden] > Since it doesn't yet optimize 2+5 to a constant-folded 7 you should > realize that you are suggesting a large increase in the compiler's > analytical powers. FWIW, limited constant folding is already in CVS for Py2.5. Raymond Hettinger -- http://mail

Re: is this sort method the same as the one in python 2.4

2005-01-29 Thread Raymond Hettinger
thing but is implemented a bit differently. A custom key wrapper is applied to each object so that only the key value gets compared (no need for a full tuple with a tie breaker value). Raymond Hettinger -- http://mail.python.org/mailman/listinfo/python-list

Re: is this sort method the same as the one in python 2.4

2005-01-30 Thread Raymond Hettinger
l and note that stability is not preserved: >>> data = [('a', 1), ('a', 2), ('b', 3)] >>> data.sort(key=lambda record: record[0]) >>> data.reverse() >>> data [('b', 3), ('a', 2), ('a', 1)] Here's another way of accomplishing the original sort and preserving stability: >>> data = [('a', 1), ('a', 2), ('b', 3)] >>> sorted(data, cmp = lambda x,y: cmp(y[0], x[0])) [('b', 3), ('a', 1), ('a', 2)] Raymond Hettinger -- http://mail.python.org/mailman/listinfo/python-list

Re: is this sort method the same as the one in python 2.4

2005-01-30 Thread Raymond Hettinger
d in lib/test/test_builtins.py The key= and reverse= parameters were introduced to list.sort() in Py2.4. Consequently, the above code won't provide the desired functionality in Py2.3 and prior. Raymond Hettinger -- http://mail.python.org/mailman/listinfo/python-list

Re: set, dict and other structures

2005-01-31 Thread Raymond Hettinger
(there is probably a much greater demand for combinatorics, numeric/numarray, or financial modules). If the appeal is not broad, it has little chance of making it into the standard library. Raymond Hettinger -- http://mail.python.org/mailman/listinfo/python-list

Re: returning True, False or None

2005-02-04 Thread Raymond Hettinger
True in lst: > return True > elif False in lst: > return False > else: > return None > > This has a light code smell for me though -- can anyone see a simpler > way of writing this? return max(lst) Raymond Hettinger -- http://mail.python.org/mailman/listinfo/python-list

Re: returning True, False or None

2005-02-04 Thread Raymond Hettinger
return True in s or s == set([None]) and None Raymond Hettinger -- http://mail.python.org/mailman/listinfo/python-list

Re: Why is there no instancemethod builtin?

2005-06-20 Thread Raymond Hettinger
[George Sakkis] > The fact that strings don't have __iter__ is an implementation > detail. I can't think of any reason other than historic and perhaps > backwards compatibility for this; > iterables should IMHO by definition be exactly > the objects with __iter__). There would be no benefit other

Re: a dictionary from a list

2005-06-27 Thread Raymond Hettinger
[Roy Smith] > I also think the published description is needlessly confusing. Why does > it use > >{'one': 2, 'two': 3} > > as the example mapping when > >{'one': 1, 'two': 2} > > would illustrate exactly the same point but be easier to comprehend. The > mapping given is the kind of thing

Re: a dictionary from a list

2005-06-27 Thread Raymond Hettinger
[Roy Smith] > I also think the published description is needlessly confusing. Why does > it use > >{'one': 2, 'two': 3} > > as the example mapping when > >{'one': 1, 'two': 2} > > would illustrate exactly the same point but be easier to comprehend. The > mapping given is the kind of thing

Re: Lisp development with macros faster than Python development?..

2005-07-06 Thread Raymond Hettinger
[EMAIL PROTECTED] wrote: > I've been reading the beloved Paul Graham's "Hackers and Painters". > He claims he developed a web app at light speed using Lisp and lots > of macros. > > It got me curious if Lisp > is inherently faster to develop complex apps in. With Lisp or Forth, a master programme

Re: Lisp development with macros faster than Python development?..

2005-07-06 Thread Raymond Hettinger
[EMAIL PROTECTED] wrote: > The problem is that questions like 'What lang is fastest to develop > in?' > are hard to answer definitively. FWIW, Google's answer to that question is C++, Java, and Python. For any given problem, any of the three are acceptable. Each programmer or engineering team ge

Re: f*cking re module

2005-07-06 Thread Raymond Hettinger
> There's really not a single good re tutorial or documentation >I could found! With * being a greedy operator, your post's subject line matches, "firetrucking" which, of course, has nothing to do with regular expressions, or python.org's re how-to guide, or Amazon's 18 books on the subject, or th

  1   2   3   4   5   6   7   8   >