Re: Why doesn't Python remember the initial directory?

2012-08-19 Thread kj
In Roy Smith writes: >In article , kj >wrote: >> As far as I've been able to determine, Python does not remember >> (immutably, that is) the working directory at the program's start-up, >> or, if it does, it does not officially expose this information. &

Why doesn't Python remember the initial directory?

2012-08-19 Thread kj
As far as I've been able to determine, Python does not remember (immutably, that is) the working directory at the program's start-up, or, if it does, it does not officially expose this information. Does anyone know why this is? Is there a PEP stating the rationale for it? Thanks! -- http://ma

How to get initial absolute working dir reliably?

2012-08-18 Thread kj
What's the most reliable way for "module code" to determine the absolute path of the working directory at the start of execution? (By "module code" I mean code that lives in a file that is not meant to be run as a script, but rather it is meant to be loaded as the result of some import statement

Re: Official reason for omitting inspect.currentcallable() ?

2012-08-13 Thread kj
In Chris Angelico writes: >I'm not familiar with it by that name, but Pike's this_function is >what the OP's describing. You got it. >It's a useful construct in theory when you want to write in recursion, >which was part of the rationale behind PE

Official reason for omitting inspect.currentcallable() ?

2012-08-12 Thread kj
Is there an *explicitly stated* reason (e.g. in a PEP, or in some python dev list message) for why the inspect module (at least for Python 2.7) does not include anything like a "currentcallable()" function that would *stably*[1] return the currently executing callable object? (It seems unlikely

sick of distribute, setup, and all the rest...

2011-11-26 Thread kj
it's an all-out disgrace. when is python going to get a decent module distribution system??? and don't tell me to do it myself: it's clear that the sorry situation we have now is precisely that too many programmers without the requisite expertise or policy-making authority have decided to pitch

Java is killing me! (AKA: Java for Pythonheads?)

2011-08-12 Thread kj
n implementing and testing functions with optional arguments in Java would be appreciated. TIA! kj -- http://mail.python.org/mailman/listinfo/python-list

Python app dev tools for Gnome?

2011-01-08 Thread kj
thing like Xcode for Gnome+Python? TIA! ~kj [1] Needless to say, when I write "apps" I mean full-blown GUI apps: windows, menus, events, threads, clickable icon, the whole ball of wax. As opposed to cli apps, panel widgets, etc. -- http://mail.python.org/mailman/listinfo/python-list

Re: __delitem__ "feature"

2010-12-27 Thread kj
In <4d181afb$0$30001$c3e8da3$54964...@news.astraweb.com> Steven D'Aprano writes: >We know it because it explains the observable facts. So does Monday-night quarterbacking... -- http://mail.python.org/mailman/listinfo/python-list

Re: How to pop the interpreter's stack?

2010-12-26 Thread kj
In Ethan Furman writes: >You failed to mention that cleverness is not a prime requisite of the >python programmer -- in fact, it's usually frowned upon. That's the party line, anyway. I no longer believe it. I've been crashing against one bit of cleverness after another in Python's unificat

Re: How to pop the interpreter's stack?

2010-12-26 Thread kj
es the exception than I have for seeing the traceback of Python's underlying C code when I get an error like the one shown above. ~kj -- http://mail.python.org/mailman/listinfo/python-list

Re: __delitem__ "feature"

2010-12-26 Thread kj
In Ian Kelly writes: >On 12/26/2010 10:53 AM, kj wrote: >> P.S. If you uncomment the commented-out line, and comment out the >> last line of the __init__ method (which installs self._delitem as >> self.__delitem__) then *all* the deletion attempts invoke the >>

Re: type(d) != type(d.copy()) when type(d).issubclass(dict)

2010-12-26 Thread kj
In Duncan Booth writes: >kj wrote: >> Watch this: >> >>>>> class neodict(dict): pass >> ... >>>>> d = neodict() >>>>> type(d) >> >>>>> type(d.copy()) >> >> >> >> Bug? Feature?

Re: type(d) != type(d.copy()) when type(d).issubclass(dict)

2010-12-26 Thread kj
t obfuscated design I've ever seen. UserDict, come back, all is forgotten! ~kj -- http://mail.python.org/mailman/listinfo/python-list

__delitem__ "feature"

2010-12-26 Thread kj
talled instance method __delitem__. If I replace dict with UserDict, *both* deletion attempts lead to a call to the dynamic __delitem__ method, and are thus blocked. This is the behavior I expected of dict (and will help me hold on to my belief that I'm not going insane when inevitably I'm

type(d) != type(d.copy()) when type(d).issubclass(dict)

2010-12-24 Thread kj
Watch this: >>> class neodict(dict): pass ... >>> d = neodict() >>> type(d) >>> type(d.copy()) Bug? Feature? Genius beyond the grasp of schlubs like me? ~kj -- http://mail.python.org/mailman/listinfo/python-list

Re: How can a function find the function that called it?

2010-12-24 Thread kj
In Daniel Urban writes: >On Fri, Dec 24, 2010 at 17:24, kj wrote: >> (BTW, I don't understand why inspect doesn't provide something as >> basic as the *class* that the method belongs to, whenever applicable. >> I imagine there's a good reason for this c

How can a function find the function that called it?

2010-12-24 Thread kj
is defined. (BTW, I don't understand why inspect doesn't provide something as basic as the *class* that the method belongs to, whenever applicable. I imagine there's a good reason for this coyness, but I can't figure it out.) TIA! ~kj -- http://mail.python.org/mailman/listinfo/python-list

Re: Partition Recursive

2010-12-23 Thread kj
char are: >specialMeaning = ["//",";","/", "?", ":", "@", "=" , "&","#"] You forgot '.'. >>> import re # sorry >>> sp = re.compile('(//?|[;?:@=&#.])') >>> filter(len, sp.split(url)) ['http', ':', '//', 'docs', '.', 'python', '.', 'org', '/', 'dev', '/', 'library', '/', 'stdtypes', '.', 'html', '\ ?', 'highlight', '=', 'partition', '#', 'str', '.', 'partition'] ~kj -- http://mail.python.org/mailman/listinfo/python-list

Re: How to order base classes?

2010-12-23 Thread kj
In <4d14209d$0$3$c3e8da3$54964...@news.astraweb.com> Steven D'Aprano writes: >The question you ask can only be answered in reference to a specific >class with specific methods. There is no general principle, it depends >entirely on the problem being solved. T

How to order base classes?

2010-12-23 Thread kj
How should one go about deciding the ordering of base classes? TIA! ~kj -- http://mail.python.org/mailman/listinfo/python-list

Re: issubclass(dict, Mapping)

2010-12-22 Thread kj
In <4d127d5e$0$29997$c3e8da3$54964...@news.astraweb.com> Steven D'Aprano writes: >On Wed, 22 Dec 2010 14:20:51 +, kj wrote: >> Here's another example, fresh from today's crop of wonders: >> >> (v. 2.7.0) >>>>> from collectio

general problem when subclassing a built-in class

2010-12-22 Thread kj
on't know the first thing about Python's internals, and even if I did, going behind the documented API like that would make whatever I implement very likely to break with future releases of Python. Approach (2) could also take a very long time (probably much longer than the implementation

Re: How to pop the interpreter's stack?

2010-12-22 Thread kj
In <1f47c36d-a509-4d05-ba79-62b4a534b...@j19g2000prh.googlegroups.com> Carl Banks writes: >On Dec 22, 8:52=A0am, kj wrote: >> In Robert Kern t.k...@gmail.com> writes: >> >> >Obfuscating the location that an exception gets raised prevents a lot of >> >

Re: How to pop the interpreter's stack?

2010-12-22 Thread kj
most useful traceback is the one that stops at the deepest point where the *intended audience* for the traceback can take action, and goes no further. The intended audience for the errors generated by my argument-checking functions should see no further than the point where they called a function incorrectly. ~kj -- http://mail.python.org/mailman/listinfo/python-list

issubclass(dict, Mapping)

2010-12-22 Thread kj
on a time..."). I conclude that, for me to understand Python's (rather leaky) object model abstraction, I have to understand its underlying implementation. Unfortunately, as far as I know, there's no other choice but to study the source code, since there's no other more readable description of this implementation. Maybe there are fewer "abstraction leaks" in 3.0... ~kj -- http://mail.python.org/mailman/listinfo/python-list

How to pop the interpreter's stack?

2010-12-14 Thread kj
its frame from the interpreter stack before re-raising the exception. (Or some clueful/non-oxymoronic version of this.) How feasible is this? And, if it is quite unfeasible, is there some other way to achieve the same overall design goals described above? TIA! ~kj -- http://mail.python.org/mailman/listinfo/python-list

Assigning to __class__ attribute

2010-12-03 Thread kj
definitive/highest-quality information can get lost among a huge number of Google hits to popular-but-only-partially-correct sources of information. (In fact, I *may* have already read the source I'm seeking, but subsequent readings of incorrect stuff may have overwritten the correct information in my brain.) TIA! ~kj -- http://mail.python.org/mailman/listinfo/python-list

Comparing floats

2010-11-27 Thread kj
Absent these possibilities, does Python provide any standard value of epsilon for this purpose? TIA! ~kj -- http://mail.python.org/mailman/listinfo/python-list

Re: Why "flat is better than nested"?

2010-10-27 Thread kj
In Steve Holden writes: >On 10/26/2010 2:44 PM, kj wrote: >> In Steve Holden >> writes: >> >>> The answer is probably the same as you will see if you try >> >>> from __future__ import braces >> >>> That feature *is* availa

Re: Why "flat is better than nested"?

2010-10-26 Thread kj
In Steve Holden writes: >The answer is probably the same as you will see if you try > from __future__ import braces >That feature *is* available in Python 2.6 ;-) Now, that's hilarious. kj -- http://mail.python.org/mailman/listinfo/python-list

Re: Why "flat is better than nested"?

2010-10-26 Thread kj
In Terry Reedy writes: >On 10/25/2010 3:11 PM, kj wrote: >> Well, it's pretty *enshrined*, wouldn't you say? >No. > > After all, it is part of the standard distribution, >So is 'import antigravity' Are you playing with my feelings? % python Pyt

Re: Why "flat is better than nested"?

2010-10-25 Thread kj
In Steve Holden writes: >On 10/25/2010 10:47 AM, rantingrick wrote: >> On Oct 25, 5:07 am, kj wrote: >>> In "The Zen of Python", one of the "maxims" is "flat is better than >>> nested"? Why? Can anyone give me a concrete exa

Re: Why "flat is better than nested"?

2010-10-25 Thread kj
In rantingrick writes: >On Oct 25, 5:07=A0am, kj wrote: >> In "The Zen of Python", one of the "maxims" is "flat is better than >> nested"? =A0Why? =A0Can anyone give me a concrete example that illustrate= >s >> this point? >Simpl

Why "flat is better than nested"?

2010-10-25 Thread kj
In "The Zen of Python", one of the "maxims" is "flat is better than nested"? Why? Can anyone give me a concrete example that illustrates this point? TIA! ~kj PS: My question should not be construed as a defense for "nested". I have no particular pref

How to optimize and monitor garbage collection?

2010-10-24 Thread kj
explicitly call del on objects that should be gc'd? TIA! ~kj -- http://mail.python.org/mailman/listinfo/python-list

MATLAB:matplotlib::Mathematica::???

2010-10-23 Thread kj
ing more Mathematica-like in Python would be appreciated. TIA! kj -- http://mail.python.org/mailman/listinfo/python-list

Re: python shell silently ignores termios.tcsetattr()

2010-10-21 Thread kj
In Lawrence D'Oliveiro writes: >In message , kj wrote: >> I tried to fix the problem by applying the equivalent of "stty >> -echo" within a python interactive session, but discovered that >> this setting is immediately (and silently) overwritten. >That

python shell silently ignores termios.tcsetattr()

2010-10-20 Thread kj
stuff, so it is unlikely that there's a clean solution; I'm hoping, however, that there may be a way to fool python into doing the right thing; after all, this strange behavior only happens under the Emacs shell; I don't observe it under, e.g., Terminal or xterm.) TIA! ~kj -- http://mail.python.org/mailman/listinfo/python-list

Re: annoying CL echo in interactive python / ipython

2010-10-20 Thread kj
In Jed Smith writes: >On Tue, Oct 19, 2010 at 2:35 PM, kj wrote: >> In Jed Smith smith.org> writes: >> >>>On Tue, Oct 19, 2010 at 1:37 PM, kj wrote: >> >>>> % stty -echo >> >>>That doesn't do what you think it does. >>

Re: annoying CL echo in interactive python / ipython

2010-10-19 Thread kj
In Jed Smith writes: >On Tue, Oct 19, 2010 at 1:37 PM, kj wrote: >> % stty -echo >That doesn't do what you think it does. Gee, thanks. That really helped. I'll go talk to my guru now, and meditate over this. -- http://mail.python.org/mailman/listinfo/python-list

annoying CL echo in interactive python / ipython

2010-10-19 Thread kj
(As I said, this happens only under some shells (e.g. emacs shell), so YMMV.) Does anyone know how can I suppress this annoying feature? TIA! ~kj -- http://mail.python.org/mailman/listinfo/python-list

Re: docstring that use globals?

2010-10-16 Thread kj
In <8hujfsfb9...@mid.individual.net> Gregory Ewing writes: >kj wrote: >> The hardest case is "module docstrings". >Actually, that one's quite easy, just assign to __doc__. >__doc__ = "This is a %s docstring" % "made-up" D'oh! Thanks. -- http://mail.python.org/mailman/listinfo/python-list

Re: dynamic loading error ("Symbol not found")

2010-10-16 Thread kj
In Emile van Sebille writes: >On 10/16/2010 2:15 PM kj said... >> >> >> >> The following interaction (in OS X) summarizes the situation: >> >> % echo $DYLD_LIBRARY_PATH >> /Applications/MATLAB_R2010a.app/bin/maci64 >> % grep -r _engCl

dynamic loading error ("Symbol not found")

2010-10-16 Thread kj
; The permissions of the file in question are all OK (0555); likewise, the permissions of all the prefix subpaths leading to this file are fine. (For all I know, it is possible that, even though the libeng.dylib file matches "_engClose", this is only a fragment of a longer symbol name.)

Re: docstring that use globals?

2010-10-16 Thread kj
In kj writes: >MRAB, Peter: thanks for the decorator idea! As an afterthought, is there any way to extend this general idea to other docstrings beyond function docstrings? I imagine that the decorator idea works well for method docstrings too (though I have not tried any of this yet).

Re: docstring that use globals?

2010-10-16 Thread kj
MRAB, Peter: thanks for the decorator idea! ~kj -- http://mail.python.org/mailman/listinfo/python-list

docstring that use globals?

2010-10-16 Thread kj
body can serve as a docstring. What's the best way to achieve what I'm trying to do? (Of course, all these acrobatics are hardly worth the effort for the simple example I give above. In the actual situation I'm dealing with, however, there are a lot more docstrings and global variabl

Re: hashkey/digest for a complex object

2010-10-10 Thread kj
ime, so by now I've developed what can only be described as a phobia to it. I probably need professional help at this point. ~kj -- http://mail.python.org/mailman/listinfo/python-list

Re: hashkey/digest for a complex object

2010-10-10 Thread kj
h function is (or appears to be) idempotent on integers (long or not), even though it is not the identity on the integers. Thanks to Steven for the counterexamples to show the latter. I've learned tons from this exchange. ~kj -- http://mail.python.org/mailman/listinfo/python-list

Re: hashkey/digest for a complex object

2010-10-09 Thread kj
Without some knowledge of the Python internals, I don't see how this follows. More specifically, it is not obvious to me that, for example, hash(frozenset((,))) would be identical to hash(frozenset((hash(),))) but this identity has held every time I've checked it. Similarly for other more complicated variations on this theme. Anyway, thanks for the code. It's very useful. ~kj -- http://mail.python.org/mailman/listinfo/python-list

Re: frozendict (v0.1)

2010-10-08 Thread kj
t frozensets had a consistent order (i.e. frozensets that were equal according to '==' would be iterated over in the same order), but now I'm not sure that this is the case. (Granted, semantically, there's nothing in the definition of a frozenset that would imply a consistent

Re: frozendict (v0.1)

2010-10-08 Thread kj
In "Jonas H." writes: >On 10/08/2010 02:23 AM, kj wrote: >Here's my implementation suggestion: >class frozendict(dict): > def _immutable_error(self, *args, **kwargs): > raise TypeError("%r object is immutable" % self.__class__.__name__)

Re: frozendict (v0.1)

2010-10-08 Thread kj
In kj writes: >At any rate, using your [i.e. Arnaud's] suggestions in this and >your other post, the current implementation of frozendict stands >at: >class frozendict(dict): >for method in ('__delitem__ __setitem__ clear pop popitem setdefault ' >

Re: frozendict (v0.1)

2010-10-08 Thread kj
n again, just looking at the voodoo that goes into algorithms for computing hashes fills me with despair. As much as I dislike it, sooner or later I'll have to go on faith. ~kj -- http://mail.python.org/mailman/listinfo/python-list

Re: frozendict (v0.1)

2010-10-08 Thread kj
In <4cae667c$0$29993$c3e8da3$54964...@news.astraweb.com> Steven D'Aprano writes: >On Fri, 08 Oct 2010 00:23:30 +, kj wrote: >Because it's always better to use a well-written, fast, efficient, >correct, well-tested wheel than to invent your own slow, incorrect &

Re: frozendict (v0.1)

2010-10-07 Thread kj
popitem setdefault ' 'update').split(): exec """ def %s(self, *a, **k): cn = self.__class__.__name__ raise TypeError("'%%s' object is not mutable" %% cn) """ % method def __hash__(self): r

frozendict (v0.1)

2010-10-07 Thread kj
t methods to the delegate (since in this case frozendict.__getattr__ wouldn't be called). The handling of comparison methods is particularly horrific and inefficient. If "Beautiful is better than ugly", I sure how there's another way that is a lot more beautiful than this one. TIA! ~kj -- http://mail.python.org/mailman/listinfo/python-list

how to test for atomicity/mutability/hashability?

2010-10-07 Thread kj
lementation of t() to have a simple test for mutability. Is there one? Thanks! ~kj -- http://mail.python.org/mailman/listinfo/python-list

Re: hashkey/digest for a complex object

2010-10-07 Thread kj
nternals at our local Python club. Thanks, ~kj -- http://mail.python.org/mailman/listinfo/python-list

Re: hashkey/digest for a complex object

2010-10-07 Thread kj
In de...@web.de (Diez B. Roggisch) writes: >kj writes: >> The short version of this question is: where can I find the algorithm >> used by the tuple class's __hash__ method? >Surprisingly, in the source: >http://google.com/codesearch/p?hl=de#-2BKs-LW4I0/trunk/python

Re: hashkey/digest for a complex object

2010-10-07 Thread kj
s). If you had something else in mind, please let me know. ~kj -- http://mail.python.org/mailman/listinfo/python-list

hashkey/digest for a complex object

2010-10-06 Thread kj
27;, '5'])}, 'B': set(['6', '7', '8'])} I'm looking for a good algorithm for computing a hash key for something like this? (Basically I'm looking for a good way to combine hashkeys.) Thanks! kj -- http://mail.python.org/mailman/listinfo/python-list

How parametrize classes by class data?

2010-10-04 Thread kj
looked to me like a rather un-Pythonic hack, but seeing there in the venerable collections module suggested to me that maybe this is actually the best way to achieve this effect in Python. Is this so? If not, please let me know of a better way. TIA! kj -- http://mail.python.org/mailman/listinfo/python-list

namespace hacking question

2010-09-30 Thread kj
of the local variable x. I also tried a hack using eval: for v in ('spam', 'ham', 'eggs'): eval "%s = init('%s')" % (v, v) but the "=" sign in the eval string resulted in a "SyntaxError: invalid syntax". Is there any way to use a loop to set a whole bunch of local variables (and later refer to these variables by their individual names)? TIA! kj -- http://mail.python.org/mailman/listinfo/python-list

Supplementing the std lib (Was: partial sums problem)

2010-09-29 Thread kj
ne reply; rather, I'm interested in reading people's take on the question and their way of dealing with those functions they consider worthy of the standard library.) kj -- http://mail.python.org/mailman/listinfo/python-list

