Re: subexpressions (OT: math)

2007-06-02 Thread Steve Howell
--- Steven D'Aprano <[EMAIL PROTECTED]> wrote: > On Sat, 02 Jun 2007 05:54:51 -0700, Steve Howell > wrote: > > >> > >>def f(x): y = x*x; return sin(y)+cos(y); > >> > > > > Although I know valid trigonometry is not the >

Re: subexpressions

2007-06-02 Thread Steve Howell
--- Stef Mientki <[EMAIL PROTECTED]> wrote: > Maybe he meant >sin(x)^2 + cos(x)^2 > which is well known demodulation technique if you > create two signals 90 degrees out of phase. > There's a shorter way to phrase that expression, of course. :) 1

Re: subexpressions (fourier example)

2007-06-02 Thread Steve Howell
--- Steve Howell <[EMAIL PROTECTED]> wrote: > > --- Stef Mientki <[EMAIL PROTECTED]> > wrote: > > Maybe he meant > >sin(x)^2 + cos(x)^2 > > which is well known demodulation technique if you > > create two signals 90 degrees out of phase. >

Re: file reading by record separator (not line by line)

2007-06-02 Thread Steve Howell
--- George Sakkis <[EMAIL PROTECTED]> wrote: > > It seems > > like it would be fairly straightforward to do a > quick > > prototype implementation of this. I'm off to work > > soon, so I can't do it today, but maybe Sunday. > > I'm afraid I beat you to it :) > http://aspn.activestate.com/ASPN/

Re: file reading by record separator (not line by line)

