Re: A gnarly little python loop

2012-11-12 Thread Steve Howell
On Nov 12, 7:21 am, rusi rustompm...@gmail.com wrote: On Nov 12, 12:09 pm, rusi rustompm...@gmail.com wrote: This is a classic problem -- structure clash of parallel loops rest snipped Sorry wrong solution :D The fidgetiness is entirely due to python not allowing C-style loops like

Re: A gnarly little python loop

2012-11-11 Thread Steve Howell
that goes through a succession of transforms each of which is very straightforward. [Steve Howell] def get_tweets(term, get_page): page_nums = itertools.count(1) pages = itertools.imap(api.getSearch, page_nums) valid_pages

Re: A gnarly little python loop

2012-11-11 Thread Steve Howell
On Nov 11, 1:09 am, Paul Rubin no.em...@nospam.invalid wrote: Cameron Simpson c...@zip.com.au 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

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, gg,

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 that

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 no.em...@nospam.invalid wrote: Cameron Simpson c...@zip.com.au writes: | I'd prefer the original code ten times over this inaccessible beast. Me too. Me, I like the itertools

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 namedotpor...@gmail.com 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): ...        

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 oscar.j.benja...@gmail.com 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.

Re: A gnarly little python loop

2012-11-11 Thread Steve Howell
On Nov 11, 4:44 pm, Cameron Simpson c...@zip.com.au wrote: On 11Nov2012 11:16, Steve Howell showel...@yahoo.com wrote: | On Nov 11, 10:34 am, Peter Otten __pete...@web.de wrote: | Steve Howell wrote: | On Nov 11, 1:09 am, Paul Rubin no.em...@nospam.invalid wrote: | Cameron Simpson c

Re: A gnarly little python loop

2012-11-10 Thread Steve Howell
On Nov 10, 2:58 pm, Roy Smith r...@panix.com 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.

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: sum works in sequences (Python 3)

2012-09-19 Thread Steve Howell
On Sep 19, 8:06 am, Neil Cerutti ne...@norwich.edu wrote: On 2012-09-19, Ian Kelly ian.g.ke...@gmail.com 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    

Re: sum works in sequences (Python 3)

2012-09-19 Thread Steve Howell
On Sep 19, 11:34 am, Ian Kelly ian.g.ke...@gmail.com wrote: On Wed, Sep 19, 2012 at 9:37 AM, Steve Howell showel...@yahoo.com 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

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

Re: Comparing strings from the back?

2012-09-14 Thread Steve Howell
On Sep 6, 4:04 am, Oscar Benjamin oscar.j.benja...@gmail.com wrote: On Thu, 06 Sep 2012 06:07:38 -0400, Dave Angel d...@davea.name 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.

Re: Decorators not worth the effort

2012-09-14 Thread Steve Howell
On Sep 14, 6:05 am, Tim Chase python.l...@tim.thechases.com 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

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 gor...@panix.com 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

Re: key/value store optimized for disk storage

2012-05-07 Thread Steve Howell
On May 6, 10:21 pm, John Nagle na...@animats.com wrote: On 5/4/2012 12:14 AM, Steve Howell wrote: On May 3, 11:59 pm, Paul Rubinno.em...@nospam.invalid  wrote: Steve Howellshowel...@yahoo.com  writes:      compressor = zlib.compressobj()      s = compressor.compress(foobar)      s

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 na...@animats.com wrote: On 5/6/2012 9:59 PM, Paul Rubin wrote: Javiernos...@nospam.com  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

Re: key/value store optimized for disk storage

2012-05-04 Thread Steve Howell
On May 3, 11:03 pm, Paul Rubin no.em...@nospam.invalid wrote: Steve Howell showel...@yahoo.com 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

Re: key/value store optimized for disk storage