partial sums problem

2010-09-28 Thread kj
The following attempt to get a list of partial sums fails: >>> s = 0 >>> [((s += t) and s) for t in range(1, 10)] File "", line 1 [((s += t) and s) for t in range(1, 10)] ^ SyntaxError: invalid syntax What's the best way to get a list of

audio time-stretching?

2010-09-07 Thread kj
Does anyone know of a Python module for *moderate* "time-stretching"[1] an MP3 (or AIFF) file? FWIW, the audio I want to time-stretch is human speech. TIA! ~K [1] By "moderate time stretching" I mean, for example, taking an audio that would normally play in 5 seconds, and stretch it so that i

Re: How to convert (unicode) text to image?

2010-08-28 Thread kj
In Benjamin Kaplan writes: >On Fri, Aug 27, 2010 at 8:01 PM, kj wrote: >> >> >> Hi! =A0Does anyone know of an easy way to convert a Unicode string into a= >n image file (either jpg or png)? >> >Do you mean you have some text and you want an image containing t

How to convert (unicode) text to image?

2010-08-27 Thread kj
Hi! Does anyone know of an easy way to convert a Unicode string into an image file (either jpg or png)? TIA! ~k -- http://mail.python.org/mailman/listinfo/python-list

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

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: >>>> >>>> >

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

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: 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

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

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: 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

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: 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