2007-06-02 Thread Steve Howell
--- Steve Howell <[EMAIL PROTECTED]> wrote: > > Can I suggest a minor optimization? > > Instead of this... > > def get_predicate(arg): > return arg if callable(arg) else ( >arg.__eq__ if hasattr(arg,'__eq__') > els

Re: Python rocks

2007-06-02 Thread Steve Howell
--- Mark Carter <[EMAIL PROTECTED]> wrote: > Well, I know I'm preaching to the converted - but > Python rocks. > [...] A few questions from the choir: As a recent newcomer to the language, did you encounter any traps or pitfalls while you were learning? Also, could you single out anything in p

iterblocks cookbook example

2007-06-02 Thread Steve Howell
George Sakkis produced the following cookbook recipe, which addresses a common problem that comes up on this mailing list: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/521877 I would propose adding something like this to the cookbook example above. def iterblocks2(lst, start_delim):

Re: iterblocks cookbook example

2007-06-03 Thread Steve Howell
--- Raymond Hettinger <[EMAIL PROTECTED]> wrote: > ISTM, this is a common mailing list problem because > it is fun > to solve, not because people actually need it on a > day-to-day basis. > It comes up in the real world for me once very couple months or so. It's usually when I need to manipulate

Re: *Naming Conventions*

2007-06-03 Thread Steve Howell
--- Thorsten Kampe <[EMAIL PROTECTED]> wrote: > > for validanswer in validanswers: > if myAnswers.myanswer in > myAnswers.validAnswers[validanswer]: > MyOptions['style'] = validanswer > I can at least sympathize with your problem, although I don't have a great solution for you. I o

Re: subexpressions (OT: math)

2007-06-03 Thread Steve Howell
What's the square root of -1 radians? :) Park yourself in front of a world of choices in alternative vehicles. Visit the Yahoo! Auto Green Center. http://autos.yahoo.com/green_center/ -- http://mail.p

Re: another thread on Python threading

2007-06-03 Thread Steve Howell
--- "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > One random idea is to for Python 3000, make the > equivalent of > __slots__ the default, *but* instead gather > the set of attributes from all member variables set > in __init__. Are you suggesting to do this at startup time or runtime? The

Re: *Naming Conventions*

2007-06-03 Thread Steve Howell
--- Dan Bishop <[EMAIL PROTECTED]> wrote: > > * Loop indices often have single-letter names > (typically i/j/k or x/ > y), or names that are the singular form of the list > name (e.g., "for > ballot in self._ballots"). For iterating over > files, I use "line". > You are in good company with "i"

Python, Dutch, English, Chinese, Japanese, etc.

2007-06-03 Thread Steve Howell
The never-ending debate about PEP 3131 got me thinking about natural languages with respect to Python, and I have a bunch of mostly simple observations (some factual, some anecdotal). I present these mostly as food for thought, but I do make my own continent-by-continent recommendations at the bot

Re: subexpressions (OT: math)

2007-06-03 Thread Steve Howell
--- Alex Martelli <[EMAIL PROTECTED]> wrote: > > I blame the > Babylonians for that > confusion just as much as for the clunky base-60 > that intrudes in our > ordinary time reckoning...! > I apologize for helping to start this whole ridiculous thread, although I hope some people have been ente

Re: Python, Dutch, English, Chinese, Japanese, etc.

2007-06-03 Thread Steve Howell
--- Ross Ridge <[EMAIL PROTECTED]> wrote: > >Asia: > > > > Python should be *completely* internationalized > for > >Mandarin, Japanese, and possibly Hindi and Korean. > >Not just identifiers. I'm talking the entire > >language, keywords and all. > > > btw. Mandarin is a spoken dialect Chines

Re: Python, Dutch, English, Chinese, Japanese, etc.

2007-06-04 Thread Steve Howell
--- [EMAIL PROTECTED] wrote: > what about slavic languages? > in croatian you have five accented letters plus > three letters for > digrahps. russian, bulgarian, serbian, macedonian, > ukranian etc. use > cyrilic alphabet (lets not forget that russia isn't > that small - > around 150 million peopl

Re: subexpressions (OT: math)

2007-06-04 Thread Steve Howell
--- Peter Otten <[EMAIL PROTECTED]> wrote: > > I know not much more about Fourier series than that > they do exist, so let me > refer you to > > http://en.wikipedia.org/wiki/Fourier_series > I'd like to try to bring this thread back full circle (or maybe at least 7*pi/4). 1) OP posted an ex

Re: subexpressions (OT: math)

2007-06-04 Thread Steve Howell
--- Wildemar Wildenburger <[EMAIL PROTECTED]> wrote: > > > Oh my, remember when we used to discuss murderous > snakes and silly > British comedians on this group? > I hardly do ... > /W Although all of us are mere amateurs in this business of making parameters when it's circles in question I

Re: Python, Dutch, English, Chinese, Japanese, etc.

2007-06-04 Thread Steve Howell
--- [EMAIL PROTECTED] wrote: > > Méta-MCI je napisao/la: > > Et le klingon ? > > > > Please, don't forget klingons > > SVP, n'oubliez pas les klingons > > > > ;o) > > je pense que le klingon utilise les mems lettres > comme l'anglais > Oui, mais en tous case, dans l'Enterprise on doit utilise

Re: Python, Dutch, English, Chinese, Japanese, etc.

2007-06-04 Thread Steve Howell
--- olive <[EMAIL PROTECTED]> wrote: > What is a "sharp hair boss" ? > "Sharp hair boss" came out from my translation into French of "pointy-haired boss." Wikipedia tells me I should have said "Boss a tête de pioche." Here are some links, if you've never had the pleasure of reading Dilbert:

Re: Python, Dutch, English, Chinese, Japanese, etc.

2007-06-04 Thread Steve Howell
--- Josiah Carlson <[EMAIL PROTECTED]> wrote: > Steve Howell wrote: > > I don't predict a huge upswing in Slavic-writing > > Python programmers after PEP 3131, even among > > children. > I slightly misspoke here. I meant to say children and young adults, i

Re: Python, Dutch, English, Chinese, Japanese, etc.

2007-06-04 Thread Steve Howell
--- MRAB <[EMAIL PROTECTED]> wrote: > Instead of having many different Pythons for many > different languages, > how about one for a language like Esperanto? > > http://en.wikipedia.org/wiki/Esperanto > > That could be the language for the standard > libraries instead of > English. > English b

Re: Refactoring test units after an extract method

2007-06-05 Thread Steve Howell
--- Virgil Dupras <[EMAIL PROTECTED]> wrote: > How to you handle the tests? Copy over the tests you > had for foo() and > apply them to bar()? I don't like copy and pasting > code. Move the B > related tests to baz()'s tests? Then your tests > wouldn't fail if you > stopped calling baz() in foo()

Re: Who uses Python?

2007-06-05 Thread Steve Howell
--- walterbyrd <[EMAIL PROTECTED]> wrote: > I am getting the idea that most python "programmers" > use python more > like a tool, rather than as their primary > specialization. In other > words, python is usually not the primary > specialization. I'm one of the exceptions to this rule. My prima

Re: lists - append - unique and sorted

2007-06-06 Thread Steve Howell
--- Neil Cerutti <[EMAIL PROTECTED]> wrote: > i agree that using bisect and inserting manually > clearly meets > the stated requirements, while there isn't enough > information to > know if a heapq will meet his requirements. > > Thanks for the correction. > If the OP is still reading, don't di

Re: Bragging about Python

2007-06-07 Thread Steve Howell
--- "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Is there a resource somewhere on the net that can be > used to quickly > and effectively show Python's strengths to > non-Python programmers? > Small examples that will make them go "Wow, that > _is_ neat"? > 15 small programs here: http://w

Re: Bragging about Python

2007-06-07 Thread Steve Howell
--- Szabolcs Nagy <[EMAIL PROTECTED]> wrote: > > actually i don't like when a tutorial uses over > complicated cute names > if the context is obvious (fibonacci) then we don't > need to add > 'parent_rabbits' and such identifiers I still prefer the use of "rabbits," but I don't mind if people ch

Re: Bragging about Python

2007-06-07 Thread Steve Howell
Programs like this were posted on this thread: >def fib(): >generation, parent_rabbits, baby_rabbits = 1, > 1, 1 >while True: >yield generation, baby_rabbits >generation += 1 >parent_rabbits, baby_rabbits = \ > baby_rabbits,

Re: Bragging about Python

2007-06-07 Thread Steve Howell
--- Georg Brandl <[EMAIL PROTECTED]> wrote: > >> > >> 15 small programs here: > >> > >> http://wiki.python.org/moin/SimplePrograms > >> > > > > IMHO a few python goodies are missing there. > > "It's a Wiki." ;) > Yes indeed. Please feel free to add to the page, or make your own fork. See l

Re: Bragging about Python

2007-06-08 Thread Steve Howell
--- Szabolcs Nagy <[EMAIL PROTECTED]> wrote: > > the title of a program shouldn't be part of the code > (or it should at > least start with #) > sorry i'm too lazy now to fix it, but imho it needs > nicer layout to be > used as 'bragging about python' site > Agreed. I just spruced up the layout

Re: Bragging about Python (8 queens)

2007-06-08 Thread Steve Howell
--- Paul McGuire <[EMAIL PROTECTED]> wrote: > > > > So I'm throwing down the gauntlet--can somebody > write > > a short program (maybe 10 to 20 lines) where you > solve > > a problem more simply than a similar > > non-generator-using solution would solve it? > Maybe > > something like Eight Queen

Re: Python in the Mozilla world

2007-06-10 Thread Steve Howell
--- "Eric S. Johansson" <[EMAIL PROTECTED]> wrote: > > As a result, I started looking at Python generating > JavaScript and I know there > is pypy but is that really something one can count > on or is it more a good > demonstration of technology? > I would not completely give up on the idea o

Re: Python in the Mozilla world

2007-06-10 Thread Steve Howell
--- "Eric S. Johansson" <[EMAIL PROTECTED]> wrote: http://www.voidspace.org.uk/python/weblog/arch_d7_2007_04_28.shtml#e702 > > interesting. Very interesting but I suspect the > message is "don't hold your > breath but don't give up hope." > Exactly. :) > [...] What I need to do would take m

Re: Python optimization (was Python's "only one way to do it" philosophy isn't good?)

2007-06-10 Thread Steve Howell
--- John Nagle <[EMAIL PROTECTED]> wrote: > > With this, the heavy optimizations are possible. > Strength reduction. Hoisting > common subexpressious out of loops. Hoisting > reference count updates out of > loops. Keeping frequently used variables in > registers. And elimination of > many u

Re: Python in the Mozilla world

2007-06-10 Thread Steve Howell
--- "Eric S. Johansson" <[EMAIL PROTECTED]> wrote: > Steve Howell wrote: > > --- "Eric S. Johansson" <[EMAIL PROTECTED]> wrote: > > > http://www.voidspace.org.uk/python/weblog/arch_d7_2007_04_28.shtml#e702 > >> interesting. Very int

Re: Python in the Mozilla world

2007-06-10 Thread Steve Howell
--- "Eric S. Johansson" <[EMAIL PROTECTED]> wrote: > > this is good to know except I am somewhat cautious > about the end result given > that it's from Microsoft (explained below) > Believe me, I agree! I work mostly in the Unix world now, but I've done enough serious development in the Windo

Re: Python optimization (was Python's "only one way to do it" philosophy isn't good?)

2007-06-10 Thread Steve Howell
--- Kay Schluehr <[EMAIL PROTECTED]> wrote: > On Jun 11, 12:43 am, Steve Howell > <[EMAIL PROTECTED]> wrote: > > > To the extent that some of these optimizations > could > > be achieved by writing better Python code, it > would > > nice for optimizat

Re: Python optimization (was Python's "only one way to do it" philosophy isn't good?)

2007-06-11 Thread Steve Howell
--- John Nagle <[EMAIL PROTECTED]> wrote: > > When you have to start buying more servers for > the server farm, > it's a real pain. I'm actually facing that because > Python's HTML > parsing is so slow. > I have been following this thread for a bit, but apologies in advance if I didn't rea

SimplePrograms challenge

2007-06-11 Thread Steve Howell
Hi, I'm offering a challenge to extend the following page by one good example: http://wiki.python.org/moin/SimplePrograms Right now the page starts off with 15 examples that cover lots of ground in Python, but they're still scratching the surface. (There are also two Eight Queens implementations

Re: Properties for modules?

2007-06-11 Thread Steve Howell
--- Ed Leafe <[EMAIL PROTECTED]> wrote: > I have a simple module that reads in values from > disk when imported, > and stores them in attributes, allowing for code > like: > > >>> import moduleFoo > >>> print moduleFoo.someSetting > 'the value' > > What I'd like to do is have a

Re: SimplePrograms challenge

2007-06-11 Thread Steve Howell
--- infidel <[EMAIL PROTECTED]> wrote: > # reading CSV files, tuple-unpacking > import csv > > #pacific.csv contains: > #1,CA,California > #2,AK,Alaska > #3,OR,Oregon > #4,WA,Washington > #5,HI,Hawaii > > reader = csv.reader(open('pacific.csv')) > for id, abbr, name in reader: > print '%s i

Re: SimplePrograms challenge

2007-06-11 Thread Steve Howell
--- John Machin <[EMAIL PROTECTED]> wrote: > On Jun 12, 9:16 am, Steve Howell > <[EMAIL PROTECTED]> wrote: > > > > > One more suggestion--maybe it could exercise a > little > > more of the CVS module, i.e. have something in the > > data that would

Re: SimplePrograms challenge

2007-06-12 Thread Steve Howell
--- Rob Wolfe <[EMAIL PROTECTED]> wrote: > Steven Bethard <[EMAIL PROTECTED]> writes: > > > I'd hate to steer a potential new Python developer > > to a clumsier [...] > > [...] > But as far as HTML (not XML) is concerned this is > not very realistic solution. > I think both posted examples wou

Re: SimplePrograms challenge

2007-06-12 Thread Steve Howell
--- George Sakkis <[EMAIL PROTECTED]> wrote: > > from itertools import count, ifilter > def sieve(): > seq = count(2) > while True: > p = seq.next() > seq = ifilter(p.__rmod__, seq) > yield p > > > I suspect that it violates your second rule though > :) > I'm g

Re: Python's "only one way to do it" philosophy isn't good?

2007-06-12 Thread Steve Howell
--- "Anders J. Munch" <[EMAIL PROTECTED]> wrote: > > Converting tail-recursion to iteration is trivial, > and perfectly reasonable for > a human to do by hand. You add an outer "while > True"-loop, the recursive call > becomes a tuple assignment, and other code paths end > with a break out of

Re: SimplePrograms challenge

2007-06-12 Thread Steve Howell
--- Rob Wolfe <[EMAIL PROTECTED]> wrote: > > What about simple HTML parsing? As a matter of fact > this is not > language concept, but shows the power of Python > standard library. > Besides, that's very popular problem among newbies. I totally agree with the relevance of this example. FWIW it

Re: SimplePrograms challenge

2007-06-12 Thread Steve Howell
--- Steven Bethard <[EMAIL PROTECTED]> wrote: > Steve Howell wrote: > > --- George Sakkis <[EMAIL PROTECTED]> wrote: > >> from itertools import count, ifilter > >> def sieve(): > >> seq = count(2) > >> while True: > >>

Re: SimplePrograms challenge

2007-06-12 Thread Steve Howell
--- Steven Bethard <[EMAIL PROTECTED]> wrote: > Steve Howell wrote: > > --- George Sakkis <[EMAIL PROTECTED]> wrote: > >> from itertools import count, ifilter > >> def sieve(): > >> seq = count(2) > >> while True: > >>

Re: SimplePrograms challenge

2007-06-12 Thread Steve Howell
--- I wrote: > [...] was the final straw in converting > me from Python to Perl. Er, Perl to Python. In looking backwards, I started writing backwards. And no, I'm not ever going back to Perl... Boa

Re: SimplePrograms challenge

2007-06-12 Thread Steve Howell
--- Steven Bethard <[EMAIL PROTECTED]> wrote: > On 6/12/07, Steve Howell <[EMAIL PROTECTED]> > wrote: > > --- Steven Bethard <[EMAIL PROTECTED]> > wrote: > > > import itertools > > > > > > def iter_primes(): > > > # an ite

Re: Python's "only one way to do it" philosophy isn't good?

2007-06-12 Thread Steve Howell
--- Steven D'Aprano <[EMAIL PROTECTED]> wrote: > On Tue, 12 Jun 2007 15:51:07 -0700, Steve Howell > wrote: > > > > > --- "Anders J. Munch" <[EMAIL PROTECTED]> wrote: > >> > >> Converting tail-recursion to iteration is > t

Re: SimplePrograms challenge

2007-06-12 Thread Steve Howell
--- Steven Bethard <[EMAIL PROTECTED]> wrote: > # print the first 100 primes > for prime in itertools.islice(iter_primes(), > 100): > print prime > Sure. FWIW, in the example I posted, I kept the output loop a little more pedestrian (using an if/break idiom), and I printed pr

Re: Multiline lamba implementation in python.

2007-06-12 Thread Steve Howell
--- Josh Gilbert <[EMAIL PROTECTED]> wrote: > > I know that the standard Python response is that you > might as well define a > function, indeed, the name might provide useful > documentation. In reality, > however, the vast majority of my anonymous functions > are callbacks (tends to > lead to na

Re: Python's "only one way to do it" philosophy isn't good?

2007-06-12 Thread Steve Howell
--- John Nagle <[EMAIL PROTECTED]> wrote: > > There's a real reason. Remember, functions are > dynamically > replaceable. The compiler would have to detect that > the function > doesn't modify or replace itself while recursing for > this optimization > to be valid. Worst case, another thre

Re: SimplePrograms challenge

2007-06-13 Thread Steve Howell
--- Steven Bethard <[EMAIL PROTECTED]> wrote: > Stefan Behnel wrote: > > Steven Bethard wrote: > >> If you want to parse invalid HTML, I strongly > encourage you to look into > >> BeautifulSoup. Here's the updated code: > >> > >> import ElementSoup # > http://effbot.org/zone/element-soup.htm

Re: SimplePrograms challenge

2007-06-13 Thread Steve Howell
--- Steven Bethard <[EMAIL PROTECTED]> wrote: > Rob Wolfe wrote: > > Steve Howell wrote: > > > >> I suggested earlier that maybe we post multiple > >> solutions. That makes me a little nervous, to > the > >> extent that it shows that th

Re: SimplePrograms challenge

2007-06-14 Thread Steve Howell
--- Steven Bethard <[EMAIL PROTECTED]> wrote: unit.text) > > I posted a slight variant of this, trimmed down a > bit to 21 lines. > Thanks, I think this will be a very useful example. Pinpoint custome

Re: SimplePrograms challenge

2007-06-14 Thread Steve Howell
--- Steven Bethard <[EMAIL PROTECTED]> wrote: > > How about including a driver? > > Yes, absolutely a good idea. Fortunately, the other > Steve borrowed the > time machine already and added this to the end:: > > for p in iter_primes(): > if p > 1000: break > print p >

Re: SimplePrograms challenge

2007-06-14 Thread Steve Howell
--- rzed <[EMAIL PROTECTED]> wrote: > Hm > > ... and so on. > > In much of Python's documentation, and in this case, > an occasional > working example of use would go FAR in aiding > understanding of the > underlying concept. > I agree with your sentiment 100%. Feel free to change t

Re: SimplePrograms challenge

2007-06-14 Thread Steve Howell
--- Joe Riopel <[EMAIL PROTECTED]> wrote: > How about this one for recursion and control flow: > > >>> def hcd(m,n): > ... r = m % n > ... if( r > 0 ): > ... hcd(n, r) > ... else: > ... print "hcd = %d" % (n,) > ... > >>> hcd(119, 544) > hcd = 17 > >>> > > It

Re: Serialization across languages?

2007-06-15 Thread Steve Howell
--- Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > Tobiah a écrit : > > I want to do SOAP like calls from a device who's > libraries > > don't include SOAP. I'm thinking of using simple > HTTP posts, > > but I'm going to want to send arrays and hashes. > > Then I'd second Simon's suggestion t

Re: Python's "only one way to do it" philosophy isn't good?

2007-06-19 Thread Steve Howell
--- Douglas Alan <[EMAIL PROTECTED]> wrote: > > For the record, I have a huge problem with > NIH-syndrome, and think > that every programming language in the world could > learn a thing or > two from what other languages have gotten right. > Which should includes natural languages in my opinion

Re: Help With Better Design

2007-06-20 Thread Steve Howell
--- [EMAIL PROTECTED] wrote: > > ON = "ON" > OFF = "OFF" > > class LightBulb: > def __init__(self, initial_state): > self.state = initial_state > > def TurnOn(self): > if self.state == OFF: > self.state = ON > else: > print "The Bulb Is A

Re: SimplePrograms challenge

2007-06-20 Thread Steve Howell
--- Pete Forman <[EMAIL PROTECTED]> wrote: > André <[EMAIL PROTECTED]> writes: > > > Ok, doctest-based version of the Unit test > example added; so much > > more Pythonic ;-) > > Sorry for being a bit picky but there are a number > of things that I'm > unhappy with in that example. > Your p

