Re: ctypes' c_longdouble: underflow error (bug?)

2010-07-16 Thread kj
In Thomas Jollans writes: >On 07/15/2010 06:41 PM, kj wrote: >> In Thomas Jollans >> writes: >> >>> http://docs.python.org/library/ctypes.html#fundamental-data-types >> >>> c_longdouble maps to float >> >> Thanks for pointing th

XML parsing: SAX/expat & yield

2010-08-04 Thread kj
I want to write code that parses a file that is far bigger than the amount of memory I can count on. Therefore, I want to stay as far away as possible from anything that produces a memory-resident DOM tree. The top-level structure of this xml is very simple: it's just a very long list of "reco

Re: XML parsing: SAX/expat & yield

2010-08-04 Thread kj
In Peter Otten <__pete...@web.de> writes: >How about >http://effbot.org/zone/element-iterparse.htm#incremental-parsing Exactly! Thanks! ~K -- http://mail.python.org/mailman/listinfo/python-list

how to pretty-print Python dict with unicode?

2010-08-04 Thread kj
Is there a simple way to get Python to pretty-print a dict whose values contain Unicode? (Of course, the goal here is that these printed values are human-readable.) If I run the following simple script: from pprint import pprint x = u'\u6c17\u304c\u9055\u3046' print '{%s: %s}' % (u'x', x) pri

Re: Unicode error

2010-08-06 Thread kj
In Nobody writes: >On Fri, 23 Jul 2010 10:42:26 +, Steven D'Aprano wrote: >> Don't write bare excepts, always catch the error you want and nothing >> else. >That advice would make more sense if it was possible to know which >exceptions could be raised. In practice, that isn't possible, a

Re: Unicode error