2012-05-04 Thread Steve Howell
On May 3, 11:59 pm, Paul Rubin no.em...@nospam.invalid wrote: Steve Howell showel...@yahoo.com writes:     compressor = zlib.compressobj()     s = compressor.compress(foobar)     s += compressor.flush(zlib.Z_SYNC_FLUSH)     s_start = s     compressor2 = compressor.copy() I think you

Re: key/value store optimized for disk storage

2012-05-04 Thread Steve Howell
On May 4, 1:01 am, Paul Rubin no.em...@nospam.invalid wrote: Steve Howell showel...@yahoo.com 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

Re: key/value store optimized for disk storage

2012-05-04 Thread Steve Howell
On May 3, 6:10 pm, Miki Tebeka miki.teb...@gmail.com 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,

Re: key/value store optimized for disk storage

2012-05-03 Thread Steve Howell
On May 2, 11:48 pm, Paul Rubin no.em...@nospam.invalid wrote: Paul Rubin no.em...@nospam.invalid 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

Re: key/value store optimized for disk storage

2012-05-03 Thread Steve Howell
On May 3, 1:42 am, Steve Howell showel...@yahoo.com wrote: On May 2, 11:48 pm, Paul Rubin no.em...@nospam.invalid wrote: Paul Rubin no.em...@nospam.invalid 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

Re: key/value store optimized for disk storage

2012-05-03 Thread Steve Howell
On May 3, 9:38 pm, Paul Rubin no.em...@nospam.invalid wrote: Steve Howell showel...@yahoo.com 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

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

Re: key/value store optimized for disk storage

2012-05-02 Thread Steve Howell
On May 2, 7:46 pm, Paul Rubin no.em...@nospam.invalid wrote: Steve Howell showel...@yahoo.com 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 mention up top

Re: key/value store optimized for disk storage

2012-05-02 Thread Steve Howell
On May 2, 8:29 pm, Paul Rubin no.em...@nospam.invalid wrote: Steve Howell showel...@yahoo.com 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

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

2012-04-20 Thread Steve Howell
On Apr 20, 8:01 pm, Roy Smith r...@panix.com wrote: In article 4f921a2d$0$29965$c3e8da3$54964...@news.astraweb.com,  Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Fri, 20 Apr 2012 09:41:25 -0400, Roy Smith wrote: In article

Re: escaping

2012-04-15 Thread Steve Howell
On Apr 15, 2:07 pm, Kiuhnm kiuhnm03.4t.yahoo.it 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

Re: Python Gotcha's?

2012-04-06 Thread Steve Howell
On Apr 5, 10:36 pm, rusi rustompm...@gmail.com wrote: On Apr 6, 9:54 am, Steve Howell showel...@yahoo.com 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

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 steve +comp.lang.pyt...@pearwood.info wrote: On Wed, 04 Apr 2012 22:13:55 -0700, Steve Howell wrote: On Apr 4, 9:49 pm, Steven D'Aprano steve +comp.lang.pyt...@pearwood.info wrote: I can connect to an IMAP server using Python 2.6: steve@runes

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 steve +comp.lang.pyt...@pearwood.info wrote: On Wed, 04 Apr 2012 22:13:55 -0700, Steve Howell wrote: On Apr 4, 9:49 pm, Steven D'Aprano steve +comp.lang.pyt...@pearwood.info wrote: I can connect to an IMAP server using Python 2.6: steve@runes

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 steve +comp.lang.pyt...@pearwood.info 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.IMAP4_SSL

Re: Python Gotcha's?

2012-04-05 Thread Steve Howell
On Apr 5, 5:32 am, Roy Smith r...@panix.com 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

Re: Python Gotcha's?

2012-04-05 Thread Steve Howell
On Apr 5, 5:00 am, Steven D'Aprano steve +comp.lang.pyt...@pearwood.info wrote: On Thu, 05 Apr 2012 11:06:11 +, Duncan Booth wrote: Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: JSON expects double-quote marks, not single:     v = json.loads({'test':'test'})  fails v =  