Q for Emacs users: code-folding (hideshow)

2010-07-15 Thread kj
This is a question _for Emacs users_ (the rest of you, go away :) ). How do you do Python code-folding in Emacs? Thanks! ~K -- http://mail.python.org/mailman/listinfo/python-list

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

2010-07-15 Thread kj
In Thomas Jollans writes: >http://docs.python.org/library/ctypes.html#fundamental-data-types >c_longdouble maps to float Thanks for pointing this out! ~K (Does it make *any difference at all* to use c_longdouble instead of c_double? If not, I wonder what's the point of having c_longdouble at

ctypes' c_longdouble: underflow error (bug?)

2010-07-14 Thread kj
I have a C library function hg that returns a long double, so when I import it using C types I specify this return type like this: MYLIB.hg.restype = ctypes.c_longdouble But certain non-zero values returned by hg appear as zero Python-side. If I modify hg so that it prints out its value right

Re: Numerics question

2010-07-02 Thread kj
Please disregard my ineptly posed question. ~K In kj writes: >I define >ninv = 1.0/n >...where n is some integer, and I want to write some function f such >that f(m * ninv) returns the smallest integer that is >= m * ninv, >where m is some other integer. And, in par

Numerics question

2010-07-02 Thread kj
I define ninv = 1.0/n ...where n is some integer, and I want to write some function f such that f(m * ninv) returns the smallest integer that is >= m * ninv, where m is some other integer. And, in particular, if m is p*n for some integer p, then f((p*n) * ninv) should return the integer p.

