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

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

2012-08-19 Thread kj
In roy-ca6d77.17031119082...@news.panix.com Roy Smith r...@panix.com writes: In article k0rj38$2gc$1...@reader1.panix.com, kj no.em...@please.post 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

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
of the rationale behind PEP 3130 Thank you! kj -- http://mail.python.org/mailman/listinfo/python-list

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
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
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 steve+comp.lang.pyt...@pearwood.info writes: We know it because it explains the observable facts. So does Monday-night quarterbacking... -- http://mail.python.org/mailman/listinfo/python-list

__delitem__ feature

2010-12-26 Thread kj
that I'm not going insane when inevitably I'm told that there's no bug in dict or list). Interestingly enough, if I replace list with UserList, I see no change in behavior. So maybe I am going insane after all. ~kj P.S. If you uncomment the commented-out line, and comment out the last line

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

2010-12-26 Thread kj
back, all is forgotten! ~kj -- http://mail.python.org/mailman/listinfo/python-list

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

2010-12-26 Thread kj
In xns9e59a27def178duncanbo...@127.0.0.1 Duncan Booth duncan.bo...@invalid.invalid writes: kj no.em...@please.post wrote: Watch this: class neodict(dict): pass ... d = neodict() type(d) class '__main__.neodict' type(d.copy()) type 'dict' Bug? Feature? Genius beyond the grasp

Re: __delitem__ feature

2010-12-26 Thread kj
In mailman.302.1293387041.6505.python-l...@python.org Ian Kelly ian.g.ke...@gmail.com 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

Re: How to pop the interpreter's stack?

2010-12-26 Thread kj
raises 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: How to pop the interpreter's stack?

2010-12-26 Thread kj
In mailman.301.1293383804.6505.python-l...@python.org Ethan Furman et...@stoneleaf.us 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

How can a function find the function that called it?

2010-12-24 Thread kj
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: How can a function find the function that called it?

2010-12-24 Thread kj
In mailman.272.1293215190.6505.python-l...@python.org Daniel Urban urban.d...@gmail.com writes: On Fri, Dec 24, 2010 at 17:24, kj no.em...@please.post wrote: (BTW, I don't understand why inspect doesn't provide something as basic as the *class* that the method belongs to, whenever applicable

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) class '__main__.neodict' type(d.copy()) type 'dict' Bug? Feature? Genius beyond the grasp of schlubs like me? ~kj -- http://mail.python.org/mailman/listinfo/python-list

How to order base classes?

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

Re: How to order base classes?

2010-12-23 Thread kj
. Thanks! ~kj -- http://mail.python.org/mailman/listinfo/python-list

Re: Partition Recursive

2010-12-23 Thread kj
', '.', 'org', '/', 'dev', '/', 'library', '/', 'stdtypes', '.', 'html', '\ ?', 'highlight', '=', 'partition', '#', 'str', '.', 'partition'] ~kj -- http://mail.python.org/mailman/listinfo/python-list

issubclass(dict, Mapping)

2010-12-22 Thread kj
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

Re: How to pop the interpreter's stack?

2010-12-22 Thread kj
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

Re: How to pop the interpreter's stack?

2010-12-22 Thread kj
In 1f47c36d-a509-4d05-ba79-62b4a534b...@j19g2000prh.googlegroups.com Carl Banks pavlovevide...@gmail.com writes: On Dec 22, 8:52=A0am, kj no.em...@please.post wrote: In mailman.65.1292517591.6505.python-l...@python.org Robert Kern rober= t.k...@gmail.com writes: Obfuscating the location

general problem when subclassing a built-in class

2010-12-22 Thread kj
that, one would have little assurance that one's experimentation has truly uncovered all the necessary details; IME, programming-by-guesswork leads to numerous and often nasty bugs. Is there any other way? TIA! ~kj [1] The minimal bit in the question statement is just another way of specifying

Re: issubclass(dict, Mapping)

2010-12-22 Thread kj
In 4d127d5e$0$29997$c3e8da3$54964...@news.astraweb.com Steven D'Aprano steve+comp.lang.pyt...@pearwood.info 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 collections import Mapping issubclass(dict, Mapping

How to pop the interpreter's stack?

2010-12-14 Thread kj
-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
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
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 mailman.278.1288129342.2218.python-l...@python.org Steve Holden st...@holdenweb.com writes: On 10/26/2010 2:44 PM, kj wrote: In mailman.258.1288104186.2218.python-l...@python.org Steve Holden st...@holdenweb.com writes: The answer is probably the same as you will see if you try from