Re: Difference between tempfile and spooled tempfile?

2012-04-05 Thread Steve Howell
On Apr 5, 7:50 am, Alex van der Spek zd...@xs4all.nl 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 iaink...@gmail.com 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

Re: Difference between tempfile and spooled tempfile?

2012-04-05 Thread Steve Howell
On Apr 5, 8:10 am, Steve Howell showel...@yahoo.com wrote: On Apr 5, 7:50 am, Alex van der Spek zd...@xs4all.nl 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

Re: Python Gotcha's?

2012-04-05 Thread Steve Howell
On Apr 5, 6:03 pm, Steven D'Aprano steve +comp.lang.pyt...@pearwood.info 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

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

Re: Python Gotcha's?

2012-04-05 Thread Steve Howell
On Apr 5, 9:28 pm, rusi rustompm...@gmail.com wrote: On Apr 5, 4:06 pm, Duncan Booth duncan.bo...@invalid.invalid wrote: Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: JSON expects double-quote marks, not single:     v = json.loads({'test':'test'})  fails     v =

Re: escaping/encoding/formatting in python

2012-04-05 Thread Steve Howell
On Apr 5, 9:59 pm, rusi rustompm...@gmail.com wrote: On Apr 6, 6:56 am, Steve Howell showel...@yahoo.com 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

Re: escaping/encoding/formatting in python

2012-04-05 Thread Steve Howell
On Apr 5, 9:59 pm, rusi rustompm...@gmail.com wrote: On Apr 6, 6:56 am, Steve Howell showel...@yahoo.com 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

Re: Async IO Server with Blocking DB

2012-04-04 Thread Steve Howell
On Apr 3, 3:13 pm, looking for lookingforsmart...@gmail.com 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

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 steve +comp.lang.pyt...@pearwood.info 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,

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

2012-04-04 Thread Steve Howell
On Apr 4, 1:37 am, Chris Angelico ros...@gmail.com wrote: On Wed, Apr 4, 2012 at 3:53 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info 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

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 steve +comp.lang.pyt...@pearwood.info 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.

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

2012-04-02 Thread Steve Howell
On Mar 28, 6:55 pm, Ben Finney ben+pyt...@benfinney.id.au wrote: Steven D'Aprano steve+comp.lang.pyt...@pearwood.info 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

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 ros...@gmail.com wrote: On Fri, Mar 30, 2012 at 12:44 AM, Nathan Rice nathan.alexander.r...@gmail.com 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

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 jeanpierr...@gmail.com 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.

Re: Python is readable

2012-04-02 Thread Steve Howell
On Mar 29, 9:38 pm, Nathan Rice nathan.alexander.r...@gmail.com 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,

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 jeanpierr...@gmail.com wrote: On Thu, Mar 29, 2012 at 10:03 AM, Chris Angelico ros...@gmail.com 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

Re: Python is readable

2012-04-02 Thread Steve Howell
On Mar 29, 8:36 pm, Steven D'Aprano steve +comp.lang.pyt...@pearwood.info 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?

Re: Python is readable

2012-04-02 Thread Steve Howell
On Mar 30, 1:20 pm, Chris Angelico ros...@gmail.com 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

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 digi...@gmail.com 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. :) obligatory joke Some folks, when confronted with a problem,

Re: Python is readable

2012-04-02 Thread Steve Howell
On Mar 30, 11:25 pm, Lie Ryan lie.1...@gmail.com 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 can act as a subject can also

Re: Python is readable

2012-04-02 Thread Steve Howell
On Apr 1, 8:30 pm, alex23 wuwe...@gmail.com wrote: On Mar 31, 2:02 am, Steve Howell showel...@yahoo.com 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

Re: string interpolation for python

