Re: Comparing strings from the back?

2012-09-14 Thread Steve Howell
On Sep 6, 4:04 am, Oscar Benjamin wrote: > On Thu, 06 Sep 2012 06:07:38 -0400, Dave Angel wrote: > > For random strings (as defined below), the average compare time is > > effectively unrelated to the size of the string, once the size > passes > > some point. > > Define random string as being a s

Re: Decorators not worth the effort

2012-09-14 Thread Steve Howell
On Sep 14, 6:05 am, Tim Chase wrote: > On 09/14/12 07:01, Steven D'Aprano wrote:> [snip timeout class] > > > Holy over-engineering Batman!!! > > > No wonder you don't think much of decorators, > > [snip] > > > Most of my decorator functions are under a dozen lines. And that's the > > complicated o

python immersion

2012-09-18 Thread Steve Howell
It's been several years since I announced this page the first time, so I feel like it's okay to announce it again, possibly introducing a few new people to Python's elegance and simplicity. This is my attempt to teach Python to programmers who have experience in other languages, using gentle immer

Re: sum works in sequences (Python 3)

2012-09-19 Thread Steve Howell
On Sep 19, 8:06 am, Neil Cerutti wrote: > On 2012-09-19, Ian Kelly wrote: > > > It notes in the doc string that it does not work on strings: > > > sum(...) > >     sum(sequence[, start]) -> value > > >     Returns the sum of a sequence of numbers (NOT strings) plus > >     the value of parameter

Re: sum works in sequences (Python 3)

2012-09-19 Thread Steve Howell
On Sep 19, 11:34 am, Ian Kelly wrote: > On Wed, Sep 19, 2012 at 9:37 AM, Steve Howell wrote: > > Sequences are iterables, so I'd say the docs are technically correct, > > but maybe I'm misunderstanding what you would be trying to clarify. > > The doc string su

attaching names to subexpressions