Re: Why flat is better than nested?

2010-10-26 Thread kj
In mailman.241.1288036400.2218.python-l...@python.org Terry Reedy tjre...@udel.edu 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

Re: Why flat is better than nested?

2010-10-26 Thread kj
In mailman.258.1288104186.2218.python-l...@python.org Steve Holden st...@holdenweb.com 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

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 preference for either flat or nested; it all depends

Re: Why flat is better than nested?

2010-10-25 Thread kj
In f8b6c925-ca3b-4be4-8851-6b18c6465...@j18g2000yqd.googlegroups.com rantingrick rantingr...@gmail.com writes: On Oct 25, 5:07=A0am, kj no.em...@please.post wrote: In The Zen of Python, one of the maxims is flat is better than nested? =A0Why? =A0Can anyone give me a concrete example

Re: Why flat is better than nested?

2010-10-25 Thread kj
In mailman.232.1288020268.2218.python-l...@python.org Steve Holden st...@holdenweb.com writes: On 10/25/2010 10:47 AM, rantingrick wrote: On Oct 25, 5:07 am, kj no.em...@please.post wrote: In The Zen of Python, one of the maxims is flat is better than nested? Why? Can anyone give me

How to optimize and monitor garbage collection?

2010-10-24 Thread kj
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
-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 i9o8jc$9p...@lust.ihug.co.nz Lawrence D'Oliveiro l...@geek-central.gen.new_zealand writes: In message i9n4ph$d7...@reader1.panix.com, 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

Re: annoying CL echo in interactive python / ipython

2010-10-20 Thread kj
In mailman.29.1287515736.2218.python-l...@python.org Jed Smith j...@jedsmith.org writes: On Tue, Oct 19, 2010 at 2:35 PM, kj no.em...@please.post wrote: In mailman.24.1287510296.2218.python-l...@python.org Jed Smith j...@jed= smith.org writes: On Tue, Oct 19, 2010 at 1:37 PM, kj no.em

python shell silently ignores termios.tcsetattr()

2010-10-20 Thread kj
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

annoying CL echo in interactive python / ipython

2010-10-19 Thread kj
(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: annoying CL echo in interactive python / ipython

2010-10-19 Thread kj
In mailman.24.1287510296.2218.python-l...@python.org Jed Smith j...@jedsmith.org writes: On Tue, Oct 19, 2010 at 1:37 PM, kj no.em...@please.post 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

docstring that use globals?

2010-10-16 Thread kj
are still fluid. I'm trying to minimize the effort required to keep the docstrings current, while still retaining the freedom to adjust the values of the globals. Also, FWIW, most of these globals are merely default values that can be overridden at runtime.) TIA! ~kj -- http://mail.python.org

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

Re: docstring that use globals?

2010-10-16 Thread kj
In i9clfa$mk...@reader1.panix.com kj no.em...@please.post 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

dynamic loading error (Symbol not found)

2010-10-16 Thread kj
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.) Can anyone suggest a way to fix this error? Thanks! ~kj -- http://mail.python.org/mailman/listinfo/python-list

Re: dynamic loading error (Symbol not found)

2010-10-16 Thread kj
In mailman.1782.1287266502.29448.python-l...@python.org Emile van Sebille em...@fenx.com 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 _engClose

Re: docstring that use globals?

2010-10-16 Thread kj
In 8hujfsfb9...@mid.individual.net Gregory Ewing greg.ew...@canterbury.ac.nz 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

Re: hashkey/digest for a complex object

2010-10-10 Thread kj
this exchange. ~kj -- http://mail.python.org/mailman/listinfo/python-list

Re: hashkey/digest for a complex object

2010-10-10 Thread kj
a *lot* of time, 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-09 Thread kj
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
In 4cae667c$0$29993$c3e8da3$54964...@news.astraweb.com Steven D'Aprano st...@remove-this-cybersource.com.au 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

Re: frozendict (v0.1)

2010-10-08 Thread kj
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 i8loa2$3o...@reader1.panix.com kj no.em...@please.post 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
In mailman.1461.1286539843.29448.python-l...@python.org Jonas H. jo...@lophus.org 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

Re: frozendict (v0.1)

2010-10-08 Thread kj
that would imply a consistent iteration order.) Thanks again! ~kj -- http://mail.python.org/mailman/listinfo/python-list

Re: hashkey/digest for a complex object

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

Re: hashkey/digest for a complex object

