How to get insight in the relations between tracebacks of exceptions in an exception-chain

2024-04-04 Thread Klaas van Schelven via Python-list
ceback` or other tools to arrive at the correct answer). This is the most trivial case that illustrates the problem; real cases have many more stack frames and thus less clearly illustrate the problem but more clearly illustrate the need for (potentially automated) clarification of what's h

Re: platform system may be Windows or Microsoft since Vista

2007-08-31 Thread Klaas
On Aug 31, 9:47 am, [EMAIL PROTECTED] wrote: > Let's suppose you get Python for Vista Windows today > fromhttp://www.python.org/download/. > > Should you then conclude that the tests: > > if platform.system() in ('Windows', 'Microsoft'): > if not (platform.system() in ('Windows', 'Microsoft')): G

Re: Closures / Blocks in Python

2007-07-25 Thread Klaas
On Jul 24, 7:58 am, treble54 <[EMAIL PROTECTED]> wrote: > Does anyone know a way to use closures or blocks in python like those > used in Ruby? Particularly those used in the { } braces. Inner functions allow you to define closures and (named) blocks anywhere). Anonymous blocks must consist of a

Re: class C: vs class C(object):

2007-07-23 Thread Klaas
On Jul 20, 5:47 am, Hrvoje Niksic <[EMAIL PROTECTED]> wrote: > "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes: > > In particular, old-style classes are noticeably faster than > > new-style classes for some things (I think it was attribute lookup > > that surprised me recently, possibly related to t

Re: The ** operator ambiguous?

2007-07-16 Thread Klaas
On Jul 16, 10:40 am, Robert Dailey <[EMAIL PROTECTED]> wrote: > I noticed that the ** operator is used as the power operator, however > I've seen it used when passing variables into a function. For example, > I was researching a way to combine dictionaries. I found that if you > do this: > > a = {"

Re: Where does str class represent its data?

2007-07-13 Thread Klaas
On Jul 11, 4:37 pm, Miles <[EMAIL PROTECTED]> wrote: > Since strings are immutable, you need to override the __new__ method. > Seehttp://www.python.org/download/releases/2.2.3/descrintro/#__new__ In case this isn't clear, here is how to do it: In [1]: class MyString(str): ...: def __new__

Re: Shed Skin Python-to-C++ Compiler 0.0.21, Help needed

2007-07-05 Thread Klaas
On Jun 29, 3:48 am, "Mark Dufour" <[EMAIL PROTECTED]> wrote: > I have just released version 0.0.22 of Shed Skin, an experimental > Python-to-C++ compiler. Among other things, it has the exciting new > feature of being able to generate (simple, for now) extension modules, > so it's much easier to c

Re: Using a switch-like if/else construct versus a dictionary?

2007-06-25 Thread Klaas
On Jun 19, 12:40 pm, asincero <[EMAIL PROTECTED]> wrote: > Which is better: using an if/else construct to simulate a C switch or > use a dictionary? Example: Whichever results in the clearest code that meets the performance requirements. FWIW, if you define the dictionary beforehand, the dict so

Re: contextlib.closing annoyance

2007-06-25 Thread Klaas
On Jun 22, 4:54 pm, Paul Rubin wrote: > it looks like contextlib.closing fails to be idempotent, > i.e. wrapping closing() around another closing() doesn't work. > This is annoying because the idea of closing() is to let you > use legacy file-like objects as targets of t

Re: Pyrex problem with cdef'd attribute

2007-06-08 Thread Klaas
On Jun 8, 6:00 am, [EMAIL PROTECTED] wrote: > I'm using Pyrex 0.9.5.1a. I have this simple Pyrex module: You might get more help on the pyrex list. > cdef class Foo: > cdef public char attr > > def __init__(self): > self.attr = 0 > > class Bar(Foo): >

Re: Running a process every N days

2007-06-07 Thread Klaas
On Jun 7, 3:27 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > What's the best way to run either an entire python process or a python > thread every N days. I'm running Python 2.4.3 on Fedora Core 5 Linux. > My code consists of a test and measurement system that runs 24/7 in a > factory settin

Re: Python rocks

2007-06-05 Thread Klaas
On Jun 3, 8:56 am, [EMAIL PROTECTED] (Alex Martelli) wrote: > Allowing a trailing ! in method names has no such cost, because in no > language I know is ! used as a "postfix unary operator"; the gain in the > convention "mutators end with !" is not huge, but substantial. So, the > tradeoffs are d

Re: Who uses Python?

2007-06-05 Thread Klaas
On Jun 4, 12:37 pm, walterbyrd <[EMAIL PROTECTED]> wrote: > I mean other than sysadmins, programmers, and web-site developers? > > I have heard of some DBAs who use a lot of python. > > I suppose some scientists. I think python is used in bioinformatics. I > think some math and physics people use p

Re: Python memory handling

2007-05-31 Thread Klaas
On May 31, 11:00 am, Thorsten Kampe <[EMAIL PROTECTED]> wrote: > If it's swapped to disk than this is a big concern. If your Python app > allocates 600 MB of RAM and does not use 550 MB after one minute and > this unused memory gets into the page file then the Operating System > has to allocate an

Re: File I/O

2007-05-09 Thread Klaas
On May 9, 2:43 pm, HMS Surprise <[EMAIL PROTECTED]> wrote: > > [lst.append(list(line.split())) for line in file] > > Thanks, this is the direction I wanted to go, BUT I must use v2.2 so > the line above gives me the error: > > AttributeError: __getitem__ > > But the write format will be helpful. (

Re: Towards faster Python implementations - theory

2007-05-09 Thread Klaas
On May 9, 10:02 am, John Nagle <[EMAIL PROTECTED]> wrote: > One option might be a class "simpleobject", from which other classes > can inherit. ("object" would become a subclass of "simpleobject"). > "simpleobject" classes would have the following restrictions: > > - New fields and f

Re: How safe is a set of floats?

2007-05-08 Thread Klaas
On May 4, 10:15 am, Paul McGuire <[EMAIL PROTECTED]> wrote: > Just to beat this into the ground, "test for equality" appears to be > implemented as "test for equality of hashes". So if you want to > implement a class for the purposes of set membership, you must > implement a suitable __hash__ met

Re: Python regular expressions just ain't PCRE

2007-05-08 Thread Klaas
On May 5, 6:57 pm, Wiseman <[EMAIL PROTECTED]> wrote: > > There's also the YAGNI factor; most folk would restrict using regular > > expressions to simple grep-like functionality and data validation -- > > e.g. re.match("[A-Z][A-Z]?[0-9]{6}[0-9A]$", idno). The few who want to > > recognise yet anot

Re: No speedup on multi-processor machine?

2007-04-23 Thread Klaas
On Apr 21, 5:14 pm, Fuzzyman <[EMAIL PROTECTED]> wrote: > Additionally, extending IronPython from C# is orders of magnitude > easier than extending CPython from C. Given the existence of Pyrex, that statement is pretty difficult to substantiate. -Mike -- http://mail.python.org/mailman/listinfo

Re: Select weirdness

2007-04-23 Thread Klaas
On Apr 23, 9:51 am, Ron Garret <[EMAIL PROTECTED]> wrote: > In article <[EMAIL PROTECTED]>, > Jean-Paul Calderone <[EMAIL PROTECTED]> wrote: > > > Twisted does this out of the box, for what it's worth. > > Thanks. I will look at that. There is also asyncore in the standard library, which is a ve

Re: Really badly structured Python Books.

2007-04-16 Thread Klaas
On Apr 14, 11:37 am, "Andre P.S Duarte" <[EMAIL PROTECTED]> wrote: > I started reading the beginning Python book. It is intended for people > who are starting out in the Python world. But it is really > complicated, because he tries to explain, then after a bad explanation > he puts out a bad examp

Re: Queue enhancement suggestion

2007-04-16 Thread Klaas
On Apr 15, 11:12 pm, Paul Rubin wrote: > I'd like to suggest adding a new operation > >Queue.finish() > > This puts a special sentinel object on the queue. The sentinel > travels through the queue like any other object, however, when > q.get() encounters the sentinel

Re: itertools, functools, file enhancement ideas

2007-04-10 Thread Klaas
On Apr 8, 9:34 am, Paul Rubin wrote: > [EMAIL PROTECTED] writes: > > > a) def flip(f): return lambda x,y: f(y,x) > > Curious resemblance to: > >itemgetter(1,0) > > Not sure I understand that. I think he read it as lambda (x, y): (y, x) More interesting would

Re: Problems with os.spawnv

2007-04-06 Thread Klaas
On Apr 5, 3:25 pm, "Henrik Lied" <[EMAIL PROTECTED]> wrote: > > > I'd still love to get a working example of my problem using the > > > Subprocess module. :-) > > > The same thing: > > p = subprocess.Popen(["mencoder", "/users/...", "-ofps", ...]) > > That example looked great at first, but on a c

Re: Why NOT only one class per file?

2007-04-04 Thread Klaas
On Apr 4, 2:52 pm, Thomas Krüger <[EMAIL PROTECTED]> wrote: > > At first: if he really like it he can place every class in a single > file. But there are some reasons why Python "allows" you to place many > classes in one file: > > - It's (a little bit) faster, no additional file system lookup is n

Re: with timeout(...):

2007-03-27 Thread Klaas
On Mar 27, 3:28 pm, Paul Rubin wrote: > Nick Craig-Wood <[EMAIL PROTECTED]> writes: > > It could be made to work I'm sure by getting the interpreter to check > > for timeouts every few hundred bytecodes (like it does for thread > > switching). > > Is there some reason not

Re: with timeout(...):

2007-03-26 Thread Klaas
On Mar 26, 3:30 am, Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > Did anyone write a contextmanager implementing a timeout for > python2.5? > > I'd love to be able to write something like > > with timeout(5.0) as exceeded: > some_long_running_stuff() > if exceeded: > print "O

Re: threading and iterator crashing interpreter

2007-03-12 Thread Klaas
On Mar 12, 1:10 pm, "Rhamphoryncus" <[EMAIL PROTECTED]> wrote: > http://sourceforge.net/tracker/index.php?func=detail&aid=1579370&grou... > > That refers to a generator crash. You are using generators, but also > getting a weird dict error. Maybe related, maybe not. > > I'll figure out if I've go

Re: Pep 3105: the end of print?

2007-02-16 Thread Klaas
On Feb 16, 2:31 pm, Sam <[EMAIL PROTECTED]> wrote: >pass > except (ImportError, SyntaxError): ># python 3.0 >print2 = print > SyntaxError: invalid syntax > > Any and all aliasing must happen in compat26.py. My suggested solution is > this: Good catch. Point is that it is not impossib

Re: Pep 3105: the end of print?

2007-02-16 Thread Klaas
On Feb 16, 6:01 am, "Edward K Ream" <[EMAIL PROTECTED]> wrote: > That's the proof. Can you find a flaw in it? Casting this in terms of theorem proving only obfuscates the discussion. Here is how to maintain a single codebase for this feature: 1. Convert all your print statements to 3.0 print f

Re: Help with Optimization of Python software: real-time audio controller

2007-02-12 Thread Klaas
On Feb 11, 6:40 pm, [EMAIL PROTECTED] wrote: > Currently, I have all of the above "working", although I'm running > into some serious timing issues. When I run the program, I get > irregular timing for my metronome (if it sounds at all), as well as > irregular timing in writing to the external dev

Re: huge amounts of pure Python code broken by Python 2.5?

2007-02-12 Thread Klaas
On Feb 10, 5:59 am, Brian Blais <[EMAIL PROTECTED]> wrote: > Klaas wrote: > > I have converted our 100 kloc from 2.4 to 2.5. It was relatively > > painless, and 2.5 has features we couldn't live without. > > Just out of curiosity, what features in 2.5 can you not

Re: huge amounts of pure Python code broken by Python 2.5?

2007-02-09 Thread Klaas
On Feb 8, 6:37 pm, "kernel1983" <[EMAIL PROTECTED]> wrote: > On Feb 9, 10:29 am, "Klaas" <[EMAIL PROTECTED]> wrote: > > The changes listed dont' seem particularly huge considering the size, > > complexity, and boundary-pushingness of Twiste

Re: huge amounts of pure Python code broken by Python 2.5?

2007-02-08 Thread Klaas
On Feb 6, 11:07 am, Jean-Paul Calderone <[EMAIL PROTECTED]> wrote: > On Tue, 06 Feb 2007 08:40:40 -0700, Steven Bethard <[EMAIL PROTECTED]> wrote: > >Jean-Paul Calderone <[EMAIL PROTECTED]> wrote: > > > Huge amounts of my pure Python code was broken by Python 2.5. > > >Interesting. Could you give a

Re: Built-in datatypes speed

2007-02-08 Thread Klaas
On Feb 7, 2:34 am, Maël Benjamin Mettler <[EMAIL PROTECTED]> wrote: > Anyway, I reimplemented parts of TigerSearch > (http://www.ims.uni-stuttgart.de/projekte/TIGER/TIGERSearch/) in Python. > I am currently writing the paper that goes along with this > reimplementation. Part of the paper deals wit

Re: The reliability of python threads

2007-01-24 Thread Klaas
On Jan 24, 5:18 pm, Paul Rubin <http://[EMAIL PROTECTED]> wrote: > "Klaas" <[EMAIL PROTECTED]> writes: > > CPython is more that "a particular implementation" of python, > It's precisely a particular implementation of Python. Other > implemen

Re: The reliability of python threads

2007-01-24 Thread Klaas
On Jan 24, 4:11 pm, Paul Rubin <http://[EMAIL PROTECTED]> wrote: > "Klaas" <[EMAIL PROTECTED]> writes: > > POSIX issues aside, Python's threading model should be less susceptible > > to memory-barrier problems that are possible in other languages (this >

Re: The reliability of python threads

2007-01-24 Thread Klaas
On Jan 24, 10:43 am, "Carl J. Van Arsdall" <[EMAIL PROTECTED]> wrote: > Yea, typically I would think that. The problem I am seeing is > incredibly intermittent. Like a simple pyro server that gives me a > problem maybe every three or four months. Just something funky will > happen to the state

Re: The reliability of python threads

2007-01-24 Thread Klaas
On Jan 24, 10:43 am, "Carl J. Van Arsdall" <[EMAIL PROTECTED]> wrote: > Chris Mellon wrote: > > On 24 Jan 2007 18:21:38 GMT, Nick Maclaren <[EMAIL PROTECTED]> wrote: > > >> [snip] > > > I'm aware of the issues with the POSIX threading model. I still stand > > by my statement - bringing up the pro

Re: The reliability of python threads

2007-01-24 Thread Klaas
On Jan 24, 10:43 am, "Carl J. Van Arsdall" <[EMAIL PROTECTED]> wrote: > Chris Mellon wrote: > > On 24 Jan 2007 18:21:38 GMT, Nick Maclaren <[EMAIL PROTECTED]> wrote: > > >> [snip] > > > I'm aware of the issues with the POSIX threading model. I still stand > > by my statement - bringing up the pro

Re: Problem installing cElementTree on Python 2.5

2007-01-10 Thread Klaas
Piet van Oostrum wrote: > I have just installed Python 2.5 on Mac OS X 10.4.8 on an iBook (PPC) from > the dmg. Now I tried to install cElementTree -1.0.5-20 from source (no egg > available in cheeseshop) and got the following compilation error: python2.5 ships with cElementTree: import xml.etree

Re: Traceback of hanged process

2007-01-08 Thread Klaas
Hynek Hanke wrote: > Hello, > > please, how do I create a pythonic traceback from a python process that > hangs and is not running in an interpreter that I executed manually > or it is but doesn't react on CTRL-C etc? I'm trying to debug a server > implemented in Python, so I need some analog of 'g

Re: Set type?

2007-01-04 Thread Klaas
Fredrik Lundh wrote: > > if type(var) is types.SetType: > >blah > > > > but that is not available in types module. I am using 2.4 > > # set or subclass of set > if isinstance(var, set): > ... or if isinstance(var, (set, frozenset)): ... -Mike -- http://mail.python.o

Re: Wow, Python much faster than MatLab

2006-12-31 Thread Klaas
sturlamolden wrote: > as well as looping over the data only once. This is one of the main > reasons why Fortran is better than C++ for scientific computing. I.e. > instead of > > for (i=0; i array1[i] = (array1[i] + array2[i]) * (array3[i] + array4[i]); > > one actually gets something like thre

Re: pyparsing announcement?

2006-12-22 Thread Klaas
Paul McGuire wrote: > I have tried a couple of times now to post an announcement of the latest > version of pyparsing, but it does not seem to be making it past the news > server, neither through my local ISP's server nor through GoogleGroups. > Could it be because I am also posting to comp.lang.py

Re: using methods base64 module in conjunction with Crypto.Hash.SHA256

2006-12-20 Thread Klaas
[EMAIL PROTECTED] wrote: > I am attempting to implement a process, and I'm pretty sure that a > major roadblock is that I do not understand the nomenclature. The > specs indicate that the goal is to calculate a message digest using an > SHA-256 algorithm. There are 2 examples included with the s

Re: Cpoying a PyList to a C string array

2006-12-19 Thread Klaas
Sheldon wrote: > Thanks Mike, > > I am rewriting the code but I don't understand the part about the c > struct variable called work. The function I posted is a part of a > larger script and I just posted that part that was problamatic. I was > under the impression that if I declared the structure

Re: Cpoying a PyList to a C string array

2006-12-19 Thread Klaas
Sheldon wrote: > The code below is a rookie attempt to copy a python list of strings to > a string array in C. It works to some extent but results in memory > problems when trying to free the C string array. Does anyone know how > to do this properly? You have numerous problems in this code. The

Re: sha, PyCrypto, SHA-256

2006-12-18 Thread Klaas
Dennis Benzinger wrote: > > Python 2.5 comes with SHA-256 in the hashlib module. > So you could install Python 2.5 instead of the PyCrypto module. You can download the python2.5 hashlib module for use with python2.4 -MIke -- http://mail.python.org/mailman/listinfo/python-list

Re: merits of Lisp vs Python

2006-12-08 Thread Klaas
Aahz wrote: > As for your claims about speed, they are also nonsense; I doubt one > would find an order of magnitude increase of speed for production > programs created by a competent Lisp programmer compared to programs > created by a competent Python programmer. Lisp can be compiled into an ex

Re: I think Python is a OO and lite version of matlab

2006-12-08 Thread Klaas
On Dec 7, 11:48 pm, "Allen" <[EMAIL PROTECTED]> wrote: > Does anyone agree with me? > If you have used Matlab, welcome to discuss it. Numpy definitely was inspired in its extended array syntax by matlab. Besides that, I don't think two languages could be more different. Philosophically, matlab i

Re: len() and PEP 3000

2006-12-06 Thread Klaas
Beliavsky wrote: > Thomas Guettler wrote: > > Hi, > > > > The function len() is not mentioned in the Python 3000 PEPs. > > > > I suggest that at least lists, tupples, sets, dictionaries and strings > > get a len() method. I think the len function can stay, removing it > > would break to much code.

Re: What are python closures realy like?

2006-12-06 Thread Klaas
Michele Simionato wrote: > I believe decorators are in large part responsible for that. A callable > object does not work > as a method unless you define a custom __get__, so in decorator > programming it is > often easier to use a closure. OTOH closures a not optimal if you want > persistency >

Re: Possible to assure no "cyclic"/"uncollectible" memory leaks?

2006-12-02 Thread Klaas
Joe Peterson wrote: > I've been doing a lot of searching on the topic of one of Python's more > disturbing issues (at least to me): the fact that if a __del__ finalizer > is defined and a cyclic (circular) reference is made, the garbage > collector cannot clean it up. It is a somewhat fundamental

Fun with with

2006-12-01 Thread Klaas
Occasionally I find myself wanting a block that I can break out of at arbitrary depth--like java's named break statements. Exceptions can obviously be used for this, but it doesn't always look nice. The with statement can be used to whip up something quite usable: class ExitBlock(object): ""

Re: Is python memory shared between theads?

2006-12-01 Thread Klaas
John Henry wrote: > Wesley Henwood wrote: > > Is this normal behavior? Based on the little documentation I have been > > able to find on this topic, it is normal behavior. The only way to use > > same-named variables in scripts is to have them run in a different > > process, rather than differe

Re: What are python closures realy like?

2006-12-01 Thread Klaas
Karl Kofnarson wrote: > Hi, > while writing my last program I came upon the problem > of accessing a common local variable by a bunch of > functions. > I wanted to have a function which would, depending on > some argument, return other functions all having access to > the same variable. An OO appro

Re: Remarkable results with psyco and sieve of Eratosthenes

2006-11-30 Thread Klaas
Klaus Alexander Seistrup wrote: > Pekka Karjalainen wrote: > > > You can omit the call to math.sqrt if you test this instead. > > > > y*y > x > > > > in place of if y > maxfact: . > > Or use > > sqrt = lambda x: x ** .5 Test it: $ python -m timeit -s "from math import sqrt" "sqrt(5.6)"

Re: How to increase the speed of this program?

2006-11-28 Thread Klaas
Klaas wrote: > Klaas wrote: > > > In fact, you can make it about 4x faster by balancing: > > > > [EMAIL PROTECTED] ~]$ python -m timeit -s "from array import array" > > "array('c','\0'*200)*500" > > 1 loops, best

Re: How to increase the speed of this program?

2006-11-28 Thread Klaas
Klaas wrote: > In fact, you can make it about 4x faster by balancing: > > [EMAIL PROTECTED] ~]$ python -m timeit -s "from array import array" > "array('c','\0'*200)*500" > 1 loops, best of 3: 32.4 usec per loop This is an unclean minim

Re: How to increase the speed of this program?

2006-11-28 Thread Klaas
John Machin wrote: > Thanks, that's indeed faster than array(t, [v]*n) but what I had in > mind was something like an additional constructor: > > array.filledarray(typecode, repeat_value, repeat_count) > > which I speculate should be even faster. Looks like I'd better get a > copy of arraymodule.c

Re: The Python Papers Edition One

2006-11-23 Thread Klaas
Tennessee writes: >* If you say LaTex, I'll eat your brain. Or my hat. Unless I'm > seriously underrating it, but I don't think so. Why? It is a suitable solution to this problem. You can produce unformatted content, then produce pdf and html pages from it. -Mike -- http://mail.python.org

Re: utf - string translation

2006-11-22 Thread Klaas
David H Wild wrote: > In article <[EMAIL PROTECTED]>, >John Machin <[EMAIL PROTECTED]> wrote: > > So why do you want to strip off accents? The history of communication > > has several examples of significant difference in meaning caused by > > minute differences in punctuation or accents includ

Re: dict.reserve and other tricks

2006-11-17 Thread Klaas
[EMAIL PROTECTED] wrote: > Klaas: > > > Well, you can reduce the memory usage to virtually nothing by using a > > generator expression rather than list comprehension. > > Are you sure? I don't think so. Can you show a little example? Sorry, that was boneheade

Re: cPickle problems

2006-11-16 Thread Klaas
Jeff Poole wrote: > Good idea. Well, I did that, and I found out that the object causing > problems is a ParseResults object (a class from PyParsing) and that the > __getstate__ member is in fact an empty string (''). I'm not sure > where this leaves me... The PyParsing code clearly never crea

Re: dict.reserve and other tricks

2006-11-16 Thread Klaas
[EMAIL PROTECTED] wrote: > I have started doing practice creating C extensions for CPython, so > here are two ideas I have had, possibly useless. > > If you keep adding elements to a CPython dict/set, it periodically > rebuilds itself. So maybe dict.reserve(n) and a set.reserve(n) methods > may hel

Re: Python memory usage

2006-11-13 Thread Klaas
velotron wrote: > On Nov 9, 8:38 pm, "Klaas" <[EMAIL PROTECTED]> wrote: > > > I was referring specifically to abominations like range(100) > > However, there are plenty of valid reasons to allocate huge lists of > integers. I'm sure there are some; I d

Re: Python memory usage

2006-11-09 Thread Klaas
placid wrote: > Actually i am executing that code snippet and creating BeautifulSoup > objects in the range() (now xrange() ) code block. Right; I was referring specifically to abominations like range(100), not looping over an incrementing integer. -Mike -- http://mail.python.org/mailman

Re: Python memory usage

2006-11-07 Thread Klaas
placid wrote: > Hi All, > > Just wondering when i run the following code; > > for i in range(100): > print i > > the memory usage of Python spikes and when the range(..) block finishes > execution the memory usage does not drop down. Is there a way of > freeing this memory that range(..) a

Re: Defaultdict and speed

2006-11-04 Thread Klaas
[EMAIL PROTECTED] wrote: > Klaas wrote: > > Benchmarks? > > There is one (fixed in a succesive post) in the original thread I was > referring to: > http://groups.google.com/group/it.comp.lang.python/browse_thread/thread/aff60c644969f9b/ > If you want I can give more of th

Re: Defaultdict and speed

2006-11-03 Thread Klaas
[EMAIL PROTECTED] wrote: > This post sums some things I have written in another Python newsgroup. > More than 40% of the times I use defaultdict like this, to count > things: > > >>> from collections import defaultdict as DD > >>> s = "abracadabra" > >>> d = DD(int) > >>> for c in s: d[c] += 1 > ..

Re: Sorted and reversed on huge dict ?

2006-11-03 Thread Klaas
[EMAIL PROTECTED] wrote: > thanks for your replies :) > > so i just have tried, even if i think it will not go to the end => i > was wrong : it is around 1.400.000 entries by dict... > > but maybe if keys of dicts are not duplicated in memory it can be done > (as all dicts will have the same keys,

Re: Javascript is turning into Python?!

2006-11-03 Thread Klaas
Paul Rubin wrote: > "Carl Banks" <[EMAIL PROTECTED]> writes: > > > http://developer.mozilla.org/en/docs/New_in_JavaScript_1.7 > > Maybe in exchange, Python can borrow the let statement. > > Maybe the with statement could be extended to allow binding more than > one variable. > with x as f(), y

Re: import in threads: crashes & strange exceptions on dual core machines

2006-10-31 Thread Klaas
robert wrote: > Klaas wrote: > > It seems clear that the import lock does not include fully-executing > > the module contents. To fix this, just import cookielib before the > > What is the exact meaning of "not include fully-executing" - regarding the > exam

Re: import in threads: crashes & strange exceptions on dual core machines

2006-10-30 Thread Klaas
It seems clear that the import lock does not include fully-executing the module contents. To fix this, just import cookielib before the threads are spawned. Better yet, use your own locks around the acquisition of the opener instance (this code seems fraughtfully thread-unsafe--fix that and you s

Re: ZODB for inverted index?

2006-10-25 Thread Klaas
[EMAIL PROTECTED] wrote: > Hello, Hi. I'm not familiar with ZODB, but you might consider berkeleydb, which behaves like a disk-backed + memcache dictionary. -Mike -- http://mail.python.org/mailman/listinfo/python-list

Re: new-style classes, __hash__. is the documentation wrong?

2006-10-25 Thread Klaas
gabor wrote: > > If a class defines mutable objects and implements a __cmp__() or > __eq__() method, it should not implement __hash__(), since the > dictionary implementation requires that a key's hash value is immutable > (if the object's hash value changes, it will be in the wrong hash buck

Re: Python segmentation fault?

2006-10-23 Thread Klaas
Michael B. Trausch wrote: > Is there a way to debug scripts that cause segmentation faults? I can > do a backtrace in gdb on Python, but that doesn't really help me all > that much since, well, it has nothing to do with my script... :-P Yes. If you think it is a python interpreter bug, create a

Re: problem with hot shot stats

2006-10-10 Thread Klaas
Monu wrote: > HI All, > I am getting problem in using hotshot profiler. > When I hotshot with lineevents=0, it works fine, > but when I use lineevents=1, I get error in stats <> > Can anybody help to figure out the problem please? hotshot has never reached production-ready stability, imo. Use th

Re: for: else: - any practical uses for the else clause?

2006-09-29 Thread Mike Klaas
On 9/29/06, Johan Steyn <[EMAIL PROTECTED]> wrote: > On 29 Sep 2006 11:26:10 -0700, Klaas <[EMAIL PROTECTED]> wrote: > > > else: does not trigger when there is no data on which to iterate, but > > when the loop terminated normally (ie., wasn't break-ed out).

Re: for: else: - any practical uses for the else clause?

2006-09-29 Thread Klaas
Klaas wrote: > else: does not trigger when there is no data on which to iterate, but > when the loop terminated normally (ie., wasn't break-ed out). It is > meaningless without break. Sorry, this was worded confusingly. "else: triggers when the loop terminates normally, not

Re: for: else: - any practical uses for the else clause?

2006-09-29 Thread Klaas
metaperl wrote: > Actually right after posting this I came up with a great usage. I use > meld3 for my Python based dynamic HTML generation. Whenever I plan to > loop over a tree section I use a for loop, but if there is no data to > iterate over, then I simply remove that section from the tree or

Re: Strange behaviour of 'is'

2006-09-21 Thread Klaas
Ben C wrote: > On 2006-09-21, Fijoy George <[EMAIL PROTECTED]> wrote: > > But my understanding does not explain the result of the second comparison. > > According to the experiment, y[0] and y[1] are the same object! > > I'm as baffled as you, even more so its implication: > >>> a = 2. > >>> b =

Re: Sets and Membership Tests

2006-07-11 Thread Klaas
JKPeck wrote: > I would like to be able use sets where the set members are objects of a > class I wrote. > I want the members to be distinguished by some of the object content, > but I have not figured out how a set determines whether two (potential) > elements are identical. I tried implementing

Re: Large Dictionaries

2006-06-12 Thread Klaas
Thomas Ganss wrote: > Klaas schrieb: > > > 4. Insert your keys in sorted order. > This advice is questionable - > it depends on the at least on the db vendor and probably > sometimes on the sort method, if inserting pre-sorted > values is better. The article I wrote

Re: Large Dictionaries

2006-05-24 Thread Klaas
Chris: > class StorageBerkeleyDB(StorageTest): >def runtest(self, number_hash): >db = bsddb.hashopen(None, flag='c', cachesize=8192) >for (num, wildcard_digits) in number_hash.keys(): >key = '%d:%d' % (num, wildcard_digits) >db[key] = None >db.clo

Re: Large Dictionaries

2006-05-24 Thread Klaas
Chris: > Berkeley DB is great for accessing data by key for things already > stored on disk (i.e. read access), but write performance for each > key-value pair is slow due to it being careful about flushing > writes to disk by default. This is absolutely false. -Mike -- http://mail.python.org/

Re: Large Dictionaries

2006-05-16 Thread Klaas
>22.2s 20m25s[3] 20m to insert 1m keys? You are doing something wrong. With bdb's it is crucial to insert keys in bytestring-sorted order. Also, be sure to give it a decent amount of cache. -Mike -- http://mail.python.org/mailman/listinfo/python-list

Re: list*list

2006-05-01 Thread Klaas
Diez wrote: > First of all: it's considered bad style to use range if all you want is a > enumeration of indices, as it will actually create a list of the size you > specified. Use xrange in such cases. > But maybe nicer is zip: > c = [av * bv for av, bv in zip(a, b)] By your logic, shouldn't it

Re: Best way to have a for-loop index?

2006-04-05 Thread Klaas
roy spewed: > The real question is *why* do you want the index? > > If you're trying to iterate through list indicies, you're probably trying > to write C, C++, Fortran, Java, etc in Python. Could we stop the stupid continual beratement of people validly asking about enumerate()? Yes, we want to

Re: Pickle or Mysql

2006-04-01 Thread Klaas
> Can I use Pickle to store about 500,000 key value pairs.. or should I > use mySql. Which one is best for performance, as the key value pair > increases. Pickle: absolutely out of the question. Mysql: might work, albeit slowly. Use berkeley DB (bsddb3), or zodb. I have no experience with the la

Re: Another proposed proposal: operator.bool_and / bool_or

2006-03-30 Thread Klaas
>def any(seq): return reduce(bool_or, seq, False) > def all(seq): return reduce(bool_and, seq, True) Any other use cases? These will be built-in in 2.5 -Mike -- http://mail.python.org/mailman/listinfo/python-list

Re: __slots__

2006-03-27 Thread Klaas
David wrote: > 3. What is a simple example of a Pythonic use of __slots__ that does NOT > involved the creation of **many** instances. mu. Your question presupposes the existence of such an example. -Mike -- http://mail.python.org/mailman/listinfo/python-list

Re: bsddb3 database file, are there any unexpected file size limits occuring in practice?

2006-02-28 Thread Klaas
> In my current project I expect the total size of the indexes to exceed > by far the size of the data indexed, but because Berkeley does not > support multiple indexed columns (i.e. only one key value column as > index) if I access the database files one after another (not > simultaneously) it sho

Re: bsddb3 database file, are there any unexpected file size limits occuring in practice?

2006-02-27 Thread Klaas
Claudio writes: > I am on a Windows using the NTFS file system, so I don't expect problems > with too large file size. how large can files grow on NTFS? I know little about it. > (I suppose it in having only 256 MB RAM available that time) as it is > known that MySQL databases larger than 2 GByt

Re: bsddb3 database file, what are the __db.001, __db.002, __db.003 files for?

2006-02-22 Thread Klaas
Claudio Grondi wrote: > Beside the intended database file >databaseFile.bdb > I see in same directory also the >__db.001 >__db.002 >__db.003 > files where >__db.003 is ten times as larger as the databaseFile.bdb > and >__db.001 has the same size as the databaseFile.bdb .

Mutable bytes type

2006-01-16 Thread Klaas
A PEP for a mutable bytes type was composed but withdrawn two years ago: http://www.python.org/peps/pep-0296.html Another was composed (status unclear) in 2004: http://www.python.org/peps/pep-0332.html It was mentioned on python-dev in 2004 (http://python.fyxm.net/dev/summary/2004-08-16_2004-08-3

Re: Regex anomaly

2006-01-02 Thread mike . klaas
Thanks guys, that is probably the most ridiculous mistake I've made in years -Mike -- http://mail.python.org/mailman/listinfo/python-list

Regex anomaly

2006-01-02 Thread mike . klaas
Hello, Has anyone has issue with compiled re's vis-a-vis the re.I (ignore case) flag? I can't make sense of this compiled re producing a different match when given the flag, odd both in it's difference from the uncompiled regex (as I thought the uncompiled api was a wrapper around a compile-and-

Re: How simputer COULD HAVE succeeded ?

2005-12-20 Thread mike . klaas
> PS. before investing time in Python, I wanted to find out if it > can interface low-level, by eg. calling the OS or C...etc. > eg. could it call linux's "dd if=.." ? In python you have full access to the shell, and excellent interoperability with c. -Mike -- http://mail.python.org/mailma

  1   2   >