2012-10-26 Thread Steve Howell
I have been reading the thread "while expression feature proposal," and one of the interesting outcomes of the thread is the idea that Python could allow you to attach names to subexpressions, much like C allows. In C you can say something like this: tax_next_year = (new_salary = salary * (1 +

Re: A gnarly little python loop

2012-11-10 Thread Steve Howell
On Nov 10, 2:58 pm, Roy Smith wrote: > I'm trying to pull down tweets with one of the many twitter APIs.  The > particular one I'm using (python-twitter), has a call: > > data = api.GetSearch(term="foo", page=page) > > The way it works, you start with page=1.  It returns a list of tweets. > If the

Re: A gnarly little python loop

2012-11-11 Thread Steve Howell
t; Me, I like the itertools version better. There's one chunk of data > > > that goes through a succession of transforms each of which > > > is very straightforward. > > > > [Steve Howell] > > > def get_tweets(term, get_page):

Re: A gnarly little python loop

2012-11-11 Thread Steve Howell
On Nov 11, 1:09 am, Paul Rubin wrote: > Cameron Simpson writes: > > | I'd prefer the original code ten times over this inaccessible beast. > > Me too. > > Me, I like the itertools version better.  There's one chunk of data > that goes through a succession of transforms each of which > is very str

Re: Is there a simpler way to modify all arguments in a function before using the arguments?

2012-11-11 Thread Steve Howell
On Nov 9, 4:48 pm, bruceg113...@gmail.com wrote: > Is there a simpler way to modify all arguments in a function before using the > arguments? > > For example, can the below code, in the modify arguments section be made into > a few statements? > >     def someComputation (aa, bb, cc, dd, ee, ff,

Re: logging, can one get it to email messages over a certain level?

2012-11-11 Thread Steve Howell
On Nov 11, 9:48 am, tinn...@isbd.co.uk wrote: > I'm sure this must be possible but at the moment I can't see how to do it. > > I want to send an E-Mail when the logging module logs a message above > a certain level (probably for ERROR and CRITICAL messages only). > > I.e. I want some sort of hook t

Re: A gnarly little python loop

2012-11-11 Thread Steve Howell
On Nov 11, 10:34 am, Peter Otten <__pete...@web.de> wrote: > Steve Howell wrote: > > On Nov 11, 1:09 am, Paul Rubin wrote: > >> Cameron Simpson writes: > >> > | I'd prefer the original code ten times over this inaccessible beast. > >> > M

Re: Method default argument whose type is the class not yet defined

2012-11-11 Thread Steve Howell
On Nov 10, 11:33 am, Jennie wrote: > What is the best solution to solve the following problem in Python 3.3? > > import math >  >>> class Point: > ...     def __init__(self, x=0, y=0): > ...         self.x = x > ...         self.y = y > ...     def __sub__(self, other): > ...         return Point(

Re: Method default argument whose type is the class not yet defined

2012-11-11 Thread Steve Howell
On Nov 11, 4:31 pm, Oscar Benjamin wrote: > On 11 November 2012 22:31, Steven D'Aprano > > Nonsense. The length and direction of a vector is relative to the origin. > > If the origin is arbitrary, as you claim, then so is the length of the > > vector. > > Wrong on all counts. Neither the length n

Re: A gnarly little python loop

2012-11-11 Thread Steve Howell
On Nov 11, 4:44 pm, Cameron Simpson wrote: > On 11Nov2012 11:16, Steve Howell wrote: > | On Nov 11, 10:34 am, Peter Otten <__pete...@web.de> wrote: > | > Steve Howell wrote: > | > > On Nov 11, 1:09 am, Paul Rubin wrote: > | > >> Cameron Simpson writes: &g

Re: A gnarly little python loop

2012-11-12 Thread Steve Howell
On Nov 12, 7:21 am, rusi wrote: > On Nov 12, 12:09 pm, rusi wrote:> This is a classic > problem -- structure clash of parallel loops > > > > Sorry wrong solution :D > > The fidgetiness is entirely due to python not allowing C-style loops > like these: > > >> while ((c=getchar()!= EOF) { ... } >

Re: Python is readable

2012-03-20 Thread Steve Howell
On Mar 20, 5:22 pm, Steven D'Aprano wrote: > On Tue, 20 Mar 2012 15:28:25 -0400, Nathan Rice wrote: > > > What if you are composing > > three or four functions, each of which is conditional on the data?  If > > you extract things from a statement and assign them somewhat arbitrary > > names, you'v

Re: Python is readable

2012-03-20 Thread Steve Howell
On Mar 20, 7:28 pm, Ben Finney wrote: > Steve Howell writes: > > Also, while the above idiom puts the verbs in the right order, it is > > still backward to me to say "noun.verb." You don't noun a verb. You > > verb a noun. > > When calling a method, the

Re: List comprehension/genexp inconsistency.

2012-03-20 Thread Steve Howell
On Mar 20, 3:50 pm, Ian Kelly wrote: > 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

Re: Python is readable

2012-03-20 Thread Steve Howell
On Mar 20, 9:16 pm, Chris Angelico wrote: > On Wed, Mar 21, 2012 at 1:44 PM, Steve Howell wrote: > > I think it's a matter of perspective, so there's no right answer, but > > I always think of the program object as also being the grammatical > > object, with

Re: Python is readable

2012-03-20 Thread Steve Howell
On Mar 20, 10:40 pm, Chris Angelico wrote: > On Wed, Mar 21, 2012 at 3:58 PM, Steve Howell wrote: > > So saying "push(stack, item)" or "push(item, stack)" seems very > > unsophisticated, almost assembly-like in syntax, albeit at a higher > > level concep

Re: Python is readable

2012-03-21 Thread Steve Howell
On Mar 21, 12:16 am, Chris Rebert wrote: > On Tue, Mar 20, 2012 at 11:52 PM, Steve Howell wrote: > > On Mar 20, 10:40 pm, Chris Angelico wrote: > >> On Wed, Mar 21, 2012 at 3:58 PM, Steve Howell wrote: > >> > So saying "push(stack, item)

Re: Python is readable

2012-03-21 Thread Steve Howell
On Mar 21, 9:22 am, Evan Driscoll wrote: > On 01/-10/-28163 01:59 PM, Steve Howell wrote: > > > > > > > > > > > Code shouldn't necessarily follow the example of English prose, but it > > seems that English has had some influence: > > >   1

Re: Python is readable

2012-03-21 Thread Steve Howell
On Mar 21, 4:34 pm, Steven D'Aprano wrote: > On Wed, 21 Mar 2012 11:22:01 -0500, Evan Driscoll wrote: > > On 01/-10/-28163 01:59 PM, Steve Howell wrote: > >> Code shouldn't necessarily follow the example of English prose, but it > >> seems that English has

Re: Python is readable

2012-03-21 Thread Steve Howell
On Mar 21, 11:06 am, Nathan Rice wrote: > As for syntax, we have a lot of "real" domain specific languages, such > as English, math and logic. They are vetted, understood and useful > outside the context of programming.  We should approach the discussion > of language syntax from the perspective o

Re: Python is readable

2012-03-22 Thread Steve Howell
On Mar 22, 1:56 am, Steven D'Aprano wrote: > On Wed, 21 Mar 2012 18:35:16 -0700, Steve Howell wrote: > > On Mar 21, 11:06 am, Nathan Rice > > wrote: > >> As for syntax, we have a lot of "real" domain specific languages, such > >> as English, math a

Re: Python is readable

2012-03-22 Thread Steve Howell
On Mar 22, 7:29 am, Nathan Rice wrote: > On Thu, Mar 22, 2012 at 9:17 AM, Chris Angelico wrote: > > On Thu, Mar 22, 2012 at 11:47 PM, Nathan Rice > > wrote: > >> Having one core language with > >> many DSLs that can interoperate is infinitely better than having many > >> languages that cannot.  

Re: Python is readable

2012-03-22 Thread Steve Howell
On Mar 22, 10:44 am, Steven D'Aprano wrote: > On Thu, 22 Mar 2012 10:29:48 -0400, Nathan Rice wrote: > > Or at least before *I* black out. Even if somebody manages to write your > meta-language, you're going to run into the problem of who is going to be > able to use it. The typical developer know

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

2012-03-22 Thread Steve Howell
On Mar 22, 6:11 pm, Steven D'Aprano wrote: > On Fri, 23 Mar 2012 06:14:46 +1100, Chris Angelico wrote: > > In any case, though, I agree that there's a lot of people professionally > > writing code who would know about the 3-4 that you say. I'm just not > > sure that they're any good at coding, eve

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

2012-03-22 Thread Steve Howell
On Mar 22, 12:14 pm, Chris Angelico wrote: > On Fri, Mar 23, 2012 at 4:44 AM, Steven D'Aprano > > wrote: > > The typical developer knows three, maybe four languages > > moderately well, if you include SQL and regexes as languages, and might > > have a nodding acquaintance with one or two more. >

Re: Python is readable

2012-03-22 Thread Steve Howell
On Mar 22, 8:20 pm, rusi wrote: > On Mar 23, 7:42 am, Steve Howell wrote: > > > Do you think we'll always have a huge number of incompatible > > programming languages?  I agree with you that it's a fact of life in > > 2012, but will it be a fact of life in 2

Re: Python is readable

2012-03-23 Thread Steve Howell
On Mar 22, 9:43 pm, MRAB wrote: > On 23/03/2012 04:16, Steve Howell wrote: > > > > > > > > > On Mar 22, 8:20 pm, rusi  wrote: > >>  On Mar 23, 7:42 am, Steve Howell  wrote: > > >>  >  Do you think we'll always have a huge number of inc

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

2012-03-23 Thread Steve Howell
On Mar 23, 12:05 am, Chris Angelico wrote: > On Fri, Mar 23, 2012 at 1:48 PM, Steve Howell wrote: > > On Mar 22, 6:11 pm, Steven D'Aprano > +comp.lang.pyt...@pearwood.info> wrote: > >> In any case, I'm not talking about the best developers. I'm talking a

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

2012-03-23 Thread Steve Howell
On Mar 22, 6:11 pm, Steven D'Aprano wrote: > On Fri, 23 Mar 2012 06:14:46 +1100, Chris Angelico wrote: > > On Fri, Mar 23, 2012 at 4:44 AM, Steven D'Aprano > > wrote: > >> The typical developer knows three, maybe four languages moderately > >> well, if you include SQL and regexes as languages, an

passing context into BaseHTTPRequestHandler

2012-03-23 Thread Steve Howell
I have a use case where I'm running BaseHTTPServer.HTTPServer, and I want to configure the request handler with some context. I've gotten the code to work, but it feels overly heavy. I am wondering if anybody could suggest an easier idiom for this. This is a brief sketch of the code: class

Re: passing context into BaseHTTPRequestHandler

2012-03-23 Thread Steve Howell
On Mar 23, 12:19 pm, Bernhard Herzog wrote: > Steve Howell writes: > > I have a use case where I'm running BaseHTTPServer.HTTPServer, and I > > want to configure the request handler with some context.  I've gotten > > the code to work, but it feels overly heavy.

Re: concurrent file reading/writing using python

2012-03-26 Thread Steve Howell
On Mar 26, 3:56 pm, Abhishek Pratap wrote: > Hi Guys > > I am fwding this question from the python tutor list in the hope of > reaching more people experienced in concurrent disk access in python. > > I am trying to see if there are ways in which I can read a big file > concurrently on a multi cor

Re: unittest: assertRaises() with an instance instead of a type

2012-04-02 Thread Steve Howell
On Mar 28, 6:55 pm, Ben Finney wrote: > Steven D'Aprano writes: > > (By the way, I have to question the design of an exception with error > > codes. That seems pretty poor design to me. Normally the exception *type* > > acts as equivalent to an error code.) > > Have a look at Python's built-in OS

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

2012-04-02 Thread Steve Howell
On Mar 29, 7:03 am, Chris Angelico wrote: > On Fri, Mar 30, 2012 at 12:44 AM, Nathan Rice > > wrote: > > We would be better off if all the time that was spent on learning > > syntax, memorizing library organization and becoming proficient with > > new tools was spent learning the mathematics, log

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

2012-04-02 Thread Steve Howell
On Mar 29, 11:53 am, Devin Jeanpierre wrote: > Well, what sort of language differences make for English vs Mandarin? > Relational algebraic-style programming is useful, but definitely a > large language barrier to people that don't know any SQL. I think this > is reasonable. (It would not matter

Re: Python is readable

2012-04-02 Thread Steve Howell
On Mar 29, 9:38 pm, Nathan Rice wrote: > The mathematics of the 20th century, (from the early 30s onward) tend > to get VERY abstract, in just the way Joel decries.  Category theory, > model theory, modern algebraic geometry, topos theory, algebraic graph > theory, abstract algebras and topologic

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

2012-04-02 Thread Steve Howell
On Mar 29, 9:42 am, Devin Jeanpierre wrote: > On Thu, Mar 29, 2012 at 10:03 AM, Chris Angelico wrote: > > You can't merge all of them without making a language that's > > suboptimal at most of those tasks - probably, one that's woeful at all > > of them. I mention SQL because, even if you were to

Re: Python is readable

2012-04-02 Thread Steve Howell
On Mar 29, 8:36 pm, Steven D'Aprano wrote: > The Romans had perfectly functioning concrete without any abstract > understanding of chemistry. If I ever stumbled upon a technology that proved how useless abstract thinking was, do you know what I would call it? "Concrete." Damn, those clever Rom

Re: Python is readable

2012-04-02 Thread Steve Howell
On Mar 30, 1:20 pm, Chris Angelico wrote: > > Really?  Or could it be that algorithms for natural language > > processing that don't fail miserably is a very recent development, > > restricted natural languages more recent still, and pretty much all > > commonly used programming languages are all

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

2012-04-02 Thread Steve Howell
On Mar 31, 1:13 pm, Tim Rowe wrote: > > I know 10 languages. But I'm not telling you what base that number is :) > Well, that means you know at least two programming languages, which puts you ahead of a lot of people. :) Some folks, when confronted with a problem, decide to solve it with binary

Re: Python is readable

2012-04-02 Thread Steve Howell
On Mar 30, 11:25 pm, Lie Ryan wrote: > On 03/21/2012 01:44 PM, Steve Howell wrote: > > > Also, don't they call those thingies "object" for a reason? ;) > > A subject is (almost?) always a noun, and so a subject is also an object. It's true that words that

Re: Python is readable

2012-04-02 Thread Steve Howell
On Apr 1, 8:30 pm, alex23 wrote: > On Mar 31, 2:02 am, Steve Howell wrote: > > > Steven, how do you predict which abstractions are going to be useless? > > A useless abstraction is one that does nothing to simplify a problem > *now*: That's the very definition of shor

Re: string interpolation for python

2012-04-02 Thread Steve Howell
On Mar 31, 3:29 am, Terry Reedy wrote: > On 3/31/2012 2:22 AM, Yingjie Lan wrote: > > > Hi all, > > > I'd really like to share this idea of string interpolation for formatting. > > Let's start with some code: > > >  >>> name = "Shrek" > >  >>> print( "Hi, $name$!") > > Hi, Shrek! > >  >>> balls =

588 Python programs

2012-04-02 Thread Steve Howell
Hi everyone, I have compiled over 500 Python programs from the Rosetta Code website in this page: http://shpaml.webfactional.com/misc/RosettaCoffee/python.htm For those of you unfamiliar with Rosetta Code, you can read more here: http://rosettacode.org/wiki/Rosetta_Code For the record,

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

2012-04-02 Thread Steve Howell
On Apr 2, 2:50 pm, Chris Angelico wrote: > On Fri, Mar 30, 2012 at 2:48 AM, Steve Howell wrote: > > I agree with you on the overall point, but I think that Python > > actually does a fine job of replacing REXX and PHP.  I've used both of > > the latter (and, of course,

Re: Async IO Server with Blocking DB

2012-04-04 Thread Steve Howell
On Apr 3, 3:13 pm, looking for wrote: > Hi > > We are thinking about building a webservice server and considering > python event-driven servers i.e. Gevent/Tornado/ Twisted or some > combination thereof etc. > > We are having doubts about the db io part. Even with connection > pooling and cache, t

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

2012-04-04 Thread Steve Howell
On Apr 3, 11:19 pm, Steven D'Aprano wrote: > On Tue, 03 Apr 2012 08:39:14 -0400, Nathan Rice wrote: > > Much like > > with the terminal to GUI transition, you will have people attacking > > declarative natural language programming as a stupid practice for noobs, > > and the end of computing (even

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

2012-04-04 Thread Steve Howell
On Apr 4, 1:37 am, Chris Angelico wrote: > On Wed, Apr 4, 2012 at 3:53 PM, Steven D'Aprano > > wrote: > > On Tue, 03 Apr 2012 15:46:31 -0400, D'Arcy Cain wrote: > > >> def cp(infile, outfile): > >>    open(outfile, "w").write(open(infile).read()) > > > Because your cp doesn't copy the FILE, it co

Re: Cannot connect to IMAP server in Python 3.2

2012-04-04 Thread Steve Howell
On Apr 4, 9:49 pm, Steven D'Aprano wrote: > I can connect to an IMAP server using Python 2.6: > > steve@runes:~$ python2.6 > Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40) > [GCC 4.4.5] on linux2 > Type "help", "copyright", "credits" or "license" for more information.>>> > import imaplib > >>>

Re: Cannot connect to IMAP server in Python 3.2

2012-04-05 Thread Steve Howell
On Apr 5, 12:09 am, Steven D'Aprano wrote: > On Wed, 04 Apr 2012 22:13:55 -0700, Steve Howell wrote: > > On Apr 4, 9:49 pm, Steven D'Aprano > +comp.lang.pyt...@pearwood.info> wrote: > >> I can connect to an IMAP server using Python 2.6: > > >> st

Re: Cannot connect to IMAP server in Python 3.2

2012-04-05 Thread Steve Howell
On Apr 5, 12:09 am, Steven D'Aprano wrote: > On Wed, 04 Apr 2012 22:13:55 -0700, Steve Howell wrote: > > On Apr 4, 9:49 pm, Steven D'Aprano > +comp.lang.pyt...@pearwood.info> wrote: > >> I can connect to an IMAP server using Python 2.6: > > >> st

Re: Cannot connect to IMAP server in Python 3.2

2012-04-05 Thread Steve Howell
On Apr 5, 5:25 am, Steven D'Aprano wrote: > On Thu, 05 Apr 2012 12:16:09 +, Steven D'Aprano wrote: > > On Thu, 05 Apr 2012 00:21:31 -0700, Steve Howell wrote: > >> Why are you changing the invocation between versions of Python? > > > Because imaplib.IMA

Re: Python Gotcha's?

2012-04-05 Thread Steve Howell
On Apr 5, 5:32 am, Roy Smith wrote: > [...] Nobody expects > that a JSON parser will be parsing human-written input, [...] Humans write JSON all the time. People use JSON as a configuration language, and some people actually write JSON files by hand. A common example would be writing package.js

Re: Python Gotcha's?

2012-04-05 Thread Steve Howell
On Apr 5, 5:00 am, Steven D'Aprano wrote: > On Thu, 05 Apr 2012 11:06:11 +, Duncan Booth wrote: > > Steven D'Aprano wrote: > > >> JSON expects double-quote marks, not single: > >>     v = json.loads("{'test':'test'}")  fails v = > >>     json.loads('{"test":"test"}')  succeeds > > > You mean

Re: Difference between tempfile and spooled tempfile?

2012-04-05 Thread Steve Howell
On Apr 5, 7:50 am, "Alex van der Spek" wrote: > I do not understand why the spooled write gives an error. See below. > The normal tempfile works just fine. They are supposed to behave equal? > > All insight you can provide is welcome. > Alex van der Spek > > +++

Re: Python Gotcha's?

2012-04-05 Thread Steve Howell
On Apr 5, 8:23 am, Iain King wrote: > A common one used to be expecting .sort() to return, rather than mutate (as > it does).  Same with .reverse() - sorted and reversed have this covered, not > sure how common a gotcha it is any more. > The sort()/sorted() variations are good to cover. To giv

Re: Difference between tempfile and spooled tempfile?

2012-04-05 Thread Steve Howell
On Apr 5, 8:10 am, Steve Howell wrote: > On Apr 5, 7:50 am, "Alex van der Spek" wrote: > > > > > > > > > > > I do not understand why the spooled write gives an error. See below. > > The normal tempfile works just fine. They are supposed t

Re: Python Gotcha's?

2012-04-05 Thread Steve Howell
On Apr 5, 6:03 pm, Steven D'Aprano wrote: > On Thu, 05 Apr 2012 23:08:11 +0200, André Malo wrote: > > * Steven D'Aprano wrote: > > >> For a 21st century programming language or data format to accept only > >> one type of quotation mark as string delimiter is rather like having a > >> 21st century

escaping/encoding/formatting in python

2012-04-05 Thread Steve Howell
One of the biggest nuisances for programmers, just beneath date/time APIs in the pantheon of annoyances, is that we are constantly dealing with escaping/encoding/formatting issues. I wrote this little program as a cheat sheet for myself and others. Hope it helps. # escaping quotes legal_strin

Re: Python Gotcha's?

2012-04-05 Thread Steve Howell
On Apr 5, 9:28 pm, rusi wrote: > On Apr 5, 4:06 pm, Duncan Booth wrote: > > > Steven D'Aprano wrote: > > > JSON expects double-quote marks, not single: > > >     v = json.loads("{'test':'test'}")  fails > > >     v = json.loads('{"test":"test"}')  succeeds > > > You mean JSON expects a string wi

Re: escaping/encoding/formatting in python

2012-04-05 Thread Steve Howell
On Apr 5, 9:59 pm, rusi wrote: > On Apr 6, 6:56 am, Steve Howell wrote: > > > One of the biggest nuisances for programmers, just beneath date/time > > APIs in the pantheon of annoyances, is that we are constantly dealing > > with escaping/encoding/formatting issues. >

Re: escaping/encoding/formatting in python

2012-04-05 Thread Steve Howell
On Apr 5, 9:59 pm, rusi wrote: > On Apr 6, 6:56 am, Steve Howell wrote: > > > One of the biggest nuisances for programmers, just beneath date/time > > APIs in the pantheon of annoyances, is that we are constantly dealing > > with escaping/encoding/formatting issues. >

Re: Python Gotcha's?

2012-04-05 Thread Steve Howell
On Apr 5, 10:36 pm, rusi wrote: > On Apr 6, 9:54 am, Steve Howell wrote: > > > JS, YAML, and HTML are pretty similar to Python with respect to single > > vs. double, as far as I know/remember/care. > > [Complete ignoramus here -- writing after a few minutes of googling]

Re: escaping

2012-04-15 Thread Steve Howell
On Apr 15, 2:07 pm, Kiuhnm wrote: > This is the behavior I need: >      path = path.replace('\\', '') >      msg = ". {} .. '{}' .. {} .".format(a, path, b) > Is there a better way? > A little more context would help. The quadruple-toothpick idiom predates Python. It's a little hard on the

Re: How do you refer to an iterator in docs?

2012-04-20 Thread Steve Howell
On Apr 20, 8:01 pm, Roy Smith wrote: > In article <4f921a2d$0$29965$c3e8da3$54964...@news.astraweb.com>, >  Steven D'Aprano wrote: > > > > > > > > > > > On Fri, 20 Apr 2012 09:41:25 -0400, Roy Smith wrote: > > > > In article <4f910c3d$0$29965$c3e8da3$54964...@news.astraweb.com>, > > >  Steven D'A

key/value store optimized for disk storage

2012-05-02 Thread Steve Howell
This is slightly off topic, but I'm hoping folks can point me in the right direction. I'm looking for a fairly lightweight key/value store that works for this type of problem: ideally plays nice with the Python ecosystem the data set is static, and written infrequently enough that I definitel

Re: key/value store optimized for disk storage

2012-05-02 Thread Steve Howell
On May 2, 7:46 pm, Paul Rubin wrote: > Steve Howell writes: > >   keys are file paths > >   directories are 2 levels deep (30 dirs w/100k files each) > >   values are file contents > > The current solution isn't horrible, > > Yes it is ;-) > > As I

Re: key/value store optimized for disk storage

2012-05-02 Thread Steve Howell
On May 2, 8:29 pm, Paul Rubin wrote: > Steve Howell writes: > > Thanks.  That's definitely in the spirit of what I'm looking for, > > although the non-64 bit version is obviously geared toward a slightly > > smaller data set.  My reading of cdb is that it has essen

Re: key/value store optimized for disk storage

2012-05-03 Thread Steve Howell
On May 2, 11:48 pm, Paul Rubin wrote: > Paul Rubin writes: > >looking at the spec more closely, there are 256 hash tables.. ... > > You know, there is a much simpler way to do this, if you can afford to > use a few hundred MB of memory and you don't mind some load time when > the program first st

Re: key/value store optimized for disk storage

2012-05-03 Thread Steve Howell
On May 3, 1:42 am, Steve Howell wrote: > On May 2, 11:48 pm, Paul Rubin wrote: > > > Paul Rubin writes: > > >looking at the spec more closely, there are 256 hash tables.. ... > > > You know, there is a much simpler way to do this, if you can afford to > > us

Re: key/value store optimized for disk storage

2012-05-03 Thread Steve Howell
On May 3, 9:38 pm, Paul Rubin wrote: > Steve Howell writes: > > My test was to write roughly 4GB of data, with 2 million keys of 2k > > bytes each. > > If the records are something like english text, you can compress > them with zlib and get some compression gain by p

Re: key/value store optimized for disk storage

2012-05-03 Thread Steve Howell
On May 3, 11:03 pm, Paul Rubin wrote: > Steve Howell writes: > > Sounds like a useful technique.  The text snippets that I'm > > compressing are indeed mostly English words, and 7-bit ascii, so it > > would be practical to use a compression library that just use

Re: key/value store optimized for disk storage

2012-05-04 Thread Steve Howell
On May 3, 11:59 pm, Paul Rubin wrote: > Steve Howell writes: > >     compressor = zlib.compressobj() > >     s = compressor.compress("foobar") > >     s += compressor.flush(zlib.Z_SYNC_FLUSH) > > >     s_start = s > >     compressor2 = compres

Re: key/value store optimized for disk storage

2012-05-04 Thread Steve Howell
On May 4, 1:01 am, Paul Rubin wrote: > Steve Howell writes: > > Makes sense.  I believe I got that part correct: > > >  https://github.com/showell/KeyValue/blob/master/salted_compressor.py > > The API looks nice, but your compress method makes no sense.  Why do you >

Re: key/value store optimized for disk storage

2012-05-04 Thread Steve Howell
On May 3, 6:10 pm, Miki Tebeka wrote: > > I'm looking for a fairly lightweight key/value store that works for > > this type of problem: > > I'd start with a benchmark and try some of the things that are already in the > standard library: > - bsddb > - sqlite3 (table of key, value, index key) > -

Re: key/value store optimized for disk storage

2012-05-07 Thread Steve Howell
On May 6, 10:21 pm, John Nagle wrote: > On 5/4/2012 12:14 AM, Steve Howell wrote: > > > On May 3, 11:59 pm, Paul Rubin  wrote: > >> Steve Howell  writes: > >>>      compressor = zlib.compressobj() > >>>      s = compressor.compress("foobar&qu

Re: Creating a directory structure and modifying files automatically in Python

2012-05-07 Thread Steve Howell
On May 7, 8:46 pm, John Nagle wrote: > On 5/6/2012 9:59 PM, Paul Rubin wrote: > > > Javier  writes: > >> Or not... Using directories may be a way to do rapid prototyping, and > >> check quickly how things are going internally, without needing to resort > >> to complex database interfaces. > > > db

Re: How to get outer class name from an inner class?

2012-05-08 Thread Steve Howell
On May 8, 1:05 pm, John Gordon wrote: > I'm trying to come up with a scheme for organizing exceptions in > my application. > > Currently, I'm using a base class which knows how to look up the text > of a specific error in a database table, keyed on the error class name. > > The base class looks li

AttributeError in "with" statement (3.2.2)

2011-12-13 Thread Steve Howell
I'm using Python 3.2.2, and the following program gives me an error that I don't understand: class Foo: pass foo = Foo() foo.name = "Steve" def add_goodbye_function(obj): def goodbye(): print("goodbye " + obj.name) obj.goodbye = goodbye add_goodbye_function(foo) foo.goodbye() # output

Re: AttributeError in "with" statement (3.2.2)

2011-12-14 Thread Steve Howell
On Dec 14, 12:01 am, Steven D'Aprano wrote: > [...] > > So the normal lookup rules that apply to data attributes, namely > instance, then class, then superclasses, also applies to methods in > Python. In languages that don't allow that sort of thing, like Java, you > need to use convoluted design

Re: AttributeError in "with" statement (3.2.2)

2011-12-15 Thread Steve Howell
On Dec 14, 9:01 pm, Steven D'Aprano wrote: > [...] > So what are methods? In Python, methods are wrappers around functions > which automatically pass the instance to the inner function object. Under > normal circumstances, you create methods by declaring functions inside a > class, but that's not

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

2007-05-31 Thread Steve Howell
--- Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > There was just recently a thread with a > `itertools.groupby()` solution. Yes, indeed. I think it's a very common coding problem (with plenty of mostly analogous variations) that has these very common pitfalls: 1) People often forget t

Re: execute a function after each source code line ?

2007-06-01 Thread Steve Howell
--- stef <[EMAIL PROTECTED]> wrote: > doing a simulation of another language (JAL), > I translate the other language into Python code, > then I execute this converted Python code. > [...] > (btw the whole program is running as an graphical > (wxPython) application) I worked on an open source proje

Re: execute a function after each source code line ?

2007-06-01 Thread Steve Howell
--- "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > > Are there any other (simple) ways of achieving > this ? > > (btw the whole program is running as an graphical > (wxPython) application) > > use the python trace facilities. > > http://docs.python.org/lib/module-trace.html > I'm not sure how

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

2007-06-01 Thread Steve Howell
--- Tijs <[EMAIL PROTECTED]> wrote: > > Yes, or a single one that takes a wide range of > construction possibilities, > like strings, lambdas or regexes in various keyword > parameters. > > BlockReader(f, start='>') > BlockReader(f, start=re.compile('>|<'), end='---') > BlockReader(f, start=lambd

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

2007-06-01 Thread Steve Howell
--- Tijs <[EMAIL PROTECTED]> wrote: > Steve Howell wrote: > > [...] but I wonder if the Python community > > couldn't help a lot of newbies (or insufficiently > > caffeinated non-newbies) by any of the following: > > > Well, I'm not a newbie, and I a

Re: subexpressions

2007-06-01 Thread Steve Howell
--- "A.T.Hofkamp" <[EMAIL PROTECTED]> wrote: > > lambda x: (lambda y: sin(y) + cos(y))(x*x) > Elegant. I find the use of y confusing there (thinking about the unit circle), so I'd amend it to this: lambda x: (lambda x2: sin(x2) + cos(x2))(x*x) But I like the overall idea.

Re: execute a function after each source code line ?

2007-06-01 Thread Steve Howell
--- stef <[EMAIL PROTECTED]> wrote: > the language I want to simulate (JAL), > is very Pascal like, > and therefor can be easily converted into equivalent > Python code. > One more idea. If you haven't already, maybe you can post something to the PyPy community to effect of this: ''' I have a P

Re: generating a tree-like structure

2007-06-01 Thread Steve Howell
--- "A.T.Hofkamp" <[EMAIL PROTECTED]> wrote: > > I would probably generate a DOT file to get a 2D > visualization. DOT is part of > Graphviz (graphviz.org), and there are quite a few > graphviz front-ends > available in Python to make DOT generation easier > (pydot, yapgvb, and probably > a few o

Re: execute a function after each source code line ?

2007-06-01 Thread Steve Howell
--- stef <[EMAIL PROTECTED]> wrote: > Steve, > that's exactly what I've in mind. > The screen shots, looks really good, > and I'll definitely will take a deeper look into > your code. Cool, good luck. Feel free to contact me privately if you have questions about the implementation. There's als

Re: subexpressions

2007-06-01 Thread Steve Howell
--- Sergey Dorofeev <[EMAIL PROTECTED]> wrote: > > What syntax would you suggest for a lambda > enhanced to cover your use > > case? > > I suppose you will end up with roughly the same > number of characters, all > > crammed in one line -- or broken into lines at a > random position as it > > happ

Re: subexpressions

2007-06-01 Thread Steve Howell
--- Tijs <[EMAIL PROTECTED]> wrote: > Steve Howell wrote: > > FWIW there's the possibility that even without a > > subexpression syntax, some Python implementations > > would detect the duplication of x*x and optimize > that > > for you. It would have t

Re: subexpressions

2007-06-01 Thread Steve Howell
--- "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > The elegance of that solution very much depends on > the cost of the duplicate > operation vs. the additional function call. > > And for the usecase at hand, that's exactly the > point not to do it: > > [EMAIL PROTECTED]:/tmp$ python -m timeit '

Re: subexpressions

2007-06-01 Thread Steve Howell
--- Paul Boddie <[EMAIL PROTECTED]> wrote: > On 1 Jun, 12:55, Steve Howell <[EMAIL PROTECTED]> > wrote: > > FWIW there's the possibility that even without a > > subexpression syntax, some Python implementations > > would detect the duplication of x*x a

Re: subexpressions

2007-06-02 Thread Steve Howell
> >def f(x): y = x*x; return sin(y)+cos(y); > Although I know valid trigonometry is not the point of this exercise, I'm still trying to figure out why anybody would ever take the square of an angle. What's the square root of pi/4 radians?

  1   2   3   4   5   >