2012-04-02 Thread Steve Howell
On Mar 31, 3:29 am, Terry Reedy tjre...@udel.edu 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 = 30   print(

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 ros...@gmail.com wrote: On Fri, Mar 30, 2012 at 2:48 AM, Steve Howell showel...@yahoo.com 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: concurrent file reading/writing using python

2012-03-26 Thread Steve Howell
On Mar 26, 3:56 pm, Abhishek Pratap abhishek@gmail.com 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

Re: Python is readable

2012-03-23 Thread Steve Howell
On Mar 22, 9:43 pm, MRAB pyt...@mrabarnett.plus.com wrote: On 23/03/2012 04:16, Steve Howell wrote: On Mar 22, 8:20 pm, rusirustompm...@gmail.com  wrote:  On Mar 23, 7:42 am, Steve Howellshowel...@yahoo.com  wrote:    Do you think we'll always have a huge number of incompatible

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 ros...@gmail.com wrote: On Fri, Mar 23, 2012 at 1:48 PM, Steve Howell showel...@yahoo.com wrote: On Mar 22, 6:11 pm, Steven D'Aprano steve +comp.lang.pyt...@pearwood.info wrote: In any case, I'm not talking about the best developers. I'm talking about

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 steve +comp.lang.pyt...@pearwood.info 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 steve+comp.lang.pyt...@pearwood.info wrote: The typical developer knows three, maybe four languages

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 b...@intevation.de wrote: Steve Howell showel...@yahoo.com 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.  I

Re: Python is readable

2012-03-22 Thread Steve Howell
On Mar 22, 1:56 am, Steven D'Aprano steve +comp.lang.pyt...@pearwood.info wrote: On Wed, 21 Mar 2012 18:35:16 -0700, Steve Howell wrote: On Mar 21, 11:06 am, Nathan Rice nathan.alexander.r...@gmail.com wrote: As for syntax, we have a lot of real domain specific languages, such as English

Re: Python is readable

2012-03-22 Thread Steve Howell
On Mar 22, 7:29 am, Nathan Rice nathan.alexander.r...@gmail.com wrote: On Thu, Mar 22, 2012 at 9:17 AM, Chris Angelico ros...@gmail.com wrote: On Thu, Mar 22, 2012 at 11:47 PM, Nathan Rice nathan.alexander.r...@gmail.com wrote: Having one core language with many DSLs that can interoperate

Re: Python is readable

2012-03-22 Thread Steve Howell
On Mar 22, 10:44 am, Steven D'Aprano steve +comp.lang.pyt...@pearwood.info 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

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 steve +comp.lang.pyt...@pearwood.info 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

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 ros...@gmail.com wrote: On Fri, Mar 23, 2012 at 4:44 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: The typical developer knows three, maybe four languages moderately well, if you include SQL and regexes as languages, and might have a

Re: Python is readable

2012-03-22 Thread Steve Howell
On Mar 22, 8:20 pm, rusi rustompm...@gmail.com wrote: On Mar 23, 7:42 am, Steve Howell showel...@yahoo.com 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 2062

Re: Python is readable

2012-03-21 Thread Steve Howell
On Mar 20, 10:40 pm, Chris Angelico ros...@gmail.com wrote: On Wed, Mar 21, 2012 at 3:58 PM, Steve Howell showel...@yahoo.com wrote: So saying push(stack, item) or push(item, stack) seems very unsophisticated, almost assembly-like in syntax, albeit at a higher level conceptually than

Re: Python is readable

2012-03-21 Thread Steve Howell
On Mar 21, 12:16 am, Chris Rebert c...@rebertia.com wrote: On Tue, Mar 20, 2012 at 11:52 PM, Steve Howell showel...@yahoo.com wrote: On Mar 20, 10:40 pm, Chris Angelico ros...@gmail.com wrote: On Wed, Mar 21, 2012 at 3:58 PM, Steve Howell showel...@yahoo.com wrote: So saying push(stack

Re: Python is readable

2012-03-21 Thread Steve Howell
On Mar 21, 9:22 am, Evan Driscoll drisc...@cs.wisc.edu 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  push(stack, item) # Push on the stack the item   2

Re: Python is readable

2012-03-21 Thread Steve Howell
On Mar 21, 4:34 pm, Steven D'Aprano steve +comp.lang.pyt...@pearwood.info 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 had some

Re: Python is readable

2012-03-21 Thread Steve Howell
On Mar 21, 11:06 am, Nathan Rice nathan.alexander.r...@gmail.com 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

Re: Python is readable

2012-03-20 Thread Steve Howell
On Mar 20, 5:22 pm, Steven D'Aprano steve +comp.lang.pyt...@pearwood.info 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

Re: Python is readable

2012-03-20 Thread Steve Howell
On Mar 20, 7:28 pm, Ben Finney ben+pyt...@benfinney.id.au wrote: Steve Howell showel...@yahoo.com 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 program

Re: List comprehension/genexp inconsistency.

2012-03-20 Thread Steve Howell
On Mar 20, 3:50 pm, Ian Kelly ian.g.ke...@gmail.com wrote: On Tue, Mar 20, 2012 at 3:16 PM, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: On Tue, 20 Mar 2012 16:23:22 -0400, J. Cliff Dyer j...@sdf.lonestar.org declaimed the following in gmane.comp.python.general: When trying to create

Re: Python is readable

2012-03-20 Thread Steve Howell
On Mar 20, 9:16 pm, Chris Angelico ros...@gmail.com wrote: On Wed, Mar 21, 2012 at 1:44 PM, Steve Howell showel...@yahoo.com 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

Re: AttributeError in with statement (3.2.2)

2011-12-15 Thread Steve Howell
On Dec 14, 9:01 pm, Steven D'Aprano steve +comp.lang.pyt...@pearwood.info 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

Re: AttributeError in with statement (3.2.2)

2011-12-14 Thread Steve Howell
On Dec 14, 12:01 am, Steven D'Aprano steve +comp.lang.pyt...@pearwood.info 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

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() # outputs

Re: Help with sets

2010-10-14 Thread Steve Howell
On Oct 14, 4:09 pm, Gregory Ewing greg.ew...@canterbury.ac.nz wrote: Steve Howell wrote: That was the original context of my comment.  The term symmetry gets used a couple times in that PEP, and I think we're in violent agreement that the concept of symmetry is wishy-washy at best. Here

Re: PEP 249 (database api) -- executemany() with iterable?

2010-10-14 Thread Steve Howell
On Oct 13, 8:32 pm, Lawrence D'Oliveiro l...@geek- central.gen.new_zealand wrote: In message d2451907-c0d2-4571-b3e1-1e4d4f66a...@a7g2000prb.googlegroups.com, Steve Howell wrote: Bulk-load strategies usually solve one or more of these problems:  network latency That’s not an issue

Re: Boolean value of generators

2010-10-14 Thread Steve Howell
On Oct 14, 7:08 pm, Paul Rubin no.em...@nospam.invalid wrote: Steven D'Aprano st...@remove-this-cybersource.com.au writes: (4) Expensive generators. The beauty of generators is that they produce values on demand. Making all generators cache their first value means that you pay that cost

extract method with generators

2010-10-14 Thread Steve Howell
Is there a way to extract code out of a generator function f() into g() and be able to have f() yield g()'s result without this idiom?: for g_result in g(): yield g_result It feels like a clumsy hindrance to refactoring, to have to introduce a local variable and a loop. Here is a program

Re: Help with sets

2010-10-14 Thread Steve Howell
On Oct 14, 9:22 pm, Lawrence D'Oliveiro l...@geek- central.gen.new_zealand wrote: In message 12fcd67a-774d-42f0-851a-9c3497df9...@s24g2000pri.googlegroups.com, Steve Howell wrote: On Oct 14, 4:09 pm, Gregory Ewing greg.ew...@canterbury.ac.nz wrote: Steve Howell wrote: Maybe analogy

Re: extract method with generators

2010-10-14 Thread Steve Howell
On Oct 14, 8:45 pm, Cameron Simpson c...@zip.com.au wrote: On 14Oct2010 20:11, Steve Howell showel...@yahoo.com wrote: | Is there a way to extract code out of a generator function f() into | g() and be able to have f() yield g()'s result without this idiom?: | |   for g_result in g

Re: Help with sets

2010-10-13 Thread Steve Howell
On Oct 13, 4:27 pm, Lawrence D'Oliveiro l...@geek- central.gen.new_zealand wrote: In message 57a322df-8e42-4da5-af96-0c21c5733...@b14g2000pro.googlegroups.com, Steve Howell wrote: Lawrence, I was actually talking about symmetry, not orthogonality. So what’s the difference? I don't think

Re: Help with sets

2010-10-13 Thread Steve Howell
On Oct 13, 7:25 pm, Lawrence D'Oliveiro l...@geek- central.gen.new_zealand wrote: In message aa6eafa0-7075-424c-abef-79cbc0dd3...@w19g2000yqb.googlegroups.com, Steve Howell wrote: I guess a lot depends on how you define symmetry.  Is your definition of symmetry equivalent to your

Re: Strong typing vs. strong testing [OT]

2010-10-13 Thread Steve Howell
On Oct 13, 12:31 pm, Steven D'Aprano st...@remove-this- cybersource.com.au wrote: 0.2141693770623265 Perhaps this will help illustrate what I'm talking about... the mathematician Mitchell Feigenbaum discovered in 1975 that, for a large class of chaotic systems, the ratio of each bifurcation

Re: how to add patch

2010-10-13 Thread Steve Howell
On Oct 13, 12:36 pm, jimgardener jimgarde...@gmail.com wrote: hi I have some demo python  code hosted on a public host that uses subversion..and I want to modify one of the files using a patch file handed to me by another person..How do I do this?Generally I checkout the code and make the

Re: Help with sets

2010-10-12 Thread Steve Howell
On Oct 12, 5:54 pm, Lawrence D'Oliveiro l...@geek- central.gen.new_zealand wrote: In message mailman.1606.1286889135.29448.python-l...@python.org, D'Arcy J.M. Cain wrote: On Tue, 12 Oct 2010 23:34 +1300 Lawrence D'Oliveiro l...@geek-central.gen.new_zealand wrote: Symmetry is always a

Re: PEP 249 (database api) -- executemany() with iterable?

2010-10-12 Thread Steve Howell
On Oct 12, 6:01 pm, Lawrence D'Oliveiro l...@geek- central.gen.new_zealand wrote: In message 4cb4ba4e$0$1641$742ec...@news.sonic.net, John Nagle wrote: In general, if you find yourself making millions of SQL database requests in a loop, you're doing it wrong. I’ve done this. Not millions,

Re: [Python-Dev] Inclusive Range

2010-10-12 Thread Steve Howell
On Oct 11, 1:40 am, Antoon Pardon antoon.par...@rece.vub.ac.be wrote: On Sat, Oct 09, 2010 at 01:37:03AM +, Steven D'Aprano wrote: On Fri, 08 Oct 2010 15:53:17 -0400, Jed Smith wrote: On Fri, Oct 8, 2010 at 1:26 PM, Steven D'Aprano st...@remove-this-cybersource.com.au wrote: On

Re: Help with sets

2010-10-11 Thread Steve Howell
On Oct 11, 5:11 pm, Gregory Ewing greg.ew...@canterbury.ac.nz wrote: Robert Kern wrote: The reasoning for this decision is spelled out in the PEP introducing the iterator feature:  http://www.python.org/dev/peps/pep-0234/ There's also the question of whether 'if x in dict' should

  1   2   3   4   5   >