2010-10-07 Thread kj
In m2fwwjazs2@web.de de...@web.de (Diez B. Roggisch) writes: kj no.em...@please.post 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

Re: hashkey/digest for a complex object

2010-10-07 Thread kj
, ~kj -- http://mail.python.org/mailman/listinfo/python-list

how to test for atomicity/mutability/hashability?

2010-10-07 Thread kj
for mutability. Is there one? Thanks! ~kj -- http://mail.python.org/mailman/listinfo/python-list

frozendict (v0.1)

2010-10-07 Thread kj
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

Re: frozendict (v0.1)

2010-10-07 Thread kj
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): return hash(frozenset(self.items())) ...which is a lot nicer! Thanks! ~kj -- http

hashkey/digest for a complex object

2010-10-06 Thread kj
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
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
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
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 stdin, 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 partial sums? TIA! kj -- http

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 it

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

2010-08-28 Thread kj
In mailman.123.1282955703.29448.python-l...@python.org Benjamin Kaplan benjamin.kap...@case.edu writes: On Fri, Aug 27, 2010 at 8:01 PM, kj no.em...@please.post 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

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 mailman.2125.1281849995.1673.python-l...@python.org Chris Rebert c...@rebertia.com writes: On Sat, Aug 14, 2010 at 5:13 PM, kj no.em...@please.post wrote: In af7fdb85-8c87-434e-94f3-18d8729bf...@l25g2000prn.googlegroups.com Ra= ymond Hettinger pyt...@rcn.com writes: On Aug 12, 1:37=3DA0pm

Re: shelf-like list?

2010-08-15 Thread kj
In i486al$b...@online.de Martin v. Loewis mar...@v.loewis.de 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-14 Thread kj
In af7fdb85-8c87-434e-94f3-18d8729bf...@l25g2000prn.googlegroups.com Raymond Hettinger pyt...@rcn.com writes: On Aug 12, 1:37=A0pm, Thomas Jollans tho...@jollybox.de wrote: On Tuesday 10 August 2010, it occurred to kj to exclaim: I'm looking for a module that implements persistent lists

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

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 a

Re: Unicode error

2010-08-07 Thread kj
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 pan.2010.07.23.21.46.03.547...@nowhere.com Nobody nob...@nowhere.com 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

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

Re: XML parsing: SAX/expat yield

2010-08-04 Thread kj
In i3c7lc$e6v$0...@news.t-online.com 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)

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

2010-07-16 Thread kj
In mailman.778.1279213534.1673.python-l...@python.org Thomas Jollans tho...@jollans.com writes: On 07/15/2010 06:41 PM, kj wrote: In mailman.733.1279124991.1673.python-l...@python.org Thomas Jollans tho...@jollans.com writes: http://docs.python.org/library/ctypes.html#fundamental-data

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

2010-07-15 Thread kj
In mailman.733.1279124991.1673.python-l...@python.org Thomas Jollans tho...@jollans.com 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

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

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

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

2010-07-02 Thread kj
Please disregard my ineptly posed question. ~K In i0l9f3$7d...@reader1.panix.com kj no.em...@please.post 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

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

Re: tallying occurrences in list

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

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

Re: Limitation of os.walk

2010-05-12 Thread kj
In mailman.86.1273631889.32709.python-l...@python.org 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

Re: Limitation of os.walk

2010-05-12 Thread kj
In mailman.82.1273630064.32709.python-l...@python.org Terry Reedy tjre...@udel.edu 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

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.

Re: Limitation of os.walk

2010-05-11 Thread kj
In mailman.75.1273614838.32709.python-l...@python.org Tim Chase python.l...@tim.thechases.com 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 --

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

Re: Inheritable computed class attributes?

2010-04-30 Thread kj
In 4bdb4e4...@dnews.tpgi.com.au Lie Ryan lie.1...@gmail.com 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 = '.' ... Ham.Y;

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

Re: How to access args as a list?

2010-04-05 Thread kj
In 4bb802f7$0$8827$c3e8...@news.astraweb.com Steven D'Aprano st...@remove-this-cybersource.com.au 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 refer, within the function

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

Re: How to access args as a list?

2010-04-03 Thread kj
In hp8h73$k1...@reader1.panix.com kj no.em...@please.post 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

Re: How to access args as a list?

2010-04-03 Thread kj
In hp8kc9$dg...@reader1.panix.com kj no.em...@please.post writes: In hp8h73$k1...@reader1.panix.com kj no.em...@please.post 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

  1   2   3   4   >