Re: Q: listsort and dictsort - official equivalents?

2007-06-20 Thread Steve Howell
--- BJörn Lindqvist <[EMAIL PROTECTED]> wrote: > On 6/20/07, Gabriel Genellina > <[EMAIL PROTECTED]> wrote: > > > It's not true that the sort must complete (or > that the whole file must > > > be read for that matter), Python has cool > generators which makes the > > > above possible. > > > > Tha

Re: SimplePrograms challenge

2007-06-20 Thread Steve Howell
--- Pete Forman <[EMAIL PROTECTED]> wrote: > Steve Howell <[EMAIL PROTECTED]> writes: > > >> 2) assert is not the simplest example of doctest. > > >> The style should be > >> > >> >>> add_money([0.13, 0.02]) &g

Re: SimplePrograms challenge

2007-06-20 Thread Steve Howell
--- Pete Forman <[EMAIL PROTECTED]> wrote: > Steve Howell <[EMAIL PROTECTED]> writes: > > > Feel free to change the page as you see fit, > although thanks for > > discussing it here first. > > Done. I've moved classes up as unittest depends on &

Re: SimplePrograms challenge

2007-06-20 Thread Steve Howell
--- Pete Forman <[EMAIL PROTECTED]> wrote: > > An empty list raises an IndexError, a non-iterable > raises TypeError. > This is correct behavior IMHO, there is nothing to > fix. Median should > return an element (or average of two) from its input > and if that is > not meaningful returning None

