Re: Best strategy for finding a pattern in a sequence of integers

2008-11-21 Thread Anton Vredegoor
On Fri, 21 Nov 2008 18:10:02 +0100 Gerard flanagan [EMAIL PROTECTED] wrote: data = ''' 1 6 6 1 6 6 1 6 6 1 6 6 1 6 6 1 9 3 3 0 3 3 0 3 3 0 3 3 0 10 6 6 1 6 6 1 6 6 1 6 6 1 6 6 1 6 6 1 6 6 1 9 3 3 0 3 3 0 3 3 0 3 3 0 10 6 6 1 6 6 1 6 6 1 6 6 1 6 6 1 6 6 1 6 6 1 9 3 3 0 3 3 0 3 3 0 3 3 0 10 6 6

Re: Possible bug in Tkinter for Python 2.6

2008-11-19 Thread Anton Vredegoor
On Wed, 19 Nov 2008 10:57:53 +0100 Eric Brunel [EMAIL PROTECTED] wrote: I'm trying out Python 2.6 and I found what might be a bug in the Tkinter module. How can I report it? maybe here: http://bugs.python.org/issue3774 The possible bug is a traceback when trying to delete a menu item in a

Re: Is psyco available for python 2.6?

2008-11-09 Thread Anton Vredegoor
On Thu, 30 Oct 2008 17:45:40 +0100 Gerhard Häring [EMAIL PROTECTED] wrote: psyco seems to just work on Linux with Python 2.6. So it is probably only a matter of compiling it on Windows for Python 2.6. Yes. I compiled it using wp setup.py build --compiler=mingw32 with cygwin, where wp was an

Re: need help with converting c function to python function

2007-07-05 Thread Anton Vredegoor
In article [EMAIL PROTECTED], [EMAIL PROTECTED] says... i have a c function from some modbus documentation that i need to translate into python. it looks like this: unsigned short CRC16(puchMsg, usDataLen) unsigned char *puchMsg ; unsigned short usDataLen ; { unsigned char

Re: Permutation over a list with selected elements

2007-06-20 Thread Anton Vredegoor
[EMAIL PROTECTED] wrote: Given a list of elements that are either a character or a character follows by a number, e.g. ['a', 'b', 'c1', 'd', 'e1', 'f', 'c2', 'x', 'e2'] find all the permutations that are given by switching the positions of the elements that: (1) begins with the same

Re: Create a new class on the fly

2007-06-02 Thread Anton Vredegoor
Alex Martelli wrote: You can find a few examples of me demonstrating the subject of your interest by searching for my name e.g. on video.google.com; searching for my name on Amazon will show some books using similar techniques, and searching for my name on groups.google.com will find about

Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-15 Thread Anton Vredegoor
Duncan Booth wrote: Recently there has been quite a bit of publicity about the One Laptop Per Child project. The XO laptop is just beginning rollout to children and provides two main programming environments: Squeak and Python. It is an exciting thought that that soon there will be

Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-15 Thread Anton Vredegoor
HYRY wrote: - should non-ASCII identifiers be supported? why? Yes. I want this for years. I am Chinese, and teaching some 12 years old children learning programming. The biggest problem is we cannot use Chinese words for the identifiers. As the program source becomes longer, they always lost

Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-14 Thread Anton Vredegoor
In article [EMAIL PROTECTED], [EMAIL PROTECTED] says... Martin v. Löwis: This PEP suggests to support non-ASCII letters (such as accented characters, Cyrillic, Greek, Kanji, etc.) in Python identifiers. I support this to ease integration with other languages and platforms that

Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-14 Thread Anton Vredegoor
Neil Hodgson wrote: Anton Vredegoor: Ouch! Now I seem to be disagreeing with the one who writes my editor. What will become of me now? It should be OK. I try to keep my anger under control and not cut off the pixel supply at the first stirrings of dissent. Thanks! I guess I won't

Re: Sorting troubles

2007-05-14 Thread Anton Vredegoor
[EMAIL PROTECTED] wrote: I see. I figured that list comprehensions made another list(duh), but I thought I could relink the object(List) to the new list and keep it once the function ended. Is it possible to pass a reference(to an object.. Like 'List', basically) to a function and change

Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-13 Thread Anton Vredegoor
Martin v. Löwis wrote: In summary, this PEP proposes to allow non-ASCII letters as identifiers in Python. If the PEP is accepted, the following identifiers would also become valid as class, function, or variable names: Löffelstiel, changé, ошибка, or 売り場 (hoping that the latter one means

Re: OT somewhat: Do you telecommute? What do you wish the boss understood about it?

2007-05-04 Thread Anton Vredegoor
estherschindler wrote: * If you telecommute, full- or part-time, what *one* thing do you wish the CIO or IT Management would understand that they don't currently get? I'm not currently telecommuting but last year I had a telecommuting job for half a year. What I would want to say to all

Re: Would You Write Python Articles or Screencasts for Money?

2007-04-25 Thread Anton Vredegoor
Antoon Pardon wrote: That's a good point, and also a valid reason for restricting the voting community to PSF members. Thanks, Alex. So in order to avoid a suspicion of a conflict of interest you want to turn the whole thing into private property of the PSF? That is the most ridiculous

Re: Would You Write Python Articles or Screencasts for Money?

2007-04-25 Thread Anton Vredegoor
Anton Vredegoor wrote: It's about as ridiculous as proving that a stiff parrot is dead by grabbing it by the legs and repeatedly hitting it's head on the counter. Or to write it's where its is more appropriate. A. -- http://mail.python.org/mailman/listinfo/python-list

Re: Would You Write Python Articles or Screencasts for Money?

2007-04-25 Thread Anton Vredegoor
Antoon Pardon wrote: On 2007-04-25, Anton Vredegoor [EMAIL PROTECTED] wrote: Antoon Pardon wrote: That's a good point, and also a valid reason for restricting the voting community to PSF members. Thanks, Alex. So in order to avoid a suspicion of a conflict of interest you want to turn

Re: Would You Write Python Articles or Screencasts for Money?

2007-04-25 Thread Anton Vredegoor
Steve Holden wrote: I'm sorry, but while the PSF is a democratically-run organization its franchise doesn't extend beyond the membership. I didn't realize this was about an PSF internal affair. Of course a group of people can decide on its internal matters without asking anyone else, as

Re: Would You Write Python Articles or Screencasts for Money?

2007-04-24 Thread Anton Vredegoor
Steve Holden wrote: When cash is involved, it's important to avoid even the slightest hint of a suggestion of a suspicion of a conflict of interest; that, I guess, is why firms that run contests with cash prizes always declare employees and their families not eligible, and why I think the

Re: TK-grid problem, please help

2007-04-21 Thread Anton Vredegoor
Ray wrote: hi, I have a question about how to use .grid_forget (in python/TK) I need to work on grid repeatly. everytime when a button is pressed, the rows of grid is different. such like, first time, it generate 10 rows of data. 2nd time, it maybe only 5 rows. so I need a way to RESET

Re: multiremberco

2007-04-20 Thread Anton Vredegoor
[EMAIL PROTECTED] wrote: This one gets the order wrong. With def test(): L = 1, 2, 3, 'a', 4, 'a', 5, 'a', 6, 'a' it1, it2 = xsplitter(L, lambda x: x == 'a') print it1.next() print it2.next() print it1.next() print it2.next() print it1.next() print

Re: multiremberco

2007-04-20 Thread Anton Vredegoor
Anton Vredegoor wrote: from collections import deque def xsplitter(seq, pred): Q = deque(),deque() it = iter(seq) def gen(p): for x in it: if pred(x) == p: Q[p].append(x) while Q[p]: yield Q[p].popleft

Re: multiremberco

2007-04-20 Thread Anton Vredegoor
Anton Vredegoor wrote: What's up here? Was it a fata morgana? Am I overlooking something? Even more crazy version: def xsplitter(seq, pred): Q = deque(),deque() it = iter(seq) def gen(p): for x in it: Q[pred(x) == p].append(x) while Q[p

Re: multiremberco

2007-04-20 Thread Anton Vredegoor
Anton Vredegoor wrote: def xsplitter(seq, pred): Q = deque(),deque() it = iter(seq) def gen(p): for x in it: Q[pred(x) == p].append(x) while Q[p]: yield Q[p].popleft() while Q[p]: yield Q[p].popleft() return gen(1),gen(0

Re: Expanding tkinter widgets to fill the window

2007-04-20 Thread Anton Vredegoor
KDawg44 wrote: I am writing a GUI front end in Python using Tkinter. I have developed the GUI in a grid and specified the size of the window. The widgets are centered into the middle of the window. I would like them to fill the window. I tried using the sticky=E+W+N+S option on the

Re: multiremberco

2007-04-19 Thread Anton Vredegoor
Anton Vredegoor wrote: [EMAIL PROTECTED] wrote: Try it with def test(): L = 'a', 1, 2, 'a' it1, it2 = xsplitter(L, lambda x: x == 'a') print it1.next() print it2.next() print it1.next() print it2.next() The last print statement raises StopIteration... We

Re: multiremberco

2007-04-19 Thread Anton Vredegoor
Anton Vredegoor wrote: Anton Vredegoor wrote: [EMAIL PROTECTED] wrote: Try it with def test(): L = 'a', 1, 2, 'a' it1, it2 = xsplitter(L, lambda x: x == 'a') print it1.next() print it2.next() print it1.next() print it2.next() The last print statement raises

Re: multiremberco

2007-04-19 Thread Anton Vredegoor
[EMAIL PROTECTED] wrote: Um, no. That one stops prematurely if your input sequence is: L = 1, 2, 3, 'a', 'a' Ah, thanks! You get points for persistence, however. :) Maybe this one is better? from collections import deque from itertools import chain, repeat def xsplitter(seq, pred):

Re: multiremberco

2007-04-19 Thread Anton Vredegoor
Anton Vredegoor wrote: Maybe this one is better? No, this one keeps generating output. But this one stops at least: from collections import deque from itertools import chain, repeat def xsplitter(seq, pred): Q = deque(),deque() sentinel = object() it = chain(seq,repeat

Re: multiremberco

2007-04-18 Thread Anton Vredegoor
[EMAIL PROTECTED] wrote: I have modified, simplified and (hopefully) improved Steven's code like this (but it may be a bit slower, because the class It is inside the function?): Here is a yet more simple version, I wonder if it still does the same thing, whatever it is you are looking for

Re: multiremberco

2007-04-18 Thread Anton Vredegoor
[EMAIL PROTECTED] wrote: If you don't wish to use objects, you can replace them with a closure: import collections def xsplitter(iseq, pred): queue = [ collections.deque(), collections.deque() ] def it(parity): while True: if queue[parity]:

Re: multiremberco

2007-04-18 Thread Anton Vredegoor
[EMAIL PROTECTED] wrote: Try it with def test(): L = 'a', 1, 2, 'a' it1, it2 = xsplitter(L, lambda x: x == 'a') print it1.next() print it2.next() print it1.next() print it2.next() The last print statement raises StopIteration... We, however, expected each

Re: combination function in python

2007-04-16 Thread Anton Vredegoor
[EMAIL PROTECTED] wrote: Isn't that what docstrings are for? Can't you leave the function name noverk() and add something to the effect of this function calculates combinations? Then it would show up in searches, wouldn't it? Yes, a doc string would help finding it in searches, however since

Re: proposed PEP: iterator splicing

2007-04-15 Thread Anton Vredegoor
Paul Rubin wrote: def some_gen(): ... yield *some_other_gen() comes to mind. Less clutter, and avoids yet another temp variable polluting the namespace. Thoughts? Well, not directly related to your question, but maybe these are some ideas that would help determine

Re: proposed PEP: iterator splicing

2007-04-15 Thread Anton Vredegoor
Kay Schluehr wrote: Maybe you should start by developing a design pattern first and publish it in the Cookbook. I have the fuzzy impression that the idea you are after, requires more powerfull control structures such as delimited continuations that are beyond ths scope of Pythons simple

Re: combination function in python

2007-04-15 Thread Anton Vredegoor
Jussi Piitulainen wrote: There's probably even a really clever way to avoid that final division, but I suspect that would cost more in time and memory than it would save. We're getting closer and closer to something I already posted a few times here. This implementation was unfortunate

Re: combination function in python

2007-04-15 Thread Anton Vredegoor
[EMAIL PROTECTED] wrote: We're getting closer and closer to something I already posted a few times here. This implementation was unfortunate because I consistently used an uncommon name for it so people couldn't easily find it But then, who's looking for it? The OP was trying to find it in

Re: Emergence of Grok

2007-04-14 Thread Anton Vredegoor
Paul McGuire wrote: I just stumbled upon a great-looking project, to make Zope3 more approachable to mere mortals such as myself. Echoing the ROR mantra of convention over configuration, the Grok project (http:// grok.zope.org/) aims to stand on the shoulders of Zope3, while providing the

Re: Simple integer comparison problem

2007-04-14 Thread Anton Vredegoor
Bart Willems wrote: I have a feeling that there's a Python-solution that is shorter yet better readable, I just can't figure it out yet... Shorter (and faster for big lists): Yes. More readable: I don't know, I guess that depends on ones familiarity with the procedure. import bisect def

Re: Hpw make lists that are easy to sort.

2007-03-31 Thread Anton Vredegoor
Paul Rubin wrote: Oh, I see what you mean. I don't see an obvious faster way to do it and I don't have the feeling that one necessarily exists. As someone mentioned, you could do an n-way merge, which at least avoids using quadratic memory. Here's a version using Frederik Lundh's trick of

Re: Hpw make lists that are easy to sort.

2007-03-30 Thread Anton Vredegoor
Terry Reedy wrote: If I understand correctly, you want to multiiply each of m numbers by each of n numbers, giving m*n products. That is O(m*n) work. Inserting (and extracting) each of these is a constant size m priority cue takes, I believe, O(log(m)) work, for a total of m*n*log(m).

Re: Hpw make lists that are easy to sort.

2007-03-29 Thread Anton Vredegoor
Terry Reedy wrote: If I understand correctly, you want to multiiply each of m numbers by each of n numbers, giving m*n products. That is O(m*n) work. Inserting (and extracting) each of these is a constant size m priority cue takes, I believe, O(log(m)) work, for a total of m*n*log(m).

Hpw make lists that are easy to sort.

2007-03-28 Thread Anton Vredegoor
Python's sorting algorithm takes advantage of preexisting order in a sequence: #sort_test.py import random import time def test(): n = 1000 k = 2**28 L = random.sample(xrange(-k,k),n) R = random.sample(xrange(-k,k),n) t = time.time() LR = [(i+j) for i in L for j

Re: Hpw make lists that are easy to sort.

2007-03-28 Thread Anton Vredegoor
Paul Rubin wrote: Well there are various hacks one can think of, but is there an actual application you have in mind? Suppose both input lists are sorted. Then the product list is still not sorted but it's also not completely unsorted. How can I sort the product? I want to know if it is

Re: Hpw make lists that are easy to sort.

2007-03-28 Thread Anton Vredegoor
Terry Reedy wrote: One could generate the items in order in less space by doing, for instance, an m-way merge, in which only the lowest member of each of the m sublists is present at any one time. But I don't know if this (which is O(m*n*log(m))) would be any faster (in some Python

Re: A better webpage filter

2007-03-26 Thread Anton Vredegoor
John J. Lee wrote: http://webcleaner.sourceforge.net/ Thanks, I will look into it sometime. Essentially my problem has been solved by switching to opera, but old habits die hard and I find myself using Mozilla and my little script more often than would be logical. Maybe the idea of having a

Re: A better webpage filter

2007-03-26 Thread Anton Vredegoor
Gabriel Genellina wrote: If you don't mind using JavaScript instead of Python, UserJS is for you: http://www.opera.com/support/tutorials/userjs/ My script loads a saved copy of a page and uses it to open an extra tab with a filtered view. It also works when javascript is disabled. A. --

A better webpage filter

2007-03-24 Thread Anton Vredegoor
Since a few days I've been experimenting with a construct that enables me to send the sourcecode of the web page I'm reading through a Python script and then into a new tab in Mozilla. The new tab is automatically opened so the process feels very natural, although there's a lot of reading,

Re: A better webpage filter

2007-03-24 Thread Anton Vredegoor
Gabriel Genellina wrote: I use the Opera browser: http://www.opera.com Among other things (like having tabs for ages!): - enable/disable tables and divs (like you do) - enable/disable images with a keystroke, or only show cached images. - enable/disable CSS - banner supressing (aggressive)

Re: [JOB] Sr. Python Developer, Northern VA

2007-03-22 Thread Anton Vredegoor
Steven D. Arnold wrote: Neosynapse is seeking a senior software developer located in or Subtract ten points from your credibility for writing senior here. willing to relocate to the Northern VA area to join a project building one of the largest grid computing data platforms in the

Re: [JOB] Sr. Python Developer, Northern VA

2007-03-22 Thread Anton Vredegoor
Steve Holden wrote: /rant Feel better now? Yes! But *now* I'm afraid it will have negative consequences for my future employability. However if it will lead to adjusting the kind of submissions at http://www.python.org/community/jobs/ it was probably worth it. A. 'thanks for asking' --

Re: [JOB] Sr. Python Developer, Northern VA

2007-03-22 Thread Anton Vredegoor
[EMAIL PROTECTED] wrote: I think the steady increase in the number of active listings over the past couple years bodes well for the job prospects of Python programmers as a whole. There are currently 99 job postings on the job board dating back to mid-December. A year ago there were

Re: [JOB] Sr. Python Developer, Northern VA

2007-03-22 Thread Anton Vredegoor
Michael Bentley wrote: Perhaps it is different where you live, but here you can put on your resume relevant things that aren't paying jobs. Otherwise nobody would ever get their first job, right? Sure you can. But around here if one has been unemployed for a while it's nearly impossible

Re: [JOB] Sr. Python Developer, Northern VA

2007-03-22 Thread Anton Vredegoor
John J. Lee wrote: You may not realise it if you haven't been applying for work since you did that, but I'm sure you've done a lot for your employability (I hate that word, it implies that it's a one-sided business, clearly false) by working as a freelancer. Since I'm freelancing my leverage

Re: To count number of quadruplets with sum = 0

2007-03-16 Thread Anton Vredegoor
n00m wrote: 62.5030784639 Maybe this one could save a few seconds, it works best when there are multiple occurrences of the same value. A. from time import time def freq(L): D = {} for x in L: D[x] = D.get(x,0)+1 return D def test(): t = time() f =

Re: number generator

2007-03-14 Thread Anton Vredegoor
Raymond Hettinger wrote: Since people are posting their solutions now (originally only hints were provided for the homework problem), here's mine: Homework problem? Do you have some information from the OP that I can't find in this thread? Anyway, I consider the 'homework' idea and the

Re: number generator

2007-03-14 Thread Anton Vredegoor
Paul Rubin wrote: def genpool(n, m): if n == 1: yield [m] else: for i in xrange(1, m): for rest in genpool(n-1, m-i): yield rest + [i] import random print random.choice(list(genpool(n=4, m=20))) This generates a lot of the

Re: number generator

2007-03-14 Thread Anton Vredegoor
Anton Vredegoor wrote: def memoize(fn): cache = {} def proxy(*args): try: return cache[args] except KeyError: return cache.setdefault(args, fn(*args)) return proxy Sorry this doesn't work in this case. This works: def memoize(fn): cache

Re: number generator

2007-03-13 Thread Anton Vredegoor
Dick Moores wrote: If the added constraint is instead that the probability of generating a given list of length N be the same as that of generating any other list of length N, then I believe my function does the job. Of course, [1,46,1,1,1] and [1,1,46,1,1], as Python lists, are distinct.

Re: number generator

2007-03-13 Thread Anton Vredegoor
Dick Moores wrote: Paul Rubin's fencepost method is about 14 times faster than mine for the same M == 8 and N == 4! :( Actually they looked a bit similar after I had mucked a bit with them :-) But indeed it's slow. Sorry, I don't understand this. Could you spell it out for me by

Re: number generator

2007-03-10 Thread Anton Vredegoor
Raymond Hettinger wrote: To make the solutions equi-probable, a simple approach is to recursively enumerate all possibilities and then choose one of them with random.choice(). Maybe it is possible to generate the possibilities by an indexing function and then use randint to pick one of them.

Re: number generator

2007-03-10 Thread Anton Vredegoor
Terry Reedy wrote: Partitioning positive count m into n positive counts that sum to m is a standard combinatorial problem at least 300 years old. The number of such partitions, P(m,n) has no known exact formula but can be computed inductively rather easily. The partitions for m and n

Re: number generator

2007-03-10 Thread Anton Vredegoor
Anton Vredegoor wrote: L = [1] * (bins-1) + [0] * (bins-1) replace these lines in the code by: L = [1] * (bins-1) + [0] * (bricks-bins) A. -- http://mail.python.org/mailman/listinfo/python-list

Re: number generator

2007-03-10 Thread Anton Vredegoor
Terry Reedy wrote: Anton Vredegoor [EMAIL PROTECTED] wrote in message | Yes that was one of my first ideas too. But later on Steven pointed out | that one can view the problem like this: | | 0001100010100 | | That would be [3,4,3,1,2] | | where the '1' elements are like dividing

Re: permutations - fast with low memory consumption?

2006-12-19 Thread Anton Vredegoor
Gerard Flanagan wrote: No claims with respect to speed, but the kslice function here: http://gflanagan.net/site/python/utils/sequtils/ will give the 'k-subsets' which then need to be permuted - alternatively Google. Maybe the function below could then do these permutations. Anton.

Re: proof of concept python and tkinter gnugo interface

2006-12-01 Thread Anton Vredegoor
grindel wrote: Anton Vredegoor wrote: [...] Here's the proof of concept, just copy it to some dir and run the Python script: http://home.hccnet.nl/a.vredegoor/gnugo/ It needs Python 2.5 which you can get at: http://www.python.org/ If you talking about a simple gui for gnu go it's

Re: How do I access a main frunction from an import module?

2006-11-24 Thread Anton Vredegoor
Jim wrote: I have created an import module. And would like to access a function from the main script, e.g., file abc.py: ### def a(): m() return None file main.py: # from abc import * def m(): print 'something'

proof of concept python and tkinter gnugo interface

2006-11-23 Thread Anton Vredegoor
For the last few days I've been doodling with a script that provides a graphical interface to gnugo by using its GTP protocol. At the moment the script is *very* basic, in fact the only thing it does is to allow one to click on a coordinate and place a move there OR press the space bar in

Re: code is data

2006-06-23 Thread Anton Vredegoor
Paul Boddie wrote: Anton Vredegoor wrote: Yes, but also what some other posters mentioned, making Pythons internal parsing tree available to other programs (and to Python itself) by using a widely used standard like XML as its datatype. http://pysch.sourceforge.net/ast.html Very

Re: How to generate all permutations of a string?

2006-06-22 Thread Anton Vredegoor
Girish Sahani wrote: I want to generate all permutations of a string. I've managed to generate all cyclic permutations. Please help :) http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496724 anton -- http://mail.python.org/mailman/listinfo/python-list

Re: [OT] code is data

2006-06-21 Thread Anton Vredegoor
Bruno Desthuilliers wrote: You mean like 'converting' javascript to python or python to ruby (or converting any home-grown DSL to Python, etc) ? Yes, but also what some other posters mentioned, making Pythons internal parsing tree available to other programs (and to Python itself) by using a

Re: [OT] code is data

2006-06-20 Thread Anton Vredegoor
Diez B. Roggisch wrote: ... The whole point of a code transformation mechanism like the one Anton is talking about is to be dynamic. Else one just needs a preprocessor... No, it is not the whole point. The point is The idea is that we now have a fast parser (ElementTree) with a

Re: [OT] code is data

2006-06-19 Thread Anton Vredegoor
bruno at modulix wrote: I still don't get the point. Well, I've got to be careful here, lest I'd be associated with the terr.., eh, the childp..., eh the macro-enablers. The idea is to have a way to transform a Python (.py) module into XML and then do source code manipulations in XML-space

[OT] code is data

2006-06-17 Thread Anton Vredegoor
With the inclusion of ElementTree (an XML-parser) in Python25 and recent developments concerning JSON (a very Pythonesque but somewhat limited XML notation scheme, let's call it statically typed XML) Python seems to have reached a stage where it now seems to be possible to completely swallow

Re: An oddity in list comparison and element assignment

2006-06-03 Thread anton . vredegoor
Alex Martelli wrote: [EMAIL PROTECTED] wrote: Can somebody please shut down this bot? I think it's running out of Much as you might love for somebody to shut me down, that (unfortunately, no doubt, from your viewpoint) is quite unlikely to happen. Although making predictions is always

Re: An oddity in list comparison and element assignment

2006-06-02 Thread anton . vredegoor
Alex Martelli wrote: [snip] Can somebody please shut down this bot? I think it's running out of control. It seems to be unable to understand that don't be evil might be good when you're small (at least it's not very bad) but that it becomes distinctly evil when you're big. What is good when

Re: integer to binary...

2006-06-01 Thread Anton Vredegoor
[EMAIL PROTECTED] wrote: does anyone know a module or something to convert numbers like integer to binary format ? for example I want to convert number 7 to 0111 so I can make some bitwise operations... def bits(i,n): return tuple((0,1)[ij 1] for j in xrange(n-1,-1,-1))

Re: A critic of Guido's blog on Python's lambda

2006-05-08 Thread Anton Vredegoor
[EMAIL PROTECTED] wrote: When you consider that there was just a big flamewar on comp.lang.lisp about the lack of standard mechanisms for both threading and sockets in Common Lisp (with the lispers arguing that it wasn't needed) I find it curious that someone can say Common Lisp scales well.

Re: not quite 1252

2006-04-29 Thread Anton Vredegoor
Martin v. Löwis wrote: Well, if the document is UTF-8, you should decode it as UTF-8, of course. Thanks. This and: http://en.wikipedia.org/wiki/UTF-8 solved my problem with understanding the encoding. Anton proof that I understand it now (please anyone, prove me wrong if you can): from

Re: not quite 1252

2006-04-28 Thread Anton Vredegoor
Serge Orlov wrote: I extracted content.xml from a test file and the header is: ?xml version=1.0 encoding=UTF-8? So any xml library should handle it just fine, without you trying to guess the encoding. Yes my header also says UTF-8. However some kind person send me an e-mail stating that

Re: not quite 1252

2006-04-28 Thread Anton Vredegoor
Richard Brodie wrote: Anton Vredegoor [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Yes my header also says UTF-8. However some kind person send me an e-mail stating that since I am getting \x94 and such output when using repr (even if str is giving correct output

Re: not quite 1252

2006-04-28 Thread Anton Vredegoor
Serge Orlov wrote: Anton Vredegoor wrote: In fact there are a lot of printable things that haven't got a text attribute, for example some items with tag ()s. In my sample file I see text:s text:c=2/, is that you're talking about? Since my file is small I can say for sure this tag

Re: not quite 1252

2006-04-28 Thread Anton Vredegoor
Anton Vredegoor wrote: So, probably yes. If it doesn't have a text attribrute if you iterate over it using OOopy for example: Sorry about that, I meant if the text attribute is None, but there *is* some text. Anton -- http://mail.python.org/mailman/listinfo/python-list

Re: not quite 1252

2006-04-28 Thread Anton Vredegoor
Martin v. Löwis wrote: So if that is the case: What is the problem then? If you interpret the document as cp1252, and it contains \x93 and \x94, what is it that you don't like about that? In yet other words: what actions are you performing, what are the results you expect to get, and what

Re: not quite 1252

2006-04-27 Thread Anton Vredegoor
John Machin wrote: Firstly, this should be 'content.xml', not 'contents.xml'. Right, the code doesn't do *anything* :-( Thanks for pointing that out. At least it doesn't do much harm either :-| Secondly, as pointed out by Sergei, the data is encoded by OOo as UTF-8 e.g. what is '\x94' in

not quite 1252

2006-04-26 Thread Anton Vredegoor
I'm trying to import text from an open office document (save as .sxw and read the data from content.xml inside the sxw-archive using elementtree and such tools). The encoding that gives me the least problems seems to be cp1252, however it's not completely perfect because there are still

Re: not quite 1252

2006-04-26 Thread Anton Vredegoor
Fredrik Lundh wrote: Anton Vredegoor wrote: I'm trying to import text from an open office document (save as .sxw and read the data from content.xml inside the sxw-archive using elementtree and such tools). The encoding that gives me the least problems seems to be cp1252, however it's

Re: not quite 1252

2006-04-26 Thread Anton Vredegoor
Martin v. Löwis wrote: Not sure I understand the question. If you process data in cp1252, then \x94 and \x94 are legal characters, and the Python codec should support them just fine. Tell that to the guys from open-office. Anton -- http://mail.python.org/mailman/listinfo/python-list

Re: Looking for resources for making the jump from Java to Python easier and more productive

2006-04-22 Thread Anton Vredegoor
ToddLMorgan wrote: I'm just starting out with python, after having a long history with Java. I was wondering if there were any resources or tips from anyone out there in Python-land that can help me make the transition as successfully as possible? Perhaps you've made the transition yourself

Re: two generators working in tandem

2006-02-12 Thread Anton Vredegoor
Michael Spencer wrote: This returns an iterator that 'nests' an arbitrary number of sequences (odometer-style). def nest(*sequences): def _nest(outer, inner): for outer_item in outer: if not isinstance(outer_item, tuple): outer_item =

Re: Fast generation of permutations

2006-01-29 Thread Anton Vredegoor
Paul Rubin wrote: Cool, I'd still like to know why (13**5)-13 = C(52,5) other than by just doing the arithmetic and comparing the results. Maybe your tkinter script can show that. That seems to be very hard :-) Unless I'm missing something. Anton def noverk(n,k): return reduce(lambda

Re: Fast generation of permutations

2006-01-29 Thread Anton Vredegoor
Anton Vredegoor wrote: Paul Rubin wrote: Cool, I'd still like to know why (13**5)-13 = C(52,5) other than by just doing the arithmetic and comparing the results. Maybe your tkinter script can show that. That seems to be very hard :-) Unless I'm missing something. Like a factor seven

Re: Intro to Pyparsing Article at ONLamp

2006-01-29 Thread Anton Vredegoor
Paul McGuire wrote: There are two types of parsers: design-driven and data-driven. With design-driven parsing, you start with a BNF that defines your language or data format, and then construct the corresponding grammar parser. As the design evolves and expands (new features, keywords,

Re: Fast generation of permutations

2006-01-28 Thread Anton Vredegoor
Paul Rubin wrote: def deals(): for i in xrange(13**5): cards = [(i//p) % 13 for p in (1, 13, 169, 2197, 28561)] yield cards This gives hands like [0,0,0,0,1] and [0,0,0,1,0] which are permutations of one another. Below is a piece of code that avoids this.

Re: Intro to Pyparsing Article at ONLamp

2006-01-28 Thread Anton Vredegoor
Paul McGuire wrote: I just published my first article on ONLamp, a beginner's walkthrough for pyparsing. Please check it out at http://www.onlamp.com/pub/a/python/2006/01/26/pyparsing.html, and be sure to post any questions or comments. I like your article and pyparsing. But since you ask

Re: OT: excellent book on information theory

2006-01-22 Thread Anton Vredegoor
Paul Rubin wrote: signal processing, for example. Perhaps it could be improved by being more explicit about what the reader needs to know, and giving references to other books where the prerequisites can be found. There are lots of good explanations, graphs, diagrams and such things in the

Re: OT: excellent book on information theory

2006-01-21 Thread Anton Vredegoor
Paul Rubin wrote: The first few pages are a review of probability theory but I think they assume you've seen it before. The book's subject matter is more mathematical by nature than what most programmers deal with from day to day, and as such, the book is not for everyone. And so the cycle

Re: OT: excellent book on information theory

2006-01-20 Thread Anton Vredegoor
Terry Hancock wrote: On 19 Jan 2006 13:57:06 +0100 Anton Vredegoor [EMAIL PROTECTED] wrote: Some time ago I tried to 'sell' Python to a mathematician. The crucial point was that it was not (in standard Python) possible to have a matrix A and a matrix B and then do for example

Re: Sudoku solver: reduction + brute force

2006-01-20 Thread Anton Vredegoor
ago wrote: [Something I mostly agree with] According to Anton the number of possible solutions can be reduced using 1) number swapping, 2) mirroring, 3) blocks/rows/columns swapping. All those operations create equivalent matrices. For a 9X9 grid, this should give a reduction factor =

Re: OT: excellent book on information theory

2006-01-19 Thread Anton Vredegoor
Paul Rubin wrote: For an absolutely amazing translation feat, try Michael Kandel's Polish-to-English translation of Stanislaw Lem's The Cyberiad. Returning to the original book, why did they write a lot of it (at least the first few pages until I gave up, after having trouble understanding

Re: OT: excellent book on information theory

2006-01-19 Thread Anton Vredegoor
Juho Schultz wrote: Last month I spent about an hour trying to explain why a*2.5e-8 = x raises a SyntaxError and why it should be written x = a*2.5e-8 The guy who wrote the 1st line has MSc in Physics from Cambridge (UK). In mathematics, there is no difference between the two lines. Some

  1   2   >