2010-08-07 Thread kj
the point of that? >> >> +1 QOTW >While I'm always happy to be nominated for QOTW, in this case I didn't >say it, and the nomination should go to KJ. (The ol' "insert Monty Python reference" move: it never fails...) -- http://mail.python.org/mailman/listinfo/python-list

shelf-like list?

2010-08-10 Thread kj
I'm looking for a module that implements "persistent lists": objects that behave like lists except that all their elements are stored on disk. IOW, the equivalent of "shelves", but for lists rather than a dictionaries. Does anyone know of such a module? (I suppose that I could slap together

Re: shelf-like list?

2010-08-14 Thread kj
In Raymond Hettinger writes: >On Aug 12, 1:37=A0pm, Thomas Jollans wrote: >> On Tuesday 10 August 2010, it occurred to kj to exclaim: >> >> > I'm looking for a module that implements "persistent lists": objects >> > that behave like lists except

How to add silent stretches to MP3 using Python?

2010-08-14 Thread kj
Here's the problem: I have about 25,000 mp3 files, each lasting, *on average*, only a few seconds, though the variance is wide (the longest one lasts around 20 seconds). (These files correspond to sample sentences for foreign language training.) The problem is that there is basically no padding

Re: shelf-like list?

2010-08-15 Thread kj
In Chris Rebert writes: >On Sat, Aug 14, 2010 at 5:13 PM, kj wrote: >> In Ra= >ymond Hettinger writes: >>>On Aug 12, 1:37=3DA0pm, Thomas Jollans wrote: >>>> On Tuesday 10 August 2010, it occurred to kj to exclaim: >>>> >>>> >

Re: shelf-like list?

2010-08-15 Thread kj
In "Martin v. Loewis" writes: >> Does anyone know of such a module? >ZODB supports persistent lists. Thanks; I'll check it out. ~K -- http://mail.python.org/mailman/listinfo/python-list

fastest way to test file for string?

2009-06-05 Thread kj
Hi. I need to implement, within a Python script, the same functionality as that of Unix's grep -rl some_string some_directory I.e. find all the files under some_directory that contain the string "some_string". I imagine that I can always resort to the shell for this, but is there an effici

Re: can it be shorter?

2009-06-06 Thread kj
In "tsangpo" writes: >I want to ensure that the url ends with a '/', now I have to do thisa like >below. >url = url + '' if url[-1] == '/' else '/' >Is there a better way? It's a pity that in python regexes are an "extra", as it were. Otherwise I'd propose: url = re.sub("/?$", "/", url) k

Re: can it be shorter?

2009-06-06 Thread kj
In <023a8d04$0$20636$c3e8...@news.astraweb.com> Steven D'Aprano writes: >On Sat, 06 Jun 2009 15:59:37 +, kj wrote: >> In "tsangpo" >> writes: >> >>>I want to ensure that the url ends with a '/', now I have to do thisa >>

Re: Is it possible to use multidimensional arrays ?

2009-06-06 Thread kj
In pdlem...@earthlink.net writes: >All attempts have failed. >import WConio >import array >screen = array.array('H',[0]*75,[0]*24) > ERR array takes at most 2 arguments >screen = array.array('H',[0]*75[0]*24) >T

Re: can it be shorter?

2009-06-06 Thread kj
In kj writes: >In <023a8d04$0$20636$c3e8...@news.astraweb.com> Steven D'Aprano > writes: >>On Sat, 06 Jun 2009 15:59:37 +, kj wrote: >>> In "tsangpo" >>> writes: >>> >>>>I want to ensure that the url ends with a

Re: How to get local copy of docs?

2009-06-07 Thread kj
In TonyM writes: >http://docs.python.org/download.html Perfect. Thanks! kynn -- -- http://mail.python.org/mailman/listinfo/python-list

How to get local copy of docs?

2009-06-07 Thread kj
What's the best way to get a local copy of the documentation at http://docs.python.org? (The goal is to have access to this documentation even when offline.) TIA! kynn -- -- http://mail.python.org/mailman/listinfo/python-list

fileinput.input(f,inplace=True,...) preserves perms?

2009-06-07 Thread kj
Does fileinput.input(files, inplace=True, ...) preserve the permissions of the file? (I.e. does it ensure that the new file has the same permissions as the original file?) TIA! kynn -- -- http://mail.python.org/mailman/listinfo/python-list

Perl's @foo[3,7,1,-1] ?

2009-06-13 Thread kj
Switching from Perl here, and having a hard time letting go... Suppose I have an "array" foo, and that I'm interested in the 4th, 8th, second, and last element in that array. In Perl I could write: my @wanted = @foo[3, 7, 1, -1]; I was a bit surprised when I got this in Python: >>> wanted

Re: Perl's @foo[3,7,1,-1] ?

2009-06-13 Thread kj
In Jack Diederich writes: >There is only so much room in the syntax for common cases before you >end up with ... perl (no offense intended, I'm a perl monk[1]). The >Python grammar isn't as context sensitive or irregular as the perl >grammar so mylist[1,2,3] so the "1,2,3" tuple is always in

Re: Perl's @foo[3,7,1,-1] ?

2009-06-13 Thread kj
ue returned by some_match.groups(). The match comes from a standard regexp defined elsewhere and that captures more groups than I need. (This regexp is applied to every line of a log file.) kj -- http://mail.python.org/mailman/listinfo/python-list

Re: Perl's @foo[3,7,1,-1] ?

2009-06-13 Thread kj
In kj writes: >OK, I see: if Python allowed foo[3,7,1,-1], then foo[3] would be >ambiguous: does it mean the fourth element of foo, or the tuple >consisting of this element alone? I suppose that's good enough >reason to veto this idea... Hmmm, come to think of it, this a

command-line one-liners a la Perl?

2009-06-18 Thread kj
I'm a recovering Perl addict, and I'm jonesin' badly for command-line one-liners, like % perl -lne '@f=split "\t";print join "\t",@f[3,1] if $f[2]=~/frobozz/i' in.txt How can I get my fix with Python? kynn -- http://mail.python.org/mailman/listinfo/python-list

The Python Way for module configuration?

2009-06-27 Thread kj
[PYTHON NOOB ALERT] I want to write a module that serves as a Python front-end to a database. This database can be either in the form of tab-delimited flat files, XML files, or a PostgreSQL server. The module is meant to hide these database implementation details from its users. But, minima

Re: The Python Way for module configuration?

2009-06-27 Thread kj
In Aaron Sherman writes: >On Jun 27, 4:38=A0pm, MRAB wrote: >> > I would appreciate your comments and suggestions. >> >> There are already modules which provide access to databases. >As you can see the "Python Way" is to be rude ;-) >Anyway, your answer is that there are some abstraction la

Re: The Python Way for module configuration?

2009-06-28 Thread kj
n remember everyone calls me kj, even my mom. My name is Keaweikekahialiʻiokamoku Jallalahwallalruwalpindi kj -- http://mail.python.org/mailman/listinfo/python-list

Why re.match()?

2009-07-01 Thread kj
tends towards minimalism, a sort of Occam's razor, when it comes to language entities; i.e. having re.match along with re.search seems to me like an "unnecessary multiplication of entities". What am I missing? TIA! kj -- http://mail.python.org/mailman/listinfo/python-list

Re: Why re.match()?

2009-07-01 Thread kj
In Duncan Booth writes: >So, for example: re.compile("c").match("abcdef", 2) ><_sre.SRE_Match object at 0x02C09B90> re.compile("^c").search("abcdef", 2) I find this unconvincing; with re.search alone one could simply do: >>> re.compile("^c").search("abcdef"[2:]) <_sre.S

Re: Why re.match()?

2009-07-02 Thread kj
In Steven D'Aprano writes: >On Thu, 02 Jul 2009 03:49:57 +, kj wrote: >> In Duncan Booth >> writes: >>>So, for example: >> >>>>>> re.compile("c").match("abcdef", 2) >>><_sre.SRE_Match object at 0x0

Re: Why re.match()?

2009-07-03 Thread kj
In <025db0a6$0$20657$c3e8...@news.astraweb.com> Steven D'Aprano writes: >On Thu, 02 Jul 2009 11:19:40 +, kj wrote: >> If the concern is efficiency for such cases, then simply implement >> optional offset and length parameters for re.search(), to specify any >&

Clarity vs. code reuse/generality

2009-07-03 Thread kj
harder to read, at least for the uninitiated... I'd love to know your opinions on this. TIA! kj -- http://mail.python.org/mailman/listinfo/python-list

Re: Clarity vs. code reuse/generality

2009-07-03 Thread kj
In Alan G Isaac writes: >1. Don't use assertions to test argument values! Out of curiosity, where does this come from? Thanks, kj -- http://mail.python.org/mailman/listinfo/python-list

Re: Clarity vs. code reuse/generality

2009-07-03 Thread kj
In a...@pythoncraft.com (Aahz) writes: >First of all, cmp() is gone in Python 3, unfortunately, so I'd avoid >using it. Good to know. >Second, assuming I understand your code correctly, I'd change >"sense" to "direction" or "order". Than

Re: Clarity vs. code reuse/generality

2009-07-04 Thread kj
In <7xk52p4tgg@ruckus.brouhaha.com> Paul Rubin <http://phr...@nospam.invalid> writes: >kj writes: >> sense = cmp(func(hi), func(lo)) >> if sense == 0: >> return None >> target_plus = sense * target + epsilon >> target_minu

Re: Clarity vs. code reuse/generality

2009-07-04 Thread kj
In Alan G Isaac writes: >> In Alan G Isaac >> writes: >>> 1. Don't use assertions to test argument values! >On 7/3/2009 12:19 PM kj apparently wrote: >> Out of curiosity, where does this come from? >http://docs.python.org/reference/simple_stmt

Re: Clarity vs. code reuse/generality

2009-07-04 Thread kj
In "Pablo Torres N." writes: >On Sat, Jul 4, 2009 at 10:05, kj wrote: >>>http://docs.python.org/reference/simple_stmts.html#grammar-token-assert_s= >tmt >>>"The current code generator emits no code for an assert statement when op= >timization is req

Re: Clarity vs. code reuse/generality

2009-07-04 Thread kj
In <7x4otsux7f@ruckus.brouhaha.com> Paul Rubin <http://phr...@nospam.invalid> writes: >kj writes: >> sense = cmp(func(hi), func(lo)) >> assert sense != 0, "func is not strictly monotonic in [lo, hi]" >bisection search usually just requires th

Re: Clarity vs. code reuse/generality

2009-07-04 Thread kj
In <7xzlbkti7z@ruckus.brouhaha.com> Paul Rubin <http://phr...@nospam.invalid> writes: >kj writes: >> This implies that code that uses *any* assert statement (other than >> perhaps the trivial and meaningless ones like "assert True") is >> liable

Re: Clarity vs. code reuse/generality

2009-07-04 Thread kj
In MRAB writes: >Paul Rubin wrote: >> kj writes: >>> This implies that code that uses *any* assert statement (other than >>> perhaps the trivial and meaningless ones like "assert True") is >>> liable to break, because whatever it is that the

memoization module?

2009-07-05 Thread kj
Is there a memoization module for Python? I'm looking for something like Mark Jason Dominus' handy Memoize module for Perl. TIA! kj -- http://mail.python.org/mailman/listinfo/python-list

Re: Why re.match()?

2009-07-06 Thread kj
In a...@pythoncraft.com (Aahz) writes: >In article , kj wrote: >You may find this enlightening: >http://www.python.org/doc/1.4/lib/node52.html Indeed. Thank you. kj -- http://mail.python.org/mailman/listinfo/python-list

Re: Why re.match()?

2009-07-06 Thread kj
In <4a4e2227$0$7801$426a7...@news.free.fr> Bruno Desthuilliers writes: >kj a écrit : >(snipo >> To have a special-case >> re.match() method in addition to a general re.search() method is >> antithetical to language minimalism, >FWIW, Python has no pretention

ISO library ref in printed form

2009-07-07 Thread kj
Does anyone know where I can buy the Python library reference in printed form? (I'd rather not print the whole 1200+-page tome myself.) I'm interested in both/either 2.6 and 3.0. TIA! kj -- http://mail.python.org/mailman/listinfo/python-list

Re: ISO library ref in printed form

2009-07-07 Thread kj
In a...@pythoncraft.com (Aahz) writes: >In article , kj wrote: >> >>Does anyone know where I can buy the Python library reference in >>printed form? (I'd rather not print the whole 1200+-page tome >>myself.) I'm interested in both/either 2.6 and 3.0.

Re: ISO library ref in printed form

2009-07-07 Thread kj
In Scott David Daniels writes: >Also consider grabbing Gruet's "Python Quick Reference" page. Not quite what I had in mind, but handy all the same. Thanks. kj -- http://mail.python.org/mailman/listinfo/python-list

tough-to-explain Python

2009-07-07 Thread kj
>>> ham += [5] >>> spam ([1, 2, 3, 4, 5, 5],) >>> What do you say to that? I can come up with much mumbling about pointers and stacks and heaps and much hand-waving about the underlying this-and-that, but nothing that sounds even remotely illuminating. Your suggestions would be much appreciated! TIA! kj -- http://mail.python.org/mailman/listinfo/python-list

Re: tough-to-explain Python

2009-07-07 Thread kj
In Piet van Oostrum writes: >>>>>> kj (k) wrote: >>k> I'm having a hard time coming up with a reasonable way to explain >>k> certain things to programming novices. >>k> Consider the following interaction sequence: >>>>>> d

Re: tough-to-explain Python

2009-07-07 Thread kj
eaning of the "=" in Python's spam = ham is from the "=" in its spam[3] = ham[3] So much for "explicit is better than implicit"... And it confirmed Paul Graham's often-made assertion that all of programming language design is still catching up to

Re: Fractions as result from divisions (was: Re: tough-to-explain Python)

2009-07-08 Thread kj
it was considered to just return a >fraction from that operation. http://www.python.org/dev/peps/pep-0239/ kj -- http://mail.python.org/mailman/listinfo/python-list

Re: tough-to-explain Python

2009-07-08 Thread kj
e, to get past the most amateurish level, one has to, one way or another, come face-to-face with bits, compilers, algorithms, and all the rest that real computer scientists learn about in their formal training... kj -- http://mail.python.org/mailman/listinfo/python-list

Re: tough-to-explain Python

2009-07-08 Thread kj
In <5f0a2722-45eb-468c-b6b2-b7bb80ae5...@q11g2000yqi.googlegroups.com> Simon Forman writes: >I'm not kidding. I wrote a (draft) article about this: "Computer >Curriculum" http://docs.google.com/View?id=dgwr777r_31g4572gp4 Very cool. kj -- http://mail.python.org/mailman/listinfo/python-list

The meaning of "=" (Was: tough-to-explain Python)

2009-07-08 Thread kj
In kj writes: >I had not realized how *profoundly* different the meaning of the >"=" in Python's > spam = ham >is from the "=" in its > spam[3] = ham[3] To clarify, this comes from my reading of Fredrik Lundh's pages "Python Objects"

Re: The meaning of "=" (Was: tough-to-explain Python)

2009-07-08 Thread kj
In <0778f257-d36c-4e13-93ea-bf8d448c8...@b15g2000yqd.googlegroups.com> Paul Boddie writes: >On 8 Jul, 16:04, kj wrote: >> >> =A0 =3D >> >> and not to those like, for example, >> >> =A0 [] =3D >> >> or >> >> =A0 . =3D &g

Re: The meaning of "=" (Was: tough-to-explain Python)

2009-07-08 Thread kj
In a...@pythoncraft.com (Aahz) writes: >In article , kj wrote: >> >>OK, so, scratching from my original post the case >> >>. = >> >>(as being a special case of = ), still, >>to the extent that I understand your post, the "=" in >&g

Re: ISO library ref in printed form

2009-07-08 Thread kj
In Piet van Oostrum writes: >>>>>> kj (kj) wrote: >>kj> Does anyone know where I can buy the Python library reference in >>kj> printed form? (I'd rather not print the whole 1200+-page tome >>kj> myself.) I'm interested in both/eit

Re: Clarity vs. code reuse/generality

2009-07-08 Thread kj
In Martin Vilcans writes: >On Fri, Jul 3, 2009 at 4:05 PM, kj wrote: >> I'm will be teaching a programming class to novices, and I've run >> into a clear conflict between two of the principles I'd like to >> teach: code clarity vs. code reuse. =A0I'd lo

Re: Clarity vs. code reuse/generality

2009-07-08 Thread kj
In Scott David Daniels writes: >First, a quote which took me a bit to find: > Thomas William Körner paraphrasing Polya and Svego > in A Companion to Analysis: > Recalling that 'once is a trick, twice is a method, > thrice is a theorem, and four times a theory,' we >

Re: Clarity vs. code reuse/generality

2009-07-08 Thread kj
In Tim Rowe writes: >2009/7/4 kj : >> Precisely. =A0As I've stated elsewhere, this is an internal helper >> function, to be called only a few times under very well-specified >> conditions. =A0The assert statements checks that these conditions >> are as i

How to "gunzip-iterate" over a file?

2009-07-29 Thread kj
I need to iterate over the lines of *very* large (>1 GB) gzipped files. I would like to do this without having to read the full compressed contents into memory so that I can apply zlib.decompress to these contents. I also would like to avoid having to gunzip the file (i.e. creating an uncompre

Re: How to "gunzip-iterate" over a file?

2009-07-31 Thread kj
Robert, Paul, thanks. That was just what I was looking for. kynn -- http://mail.python.org/mailman/listinfo/python-list

Python docs disappointing

2009-07-31 Thread kj
I'm pretty new to Python, and I like a lot overall, but I find the documentation for Python rather poor, overall. I'm sure that Python experts don't have this problem: they have internalized some good ways to access the documentation, are productive with it, and therefore have lost the ability

Re: Python docs disappointing

2009-07-31 Thread kj
In Carl Banks writes: >(omg you have to use a >*mouse*) That's precisely the point. There's a huge number of programmers out there who, like me, *hate* to use the mouse while they're coding. It is truly disappointing to us that the developers of Python chose to completely disregard this cons

Re: Python docs disappointing

2009-08-02 Thread kj
In <09bf4f17-40a5-4bad-81d3-1950545b7...@g6g2000vbr.googlegroups.com> Carl Banks writes: Thanks. Your remarks at least confirm that my impression was not simply due to my noob ignorance: the keyboard-accessible docs are indeed as poor as they look. kynn -- http://mail.python.org/mailman/list

kw param question

2009-08-03 Thread kj
I want to write a decorator that, among other things, returns a function that has one additional keyword parameter, say foo=None. When I try def my_decorator(f): # blah, blah def wrapper(*p, foo=None, **kw): x = f(*p, **kw) if (foo): # blah, blah else

Re: kw param question

2009-08-03 Thread kj
In Albert Hopkins writes: >On Mon, 2009-08-03 at 19:59 +0000, kj wrote: >> >> I want to write a decorator that, among other things, returns a >> function that has one additional keyword parameter, say foo=None. >> >> When I try >> >> def my

no-clobber dicts?

2009-08-03 Thread kj
I use the term "no-clobber dict" to refer to a dictionary D with the especial property that if K is in D, then D[K] = V will raise an exception unless V == D[K]. In other words, D[K] can be set if K doesn't exist already among D's keys, or if the assigned value is equal to the current valu

Re: kw param question

2009-08-04 Thread kj
In Steven D'Aprano writes: >On Mon, 03 Aug 2009 19:59:23 +, kj wrote: >> I want to write a decorator that, among other things, returns a function >> that has one additional keyword parameter, say foo=None. >> >> When I try >> >> def my_

Re: no-clobber dicts?

2009-08-04 Thread kj
In Steven D'Aprano writes: >On Mon, 03 Aug 2009 21:07:32 +, kj wrote: >> I use the term "no-clobber dict" to refer to a dictionary D with the >> especial property that if K is in D, then >> >> D[K] = V >> >> will raise an exception

Re: no-clobber dicts?

2009-08-04 Thread kj
In Chris Rebert writes: >On Mon, Aug 3, 2009 at 2:47 PM, r wrote: >> On Aug 3, 4:07=C2=A0pm, kj wrote: >>> I use the term "no-clobber dict" to refer to a dictionary D with >>> the especial property that if K is in D, then >>> >>> =C2=A0

Re: no-clobber dicts?

2009-08-04 Thread kj
In Steven D'Aprano writes: >class ConstantNamespace(dict): >I also have a series of unit tests for it if you're interested in them. Actually, come to think of it, I think I'll take you up on this. I'd love to see those tests. Unit testing in Python is in area I need to work on. TIA! kynn

Re: Overlap in python

2009-08-04 Thread kj
In Jay Bird writes: >Hi everyone, >I've been trying to figure out a simple algorithm on how to combine a >list of parts that have 1D locations that overlap into a non- >overlapping list. For example, here would be my input: >part name location >a 5-9 >b 7-

Re: Overlap in python

2009-08-04 Thread kj
In <78d86d92-d373-4163-a418-600a3eb36...@o15g2000yqm.googlegroups.com> Mark Dickinson writes: >On Aug 4, 7:15=A0pm, Jay Bird wrote: >> Hi everyone, >> >> I've been trying to figure out a simple algorithm on how to combine a >> list of parts that have 1D locations that overlap into a non- >> ove

Re: no-clobber dicts?

2009-08-05 Thread kj
In <00027aa9$0$2969$c3e8...@news.astraweb.com> Steven D'Aprano writes: >No problem. Here you go: >http://www.cybersource.com.au/users/steve/python/constants.py Extremely helpful. Thanks! kynn -- http://mail.python.org/mailman/listinfo/python-list

How to combine regexps?

2009-08-05 Thread kj
One of the nice things one can do with Perl's regexp's is illustrated in the following example: my $gly = qr/gg[ucag]/i my $ala = qr/gc[ucag]/i; my $val = qr/gu[ucag]/i; my $leu = qr/uu[ag]|cu[ucag]/i; my $ile = qr/au[uca]/i; my $aliphatic = qr/$gly|$ala|$val|$leu|$ile/; In other words, one c

Re: How to combine regexps?

2009-08-05 Thread kj
In kj writes: >One of the nice things one can do with Perl's regexp's is illustrated >in the following example: >my $gly = qr/gg[ucag]/i >my $ala = qr/gc[ucag]/i; >my $val = qr/gu[ucag]/i; >my $leu = qr/uu[ag]|cu[ucag]/i; >my $ile = qr/au[uca]/i; >my $aliph

PEP 8 exegetics: conditional imports?

2009-08-07 Thread kj
Conditional imports make sense to me, as in the following example: def foobar(filename): if os.path.splitext(filename)[1] == '.gz': import gzip f = gzip.open(filename) else: f = file(filename) # etc. And yet, quoth PEP 8: - Imports are always put at the

Re: Bug or feature: double strings as one

2009-08-07 Thread kj
In Peter Otten <__pete...@web.de> writes: >durumdara wrote: >> I found an interesting thing in Python. >> Today one of my "def"s got wrong result. >> >> When I checked the code I saw that I miss a "," from the list. >> >> l = ['ó' 'Ó'] >> >> Interesting, that Python handle them as one strin

unique-ifying a list

2009-08-07 Thread kj
Suppose that x is some list. To produce a version of the list with duplicate elements removed one could, I suppose, do this: x = list(set(x)) but I expect that this will not preserve the original order of elements. I suppose that I could write something like def uniquify(items): seen

Why all the __double_underscored_vars__?

2009-08-07 Thread kj
Python is chock-full of identifiers beginning and ending with double underscores, such as __builtin__, __contains__, and __coerce__. Using underscores to signal that an identifier is somehow "private" to an implementation is pretty common in languages other than Python. But in these cases the u

Re: Why all the __double_underscored_vars__?

2009-08-08 Thread kj
In Chris Rebert writes: >The double-underscores indicate that the Python interpreter itself >usually is the caller of the method, and as such some level of "magic" >may be associated with it. Other languages have you do the equivalent >of `def +():` or `def operator +()` to override an operator

Re: Why all the __double_underscored_vars__?

2009-08-08 Thread kj
In David Cournapeau writes: >On Sat, Aug 8, 2009 at 9:11 PM, kj wrote: >> In Chris Rebert p...@rebertia.com> writes: >> >>>The double-underscores indicate that the Python interpreter itself >>>usually is the caller of the method, and as such some level of

How to access a function's formal signature?

2009-08-11 Thread kj
In the standard Python interactive interpreter, the string printed by the help command when applied to a function includes the function's formal signature. E.g.: >>> def foo(bar, *baz, **frobozz): ... pass ... >>> help(foo) Help on function foo in module __main__: foo(bar, *baz, **frobozz)

How to find all possibly overlapping matches?

2009-08-12 Thread kj
re.findall finds all non-overlapping matches, but what if one wants all (maximal) matches, even those that overlap? All the solutions I can come up involve calling re.search iteratively, each time giving it a pos parameter starting just after the start of the previous match. Is there a built-in

Re: How to find all possibly overlapping matches?

2009-08-12 Thread kj
In MRAB writes: >kj wrote: >> >> re.findall finds all non-overlapping matches, but what if one wants >> all (maximal) matches, even those that overlap? >> >> All the solutions I can come up involve calling re.search iteratively, >> each time giving it

How to page output in >>> ?

2009-08-12 Thread kj
How does one tell the python interactive interpreter to run the next output to stdout through the default pager? Basically, I'm looking for Python's equivalent of Perl's debugger's "|" prefix, as in DB<1> |print $long_output TIA! kynn -- http://mail.python.org/mailman/listinfo/python-list

Splitting on '^' ?

2009-08-14 Thread kj
Sometimes I want to split a string into lines, preserving the end-of-line markers. In Perl this is really easy to do, by splitting on the beginning-of-line anchor: @lines = split /^/, $string; But I can't figure out how to do the same thing with Python. E.g.: >>> import re >>> re.split('^'

Re: Splitting on '^' ?

2009-08-16 Thread kj
In ru...@yahoo.com writes: >On Aug 14, 2:23=A0pm, kj wrote: >> Sometimes I want to split a string into lines, preserving the >> end-of-line markers. =A0In Perl this is really easy to do, by splitting >> on the beginning-of-line anchor: >> >> =A0 @lines =3D spli

XPath support?

2009-08-16 Thread kj
I'm looking for a XML parser that produces an object with full XPath support. What I've been using up to now, xml.etree.ElementTree, fails to support Xpath predicates, as in "sp...@eggs='3']/ham". What I'm trying to do is to read-in a large XML string, and parse it into an object from which I c

Re: XPath support?

2009-08-17 Thread kj
In Kev Dwyer writes: >On Sun, 16 Aug 2009 20:29:15 +0000, kj wrote: >> I'm looking for a XML parser that produces an object with full XPath >> support. What I've been using up to now, xml.etree.ElementTree, fails >> to support Xpath predicates, as in "s

Data visualization in Python

2009-08-17 Thread kj
I'm looking for a good Python package for visualizing scientific/statistical data. (FWIW, the OS I'm interested in is Mac OS X). The users of this package will be experimental biologists with little programming experience (but currently learning Python). (I normally visualize data using R or

Need help with Python scoping rules

2009-08-25 Thread kj
I have many years of programming experience, and a few languages, under my belt, but still Python scoping rules remain mysterious to me. (In fact, Python's scoping behavior is the main reason I gave up several earlier attempts to learn Python.) Here's a toy example illustrating what I mean. I

Re: Need help with Python scoping rules

2009-08-26 Thread kj
In John Posner writes: >Stephen Hansen said: >> This sounds like a fundamental confusion -- a namespace is not >> equivalent to a scope, really, I think. >> ... Hmm. I can't find Stephen Hansen's original post anywhere. Where did you come across it? Is there an *official* write-up where th

Re: Need help with Python scoping rules

2009-08-26 Thread kj
In <7figv3f2m3p0...@mid.uni-berlin.de> "Diez B. Roggisch" writes: >Classes are not scopes. This looks to me like a major wart, on two counts. First, one of the goals of OO is encapsulation, not only at the level of instances, but also at the level of classes. Your comment suggests that Python

Re: Need help with Python scoping rules

2009-08-26 Thread kj
In "Martin P. Hellwig" writes: >kj wrote: > >> First, one of the goals of OO is encapsulation, not only at the >> level of instances, but also at the level of classes. >Who says? Python itself: it already offers a limited form of class encapsulation (e.g. clas

Re: Need help with Python scoping rules

2009-08-26 Thread kj
In <16b72319-8023-471c-ba40-8025aa6d4...@a26g2000yqn.googlegroups.com> Carl Banks writes: >> First, one of the goals of OO is encapsulation, not only at the >> level of instances, but also at the level of classes. =A0Your comment >> suggests that Python does not fully support class-level encaps

Re: Need help with Python scoping rules

2009-08-26 Thread kj
In Dave Angel writes: >Thanks for diluting my point. The OP is chasing the wrong problem. Who >cares whether a class initializer can call a method, if the method >doesn't meet its original requirements, to be callable outside the class? >And the arguments about how recursion is restricted

Re: Need help with Python scoping rules

2009-08-26 Thread kj
In <1bf83a7e-f9eb-46ff-84fe-cf42d9608...@j21g2000yqe.googlegroups.com> Carl Banks writes: >On Aug 26, 7:09=A0am, kj wrote: >> In <16b72319-8023-471c-ba40-8025aa6d4...@a26g2000yqn.googlegroups.com> Ca= >rl Banks writes: >> >> >> First, one of the goa

Re: Need help with Python scoping rules

2009-08-26 Thread kj
In Dave Angel writes: >Stephen Fairchild wrote: >> You are trying to run code in a class that does not exist yet. >> >> def Demo(): >> def fact(n): >> if n < 2: >> return 1 >> else: >> return n * fact(n - 1) >> return type("Demo", (object,), {"fa

Re: Need help with Python scoping rules

2009-08-26 Thread kj
In <1bf83a7e-f9eb-46ff-84fe-cf42d9608...@j21g2000yqe.googlegroups.com> Carl Banks writes: >Yeah, it's a little surprising that you can't access class scope from >a function, but that has nothing to do with encapsulation. It does: it thwarts encapsulation. The helper function in my example is o

<    1   2   3   4   >