ten small Python programs

2007-05-26 Thread Steve Howell
I've always thought that the best way to introduce new programmers to Python is to show them small code examples. When you go to the tutorial, though, you have to wade through quite a bit of English before seeing any Python examples. Below is my attempt at generating ten fairly simple, represen

Re: ten small Python programs

2007-05-26 Thread Steve Howell
--- Steven Bethard <[EMAIL PROTECTED]> wrote: > Very cool! Do you mind putting this up on the Wiki > somewhere so that we > can link to it more easily? Maybe something like: > > http://wiki.python.org/moin/SimplePrograms > Done. > > Though the code should probably follow PEP 8 > guideli

Re: ten small Python programs

2007-05-26 Thread Steve Howell
--- Paul McGuire <[EMAIL PROTECTED]> wrote: > I ***love*** this "10 Little Programs" idea! As > soon as I get a > breathing space, I'm going to add a "10 Little > Parsers" page to the > pyparsing wiki! > Thanks. :) I'm thinking you could actually have a progression from a 1 line program up to

Re: ten small Python programs

2007-05-26 Thread Steve Howell
--- Paul McGuire <[EMAIL PROTECTED]> wrote: > On May 26, 8:48 pm, Steve Howell > <[EMAIL PROTECTED]> wrote: > > > > I'm thinking you could actually have a progression > > from a 1 line program up to a 50-line program. > The > > number 50 is kin