Re: tallying occurrences in list

2010-06-04 Thread kj
Thank you all! ~K -- http://mail.python.org/mailman/listinfo/python-list

tallying occurrences in list

2010-06-04 Thread kj
Task: given a list, produce a tally of all the distinct items in the list (for some suitable notion of "distinct"). Example: if the list is ['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a'], then the desired tally would look something like this: [('a', 4), ('b', 3), ('c', 3)] I find myself

atexit/signal for non-interactive jobs

2010-05-26 Thread kj
I want to implement clean-up functions for scripts to be run on a Linux cluster (through LSF). The goal is to make sure that a minimal wrap-up sequence (print diagnostic info, flush buffers, etc.) gets executed if the job is terminated for some reason. (The most common reason for premature te

Re: Limitation of os.walk

2010-05-12 Thread kj
In Terry Reedy writes: >On 5/11/2010 3:49 PM, kj wrote: >> PS: I never understood why os.walk does not support hooks for key >> events during such a tree traversal. >Either 1) it is intentionally simple, with the expectation that people >would write there own code for

Re: Limitation of os.walk

2010-05-12 Thread kj
In Tim Chase writes: > 05/11/2010 09:07 PM, Terry Reedy wrote: >> If os.walk were rewritten, it should be as an iterator (generator). >> Directory entry and exit functions could still be added as params. >It *is* an iterator/generator. However, I suspect you mean that >it should slurp the dirs

