Re: How can module determine its own path?

2009-10-30 Thread kj
In <7e456639-9dbb-41ba-ae36-042a034fa...@y32g2000prd.googlegroups.com> AK Eric writes: >> > How can a module determine the path of the file that defines it? >> > (Note that this is, in the general case, different from sys.argv[0].) >> >> __file__ >Also: >import inspect >print inspect.getsourc

import bug

2009-10-31 Thread kj
I'm running into an ugly bug, which, IMHO, is really a bug in the design of Python's module import scheme. Consider the following directory structure: ham |-- __init__.py |-- re.py `-- spam.py ...with the following very simple files: % head ham/*.py ==> ham/__init__.py <== ==> ham/re.py <==

Re: import bug

2009-10-31 Thread kj
In <4aec591e$0$7629$9b4e6...@newsspool1.arcor-online.net> Stefan Behnel writes: >kj, 31.10.2009 16:12: >> My sin appears to be having the (empty) file ham/re.py. So Python >> is confusing it with the re module of the standard library, and >> using it when the inspec

How to test urllib|urllib2-using code?

2009-11-04 Thread kj
I want to write some tests for code that uses both urllib and urllib2. I would like to be able to run these tests locally. Are there modules to facilitate the writing of such tests (e.g. for setting up a mock web server locally, etc.)? BTW, in the Perl world, one very easy way to learn how to

Re: Most efficient way to "pre-grow" a list?

2009-11-07 Thread kj
In Luis Alberto Zarrabeitia Gomez writes: >Quoting Andre Engels : >> On Sat, Nov 7, 2009 at 8:25 PM, Luis Alberto Zarrabeitia Gomez >> wrote: >> > >> > Ok, he has a dict. >> > >> > Now what? He needs a non-sparse array. >> >> Let d be your dict. >> >> Call the zeroeth place in your array d

How to specify Python version in script?

2009-11-11 Thread kj
I have a script that must be run with Python 2.6.x. If one tries to run it with, say, 2.5.x, *eventually* it runs into problems and crashes. (The failure is quicker if one attempts to run it with Python 3.x.) Is there some way to specify at the very beginning of the script the acceptable ran

Re: How to specify Python version in script?

2009-11-11 Thread kj
In Benjamin Kaplan writes: >On Wed, Nov 11, 2009 at 12:16 PM, kj wrote: >> >> >> >> >> I have a script that must be run with Python 2.6.x. =A0If one tries >> to run it with, say, 2.5.x, *eventually* it runs into problems and >> crashes. =A0(The

Re: How can a module know the module that imported it?

2009-11-11 Thread kj
In a...@pythoncraft.com (Aahz) writes: >In article , kj wrote: >> >>The subject line says it all. >You are probably trying to remove a screw with a hammer Worse: I'm trying to write Perl using Python! >-- why don't you >tell us what you really want to do

Python & Go

2009-11-11 Thread kj
I'm just learning about Google's latest: the GO (Go?) language. (e.g. http://golang.org or http://www.youtube.com/watch?v=rKnDgT73v8s). There are some distinctly Pythonoid features to the syntax, such as "import this_or_that", the absence of parentheses at the top of flow control constructs, and

How can a module know the module that imported it?

2009-11-12 Thread kj
The subject line says it all. Thanks! kynn -- http://mail.python.org/mailman/listinfo/python-list

Re: Python & Go

2009-11-12 Thread kj
When reading such code, to follow any method call one must check in at least two places: the base class and the subclass. The deeper the inheritance chain, the more places one must check. For every method call. Yeecch. Good riddance. kj -- http://mail.python.org/mailman/listinfo/python-list

A "terminators' club" for clp

2009-11-13 Thread kj
This is "meta-question" about comp.lang.python. I apologize in advance if it has been already discussed. Also, I don't know enough about the underlying mechanics of comp.lang.python, so this may be *totally unfeasible*, but how about giving a few bona fide *and frequent* clp posters the ability

Re: Python & Go

2009-11-14 Thread kj
In <7xpr7lixnn@ruckus.brouhaha.com> Paul Rubin writes: >It seems a little weird to me that they (Google) are concerned with >the speed of the compiler, indicating that they plan to write enormous >programs in the language. Fast compilation also means that Go ca

Re: Python & Go

2009-11-14 Thread kj
In <129a67e4-328c-42b9-9bf3-152f1b76f...@k19g2000yqc.googlegroups.com> Michele Simionato writes: >It does not look so primitive to me, compared to commonly used >languages. >I am pretty sure that they are "missing a lot of the latest ideas" on >purpose. If they want to succeed and make Go a popu

Re: How to specify Python version in script?

2009-11-14 Thread kj
In <77b812a9-d82c-4aaa-8037-ec30366fc...@h34g2000yqm.googlegroups.com> Yinon Ehrlich writes: >> Is there some way to specify at the very beginning of the script >> the acceptable range of Python versions? >sys.hexversion, >see http://mail.python.org/pipermail/python-list/2009-June/185939.html

The ol' [[]] * 500 bug...

2009-11-16 Thread kj
...just bit me in the "fuzzy posterior". The best I can come up with is the hideous lol = [[] for _ in xrange(500)] Is there something better? What did one do before comprehensions were available? I suppose in that case one would have to go all the way with lol = [None] * 500 for i i

Re: The ol' [[]] * 500 bug...

2009-11-16 Thread kj
In <6e20a31b-2218-49c5-a32c-5f0147db3...@k19g2000yqc.googlegroups.com> Jon Clements writes: lol =3D map(lambda L: [], xrange(5)) [id(i) for i in lol] >[167614956, 167605004, 167738060, 167737996, 167613036] Oh yeah, map! I'd forgotten all about it. Thanks! kynn -- http://mail.pyth

Re: A "terminators' club" for clp

2009-11-16 Thread kj
In <7x3a4i56u7@ruckus.brouhaha.com> Paul Rubin <http://phr...@nospam.invalid> writes: >kj writes: >> frequent* clp posters the ability to *easily* delete spam from the >> comp.lang.python server? >Um, this is usenet; there is no comp.lang.python serve

How to set default encoding for print?

2010-01-31 Thread kj
It gets tedious to have to append .encode('utf-8') to all my unicode strings when I print them, as in: print foobar.encode('utf-8') I want to tell python to apply this encoding automatically to anything argument passed to print. How can I do this? TIA! K PS: BTW, sys.setdefaultencoding

How to pass Chinese characters as command-line arguments?

2010-01-31 Thread kj
I want to pass Chinese characters as command-line arguments to a Python script. My terminal has no problem displaying these characters, and passing them to the script, but I can't get Python to understand them properly. E.g. if I pass one such character to the simple script import sys print sy

Re: How to set default encoding for print?

2010-01-31 Thread kj
In <7slndhfno...@mid.uni-berlin.de> "Diez B. Roggisch" writes: >Am 31.01.10 16:38, schrieb kj: >> It gets tedious to have to append .encode('utf-8') to all my unicode >> strings when I print them, as in: >> >> print foobar.encode('

Re: How to pass Chinese characters as command-line arguments?

2010-01-31 Thread kj
In <7slr5ife6...@mid.uni-berlin.de> "Diez B. Roggisch" writes: >Am 31.01.10 16:52, schrieb kj: >> I want to pass Chinese characters as command-line arguments to a >> Python script. My terminal has no problem displaying these >> characters, and passing them

How to guard against bugs like this one?

2010-02-01 Thread kj
I just spent about 1-1/2 hours tracking down a bug. An innocuous little script, let's call it buggy.py, only 10 lines long, and whose output should have been, at most two lines, was quickly dumping tens of megabytes of non-printable characters to my screen (aka gobbledygook), and in the process

Re: How to guard against bugs like this one?

2010-02-02 Thread kj
Let me preface everything by thanking you and all those who replied for their comments. I have only one follow-up question (or rather, set of related questions) that I'm very keen about, plus a bit of a vent at the end. In Steven D'Aprano writes: >As for fixing it, unfortunately it's not qu

Re: How to guard against bugs like this one?

2010-02-02 Thread kj
In Terry Reedy writes: >On 2/2/2010 9:13 AM, kj wrote: >>> As for fixing it, unfortunately it's not quite so simple to fix without >>> breaking backwards-compatibility. The opportunity to do so for Python 3.0 >>> was missed. >> >> This last p

Re: How to guard against bugs like this one?

2010-02-02 Thread kj
(For reasons I don't understand Stephen Hansen's posts don't show in my news server. I became aware of his reply from a passing reference in one of Terry Reedy's post. Then I found Hansen's post online, and then an earlier one, and pasted the relevant portion below.) > First, I don't shadow

Re: How to guard against bugs like this one?

2010-02-02 Thread kj
In Terry Reedy writes: >On 2/2/2010 2:43 PM, kj wrote: >> In Terry >> Reedy writes: >> >>> On 2/2/2010 9:13 AM, kj wrote: >> >>>>> As for fixing it, unfortunately it's not quite so simple to fix without >>>>> br

test -- please ignore

2010-02-03 Thread kj
(my replies in a different comp.lang.python thread are getting rejected by the server; i have no problem posting to alt.test; and i'm trying to toubleshoot the problem further.) -- http://mail.python.org/mailman/listinfo/python-list

Re: How to guard against bugs like this one?

2010-02-03 Thread kj
carried away by my annoyance with the Python import scheme. I'm sorry about it. Even though I don't think I can put to practice all of your advice, I can still learn a good deal from it. Cheers, ~kj Steve Holden writes: >kj wrote: >> >>> First, I don't shadow buil

Re: How to guard against bugs like this one?

2010-02-03 Thread kj
In kj writes: >Steve, I apologize for the snarkiness of my previous reply to you. >After all, I started the thread by asking the forum for advice on >how to avoid a certain kind of bugs, you were among those who gave >me advice. So nothing other than thanking you for it was in or

Re: test -- please ignore

2010-02-04 Thread kj
In <87wryumvff@benfinney.id.au> Ben Finney writes: >kj writes: >> (my replies in a different comp.lang.python thread are getting >> rejected by the server; i have no problem posting to alt.test; and >> i'm trying to toubleshoot the problem further.) >Th

Need debugging knowhow for my creeping Unicodephobia

2010-02-10 Thread kj
Some people have mathphobia. I'm developing a wicked case of Unicodephobia. I have read a *ton* of stuff on Unicode. It doesn't even seem all that hard. Or so I think. Then I start writing code, and WHAM: UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 0: ordinal not i

Re: Need debugging knowhow for my creeping Unicodephobia

2010-02-10 Thread kj
In <402ac982-0750-4977-adb2-602b19149...@m24g2000prn.googlegroups.com> Jonathan Gardner writes: >On Feb 10, 11:09=A0am, kj wrote: >> FWIW, I'm using Python 2.6. =A0The example above happens to come from >> a script that extracts data from HTML files, which are all in

Re: Need debugging knowhow for my creeping Unicodephobia

2010-02-10 Thread kj
In Duncan Booth writes: >kj wrote: >> But to ground >> the problem a bit I'll say that the exception above happens during >> the execution of a statement of the form: >> >> x = '%s %s' % (y, z) >> >> Also, I found that, with the

Re: Need debugging knowhow for my creeping Unicodephobia

2010-02-11 Thread kj
In mk writes: >To make matters more complicated, str.encode() internally DECODES from >string into unicode: > >>> nu >'\xc4\x84' > >>> > >>> type(nu) > > >>> nu.encode() >Traceback (most recent call last): > File "", line 1, in >UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in

What's the word on using """ to comment-out?

2010-02-24 Thread kj
I think I remember, early in my learning of Python, coming across the commandment "THOU SHALT NOT USE TRIPLE-QUOTES TO COMMENT-OUT LINES OF CODE", or something to that effect. But now I can't find it! Is my memory playing me a trick? After all, from what I've seen since then, the practice of

How to monitor memory usage within Python? (Linux)

2010-02-24 Thread kj
Is there some standard module for getting info about the process's memory usage, in a Linux/Unix system? (I want to avoid hacks that involve, e.g., scraping ps's output.) Thanks! ~K -- http://mail.python.org/mailman/listinfo/python-list

Anything like "Effective Java" for Python?

2010-03-10 Thread kj
Subject line pretty much says it all: is there a book like "Effective Java" for Python. I.e. a book that assumes that readers are experienced programmers that already know the basics of the language, and want to focus on more advanced programming issues? ~K -- http://mail.python.org/mailman/l

Re: Anything like "Effective Java" for Python?

2010-03-11 Thread kj
In Chris Withers writes: >kj wrote: >> >> >> Subject line pretty much says it all: is there a book like "Effective >> Java" >oxymoronic, no? >Sorry, couldn't resist ;-) I hear you, but still: read "Effective Java" some day; it

How to automate accessor definition?

2010-03-20 Thread kj
I need to create a class solely for the purpose of encapsulating a large number of disparate data items. At the moment I have no plans for any methods for this class other than the bazillion accessors required to access these various instance variables. (In case it matters, this class is mea

Re: How to automate accessor definition?

2010-03-21 Thread kj
In <639908184290880449.447600deets-nospam.web...@news.hansenet.de> Diez B. Roggisch writes: >You don't. Python is not Java. So just use instance attributes, and if >you need bhavior when accessing an attribute, introduce a property. Just accessing attributes looks a bit dangerous to me, due t

Re: How to automate accessor definition?

2010-03-21 Thread kj
In Chris Rebert writes: >On Sat, Mar 20, 2010 at 3:15 PM, kj wrote: >> I need to create a class solely for the purpose of encapsulating >> a large number of disparate data items. =C2=A0At the moment I have no >> plans for any methods for this class other than the b

Re: How to automate accessor definition?

2010-03-21 Thread kj
In <4ba58503$0$27838$c3e8...@news.astraweb.com> Steven D'Aprano writes: >On Sat, 20 Mar 2010 22:15:54 +, kj wrote: >> I need to create a class solely for the purpose of encapsulating a large >> number of disparate data items. >There's a built-in for th

Re: How to automate accessor definition?

2010-03-21 Thread kj
In <4ba66311$0$27838$c3e8...@news.astraweb.com> Steven D'Aprano writes: >Then, in your __init__ method, to initialise an attribute use: >self.__dict__['attr'] = value >to bypass the setattr. Ah, that's the trick! Thanks! ~K -- http://mail.python.org/mailman/listinfo/python-list

Re: How to automate accessor definition?

2010-03-22 Thread kj
In Dennis Lee Bieber writes: >On Sun, 21 Mar 2010 16:57:40 + (UTC), kj >declaimed the following in gmane.comp.python.general: >> Regarding properties, is there a built-in way to memoize them? For >> example, suppose that the value of a property is obtained by parsing &g

short-circuiting any/all ?

2010-03-22 Thread kj
I have a list of items L, and a test function is_invalid that checks the validity of each item. To check that there are no invalid items in L, I could check the value of any(map(is_invalid, L)). But this approach is suboptimal in the sense that, no matter what L is, is_invalid will be executed

Re: short-circuiting any/all ?

2010-03-22 Thread kj
In <291d82b7-b13b-4f49-901c-8194f3e07...@e7g2000yqf.googlegroups.com> nn writes: >If you are in Python 3 "any(map(is_invalid, L))" should short circuit. >If you are in Python 2 use "from itertools import imap; >any(imap(is_invalid, L))" Thanks! I'm glad to know that one can get the short circu

Re: How to automate accessor definition?

2010-03-22 Thread kj
In <4ba79040$0$22397$426a7...@news.free.fr> Bruno Desthuilliers writes: >kj a écrit : >> PS: BTW, this is not the first time that attempting to set an >> attribute (in a class written by me even) blows up on me. It's >> situations like these that rattle

Re: short-circuiting any/all ?

2010-03-22 Thread kj
In Tim Golden writes: >On 22/03/2010 18:30, kj wrote: >> Thanks! I'm glad to know that one can get the short circuiting >> using a map-type idiom. (I prefer map over comprehensions when I >> don't need to define a function just for the purpose of passing it >

Re: short-circuiting any/all ?

2010-03-22 Thread kj
In Steven D'Aprano writes: >On Mon, 22 Mar 2010 22:19:57 +, kj wrote: >In any case, the once-off cost of creating or importing a function is >usually quite cheap. As usual, the best advise is not to worry about >optimization until you have profiled the code and

sum for sequences?

2010-03-24 Thread kj
Is there a sequence-oriented equivalent to the sum built-in? E.g.: seq_sum(((1, 2), (5, 6))) --> (1, 2) + (5, 6) --> (1, 2, 5, 6) ? (By "sequence" I'm referring primarily to lists and tuples, and excluding strings, since for these there is ''.join()). TIA! ~K -- http://mail.python.org/ma

What's the matter with docs.python.org?

2010-03-24 Thread kj
In the last couple of weeks, docs.python.org has been down repeatedly (like right now). Has anyone else noticed this? ~K -- http://mail.python.org/mailman/listinfo/python-list

Re: What's the matter with docs.python.org?

2010-03-24 Thread kj
In Philip Semanchuk writes: >On Mar 24, 2010, at 12:05 PM, kj wrote: >> In the last couple of weeks, docs.python.org has been down repeatedly >> (like right now). Has anyone else noticed this? >http://downforeveryoneorjustme.com/docs.python.org Very handy. Th

Classes as namespaces?

2010-03-26 Thread kj
What's the word on using "classes as namespaces"? E.g. class _cfg(object): spam = 1 jambon = 3 huevos = 2 breakfast = (_cfg.spam, _cfg.jambon, _cfg.huevos) Granted, this is not the "intended use" for classes, and therefore could be viewed as a misuse ("that's what dictionaries a

Re: Classes as namespaces?

2010-03-26 Thread kj
Thanks for all your comments. I see that modules are arguably Python's standard way for implementing namespaces. I guess I tend to avoid modules primarily because of lingering mental trauma over incidents of insane/bizarro import bugs in the past. (It's not rational, I know; it's like when on

C-style static variables in Python?

2010-04-01 Thread kj
When coding C I have often found static local variables useful for doing once-only run-time initializations. For example: int foo(int x, int y, int z) { static int first_time = TRUE; static Mongo *mongo; if (first_time) { mongo = heavy_lifting_at_runtime(); first_time = FALSE;

Re: C-style static variables in Python?

2010-04-02 Thread kj
In Steve Holden writes: >But the real problem is that the OP is insisting on using purely >procedural Python when the problem is screaming for an object-oriented >answer. My initial reaction to this comment was something like "What? switch from procedural to OO just to be able to do some one-t

Re: (a==b) ? 'Yes' : 'No'

2010-04-02 Thread kj
In Steve Holden writes: >John Nagle wrote: >> Chris Rebert wrote: >>> On Tue, Mar 30, 2010 at 8:40 AM, gentlestone >>> wrote: Hi, how can I write the popular C/JAVA syntax in Python? Java example: return (a==b) ? 'Yes' : 'No' My first idea is: return ('

Re: C-style static variables in Python?

2010-04-02 Thread kj
In Duncan Booth writes: >class Spam(object): > mongo = None > def __call__(self, x, y, z): > if self.mongo is None: > self.mongo = heavy_lifting_at_runtime() > return frobnicate(x, y, z, self.mongo) >spam = Spam() >ham = spam(1, 2, 3) I really like this. Thanks. >T

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

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.) &

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

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

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

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

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

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

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

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

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

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

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

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

__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

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

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

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

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

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

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 = '.' >...

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

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

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

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

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

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

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

<    1   2   3   4   >