Re: ten small Python programs

2007-05-26 Thread Steve Howell
--- Steven D'Aprano <[EMAIL PROTECTED]> wrote: > On Sat, 26 May 2007 18:48:45 -0700, Steve Howell > wrote: > > > It also has a ComplexNumber class, but I don't > want to > > scare away mathphobes. > > Is it as short as this one-liner? > >

Re: ten small Python programs

2007-05-26 Thread Steve Howell
--- Steven D'Aprano wrote: > On Sat, 26 May 2007 18:48:45 -0700, Steve Howell > wrote: > > > It also has a ComplexNumber class, but I don't > want to > > scare away mathphobes. > > > Is it as short as this one-liner? > > ComplexNumber = comp

Re: Is PEP-8 a Code or More of a Guideline?

2007-05-27 Thread Steve Howell
--- Ben Finney <[EMAIL PROTECTED]> wrote: > Paul McGuire <[EMAIL PROTECTED]> writes: > > > At this point, I realized that I was taking things > too far > > off-topic, so I decided to start a new thread. > > So, uh, what's the purpose of this thread? Did you > have a specific > point to start off

Re: totally lost newbie

2007-05-27 Thread Steve Howell
--- Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > > Maybe it's easier to use a key function instead of a > compare function. A > key function receives an element and must return > something that is then > sorted and the element ends up where the computed > key is in the sorted > list. L