Re: Limitation of os.walk

2010-05-11 Thread kj
In Tim Chase writes: >That said, the core source for os.walk() is a whole 23 >lines of code, it's easy enough to just clone it and add what you >need... Thanks, that was a good idea. ~K -- http://mail.python.org/mailman/listinfo/python-list

Limitation of os.walk

2010-05-11 Thread kj
I want implement a function that walks through a directory tree and performs an analsysis of all the subdirectories found. The task has two essential requirements that, AFAICT, make it impossible to use os.walk for this: 1. I need to be able to prune certain directories from being visited. 2.

Re: Inheritable computed class attributes?

2010-04-30 Thread kj
In <4bdb4e4...@dnews.tpgi.com.au> Lie Ryan writes: >class MetaSpam(type): >@property >def Y(cls): >return cls.X * 3 >class Spam(object): >__metaclass__ = MetaSpam >and there we go: class Ham(Spam): >... X = 7 >... class Eggs(Spam): >... X = '.' >...

Inheritable computed class attributes?

2010-04-30 Thread kj
I want to define a class attribute that is computed from other class attributes. Furthermore, this attribute should be inheritable, and its value in the subclasses should reflect the subclasses values of the attributes used to compute the computed attribute. I tried the following: class Spam(o

Looking for registration package

2010-04-21 Thread kj
I'm looking for a Python-based, small, self-contained package to hand out API keys, in the same spirit as Google API keys. The basic specs are simple: 1) enforce the "one key per customer" rule; 2) be robot-proof; 3) be reasonably difficult to circumvent even for humans. (This is for a web se

Re: How to access args as a list?

2010-04-05 Thread kj
In <4bb802f7$0$8827$c3e8...@news.astraweb.com> Steven D'Aprano writes: >On Sat, 03 Apr 2010 22:58:43 +, kj wrote: >> Suppose I have a function with the following signature: >> >> def spam(x, y, z): >> # etc. >> >> Is there a way to r

Re: How to access args as a list?

2010-04-03 Thread kj
In kj writes: >In kj writes: >>Suppose I have a function with the following signature: >>def spam(x, y, z): >># etc. >>Is there a way to refer, within the function, to all its arguments >>as a single list? (I.e. I'm looking for Python's

Re: How to access args as a list?

2010-04-03 Thread kj
In kj writes: >Suppose I have a function with the following signature: >def spam(x, y, z): ># etc. >Is there a way to refer, within the function, to all its arguments >as a single list? (I.e. I'm looking for Python's equivalent of >Perl's @_ variable.) &

How to access args as a list?

2010-04-03 Thread kj
Suppose I have a function with the following signature: def spam(x, y, z): # etc. Is there a way to refer, within the function, to all its arguments as a single list? (I.e. I'm looking for Python's equivalent of Perl's @_ variable.) I'm aware of locals(), but I want to preserve the order

  1   2   3   4   >