Re: totally lost newbie

2007-05-27 Thread Steve Howell
--- mark <[EMAIL PROTECTED]> wrote: > Hi all > > I posted earlier on this but have changed my > approach so here is my > latest attempt at solving a problem. I have been > working on this for > around 12 hours straight and am still struggling > with it. > > Write a program that reads the values

Re: Newbie question - better way to do this?

2007-05-27 Thread Steve Howell
--- Eric <[EMAIL PROTECTED]> wrote: > I have some working code, but I realized it is just > the way I would > write it in C, which means there is probably a > better (more pythonic) > way of doing it. > > Here's the section of code: > > accumulate = firstIsCaps = False > accumStart = i

Re: Is PEP-8 a Code or More of a Guideline?

2007-05-27 Thread Steve Howell
--- Gabriel Genellina <[EMAIL PROTECTED]> wrote: > > Underscores are not always easily available on non > us-layout keyboards, > like \ and @ and many other "special" characters. A > language that requires > more symbols than the 26 english letters has to make > room somewhere - > keyboard

Re: ten small Python programs

2007-05-27 Thread Steve Howell
--- BartlebyScrivener <[EMAIL PROTECTED]> wrote: > On May 26, 1:43 pm, Steve Howell > <[EMAIL PROTECTED]> wrote: > > -- > > # def defines a method in Python > > def tax(itemCharge, taxRate = 0.05): > > return itemCharge

Re: ten small Python programs

2007-05-27 Thread Steve Howell
--- BartlebyScrivener <[EMAIL PROTECTED]> wrote: > > For the person new to programming (doesn't come from > C or other > languages), I think you need to add a separate > explanation of string > formatting and how it works, or at least add a > comment that tells them > you are using string format

Re: PHP5 programmer learning Python

2007-05-27 Thread Steve Howell
--- romiro <[EMAIL PROTECTED]> wrote: > > Anyway, my first question was if anyone knows of a > tutorial that > focuses on PHP -> Python learning, in such that > there might be a block > of PHP code alongside an example of how to do the > same thing in > Python. I know exactly what you mean, an

Re: PHP5 programmer learning Python

2007-05-27 Thread Steve Howell
--- romiro <[EMAIL PROTECTED]> wrote: > I've recently tried > C#, a very short > lived re-attempt at C++ and Java, and Ruby. To the extend that you're familiar with C++/Java/Ruby, you may find this link as an interesting way to see how Python looks: http://www.dmh2000.com/cjpr/cmpframe.html

Re: Why isn't this query working in python?

2007-05-27 Thread Steve Howell
--- erikcw <[EMAIL PROTECTED]> wrote: > > > > > ('SELECT payment_id FROM amember_payments WHERE > member_id=%s AND > > > expire_date > NOW() AND completed=1 AND > (product_id >11 AND product_id > > > <21)', (1608L,)) > > > () > > > > Here is a copy of the table schema and the first 2 > rows. >

Re: ten small Python programs

2007-05-27 Thread Steve Howell
--- Wildemar Wildenburger <[EMAIL PROTECTED]> wrote: > Steve Howell wrote: > > # def defines a method in Python > > def say_hello(name): > > print 'hello', name > > say_hello('Jack') > > say_hello('Jill'

Re: itertools.groupby

2007-05-27 Thread Steve Howell
--- 7stud <[EMAIL PROTECTED]> wrote: > Bejeezus. The description of groupby in the docs is > a poster child > for why the docs need user comments. Can someone > explain to me in > what sense the name 'uniquekeys' is used this > example: [...] > The groupby method has its uses, but it's behavi

Re: itertools.groupby

2007-05-27 Thread Steve Howell
--- 7stud <[EMAIL PROTECTED]> wrote: > Bejeezus. The description of groupby in the docs is > a poster child > for why the docs need user comments. I would suggest an example with a little more concreteness than what's currently there. For example, this code... import itertools syslog_messa

Re: ten small Python programs

2007-05-27 Thread Steve Howell
--- Steven Bethard <[EMAIL PROTECTED]> wrote: > I think I would rewrite the current unit-testing > example to use the > standard library unittest module:: > > # Let's write reusable code, and unit test it. > def add_money(amounts): > # do arithmetic in pennies so as not to >

Re: ten small Python programs

2007-05-27 Thread Steve Howell
--- Steven Bethard <[EMAIL PROTECTED]> wrote: > > I think I would rewrite the current unit-testing > example to use the > standard library unittest module:: > > # Let's write reusable code, and unit test it. > def add_money(amounts): > # do arithmetic in pennies so as not to

Re: itertools.groupby

2007-05-27 Thread Steve Howell
--- 7stud <[EMAIL PROTECTED]> wrote: > > I'd settle for a simple explanation of what it does > in python. > The groupby function prevents you have from having to write awkward (and possibly broken) code like this: group = [] lastKey = None for item in items: newKey = item.k

Re: itertools.groupby

2007-05-27 Thread Steve Howell
--- Steve Howell <[EMAIL PROTECTED]> wrote: > > --- 7stud <[EMAIL PROTECTED]> wrote: > > > Bejeezus. The description of groupby in the docs > is > > a poster child > > for why the docs need user comments. > Regarding the pitfalls of gr

Re: ten small Python programs

2007-05-27 Thread Steve Howell
--- Steven Bethard <[EMAIL PROTECTED]> wrote: > Steve Howell wrote: > > --- Steven Bethard <[EMAIL PROTECTED]> > wrote: > >> I think I would rewrite the current unit-testing > >> example to use the > >> standard library unittest module:: > &

unit testing

2007-05-27 Thread Steve Howell
--- Steven Bethard <[EMAIL PROTECTED]> wrote: > Have you tried py.test? > > http://codespeak.net/py/dist/test.html > > I've heard good things about it, but haven't gotten > around to trying it > yet. Here's a two-line test suite from the page > above: > > def test_answer(): >

Re: ten small Python programs

2007-05-27 Thread Steve Howell
--- Steven Bethard <[EMAIL PROTECTED]> wrote: > > > > Maybe this is the first good example that > motivates a > > hyperlink to alternatives. Would you accept the > idea > > that we keep my original example on the > SimplePrograms > > page, but we link to a UnitTestingPhilosophies > page, > > and

Re: itertools.groupby

2007-05-27 Thread Steve Howell
--- paul <[EMAIL PROTECTED]> wrote: > > > > Regarding the pitfalls of groupby in general (even > > assuming we had better documentation), I invite > people > > to view the following posting that I made on > > python-ideas, entitled "SQL-like way to manipulate > > Python data structures": > > >

Re: itertools.groupby

2007-05-27 Thread Steve Howell
--- Carsten Haese <[EMAIL PROTECTED]> wrote: > On Sun, 2007-05-27 at 10:17 -0700, 7stud wrote: > > Bejeezus. The description of groupby in the docs > is a poster child > > for why the docs need user comments. Can someone > explain to me in > > what sense the name 'uniquekeys' is used this > exa

Re: Newbie question - better way to do this?

2007-05-27 Thread Steve Howell
--- John Machin <[EMAIL PROTECTED]> wrote: (And you can > > > ignore the fact that > > > it won't find a sequence at the very end of > words, that is fine for my > > > purposes). > > [...] > > Bzzzt. Needs the following code at the end: > if accumulator: > doSomething(accumulator) > FWIW th

Re: Newbie question - better way to do this?

2007-05-27 Thread Steve Howell
--- Steven D'Aprano wrote: > On Sun, 27 May 2007 14:55:42 -0700, John Machin > wrote: > > Bzzzt. > Bzzzt! Can we please refrain from buzzer sounds in this mostly civil forum, even if one beep deserves another? __

Re: unit testing

2007-05-27 Thread Steve Howell
Let me preface every reply here by YMMV. I strongly, strongly encourage people to tap into the unit testing community for all tools that are available to them. Also, let me say that despite any place where Steven and I disagree about the mechanics of unit testing, we're in firm agreement that UNI

Re: itertools.groupby

2007-05-27 Thread Steve Howell
--- Carsten Haese <[EMAIL PROTECTED]> wrote: > [...] It's an abstract code pattern for an abstract use > case. I question the use of abstract code patterns in documentation, as they just lead to confusion. I really think concrete examples are better in any circumstance. Also, to the OP's ori

<    1   2   3   4   5   >