Re: Nufox : Xul + Python

2005-10-01 Thread bearophileHUGS
Nufox seems a really interesting thing (probably it can even be used to design GUIs for local desktop apps), but the site seems down at the moment. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Nufox : Xul + Python

2005-10-02 Thread bearophileHUGS
It doesn't work yet, to me... bearophile -- http://mail.python.org/mailman/listinfo/python-list

Multiple assignments simplification

2005-10-12 Thread bearophileHUGS
The current version of ShedSkin (http://shedskin.sourceforge.net/ experimental Python to C++ compiler) is rather alpha, and the development work is focused on debugging and implementing some more basic Python functionality. But hopefully in future versions more work will be spent to make the result

Re: Multiple assignments simplification

2005-10-13 Thread bearophileHUGS
Thank you George Sakkis for your fast and accurate answer. In my life I am encountering lot of graph-based solutions to my problems. I'll try to implement your solution as soon as possible. Fredrik Lundh>working on a Python to C/C++ translator without knowing what kind of optimizations a C/C++ co

Re: Adding methods to an object

2005-10-13 Thread bearophileHUGS
This isn't code of mine, it's probably from the cookbook, maybe with little changes: | def addMethod(object, method, name=None): | if name is None: name = method.func_name | class newclass(object.__class__): | pass | setattr(newclass, name, method) | object.__class__ = newc

Some set operators

2005-10-15 Thread bearophileHUGS
Sometimes I suggest to add things to the language (like adding some set methods to dicts), but I've seen that I tend to forget the meaning of six set/frozenset operators: s & t s &= t s | t s |= t s ^ t s ^= t My suggestion is to remove them, and keep them only as explicit non-operator version

Re: List of strings to list of floats ?

2005-10-17 Thread bearophileHUGS
Erik Max Francis: >result = [sqrt(x**2 + y**2) for x, y in zip(xs, ys)] Another possibility: from math import hypot result = [hypot(*xy) for xy in zip(xs, ys)] Or better: from math import hypot result = map(hypot, xs, ys) bearophile -- http://mail.python.org/mailman/listinfo/python-list

Syntax across languages

2005-10-23 Thread bearophileHUGS
This post comes from a boring morning, if you are busy ignore this. This post is only for relaxed people. I've found this page, "Syntax Across Languages", it contains many errors and omissions, but it's interesting. http://merd.sourceforge.net/pixel/language-study/syntax-across-languages.html Com

Re: Syntax across languages

2005-10-23 Thread bearophileHUGS
Thank you for the comments, Fredrik Lundh. >(that's (mostly) CPython-dependent, and should be avoided)< Then a non CPython-dependent way of doing it can be even more useful. >sure looks like four possible outcomes.< Right (but to me four explicit answers seem better than three answers and an e

Re: Syntax across languages

2005-10-23 Thread bearophileHUGS
Thank you Fredrik Lundh for showing everybody that indeed lot of people feel the need of such function in Python too. >to create a generic version, you have to decide which sequences to treat like >sequences< In my version I give the function some parameter(s) to define what I want to flatten. I

Re: System tray Icon

2005-10-23 Thread bearophileHUGS
Questo non e' sufficiente, ma puo' essere un punto di partenza: http://www.pycode.com/modules/?id=2&tab=download Bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Syntax across languages

2005-10-23 Thread bearophileHUGS
Thank you for all the answers, some people have already answered for me about most details I don't agree :-) Mike Meyer>Rexx has a global control that lets you set the number of digits to be considered significant in doing an FP equality test.< Mathematica too, I think. Tom Anderson>There are a

MSH (shell)

2005-10-27 Thread bearophileHUGS
This can be of little interest of some people here, but I think it can be interesting enough to justify a post. An article on the Microsoft Command Shell: http://arstechnica.com/guides/other/msh.ars (Its syntax is rather Python-like, but Py syntax seems better to me, even taking into account that

Re: how to discard a line if it's not a number?

2005-10-29 Thread bearophileHUGS
This is a possible solution, using exceptions: fileName = "data" out = file(fileName + "_filt.txt", "w") for line in file(fileName + ".txt"): try: nline = float(line) except ValueError: pass else: out.write(str(nline) + "\n") out.close() If the file is small en

Re: How do I sort these?

2005-10-30 Thread bearophileHUGS
# This can be a solution: from operator import itemgetter seq1a = ([2] * 4) + ([1] * 4) seq2a = [complex(3-el,7-el) for el in range(1, 9)] assert len(seq1a) == len(seq2a) print seq1a, seq2a, "\n" mix = zip(seq1a, seq2a) # mix.sort() # Not possible mix.sort(key=itemgetter(0)) # If you need tuples

Re: Python's website does a great disservice to the language

2005-11-01 Thread bearophileHUGS
Grant Edwards wrote: > May God save us from "professional" looking web sites. > I like the Python web site. It's simple, easy to read, and easy to > use. I strongly agree with you, the web is full of web sites that are nice "looking" but have microscopic fixed fonts (against the very spirit of Ht

Re: Python's website does a great disservice to the language

2005-11-01 Thread bearophileHUGS
CppNewB>and maybe a readable default font is in order.< That font looks fine to me, maybe there's a problem in the default font of your browser, you can probably fix your problem... Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Burrows-Wheeler (BWT) Algorithm in Python

2005-11-03 Thread bearophileHUGS
Michael J. Fromberger: > I can send you > a Python implementation I wrote, if you like; but if you're interested > in better understanding how the transform works, I would recommend you > try writing your own implementation. I'd like to see it, if you want you can put it somewhere or send it direc

Re: help make it faster please

2005-11-10 Thread bearophileHUGS
This can be faster, it avoids doing the same things more times: from string import maketrans, ascii_lowercase, ascii_uppercase def create_words(afile): stripper = """'[",;<>{}_&?!():[]\.=+-*\t\n\r^%0123456789/""" mapper = maketrans(stripper + ascii_uppercase, " "*le

Re: help make it faster please

2005-11-12 Thread bearophileHUGS
Thank you Bengt Richter and Sybren Stuvel for your comments, my little procedure can be improved a bit in many ways, it was just a first quickly written version (but it can be enough for a basic usage). Bengt Richter: >good way to prepare for split Maybe there is a better way, that is putting in

Re: Iterator addition

2005-11-12 Thread bearophileHUGS
Tom Anderson: > And we're halfway to looking like perl already! Perhaps a more pythonic > thing would be to define a "then" operator: > all_lines = file1 then file2 then file3 Or a "chain" one: > all_lines = file1 chain file2 chain file3 Bearophile -- http://mail.python.org/mailman/listinfo/pyt

D foreach

2005-11-13 Thread bearophileHUGS
The Digital Mars D compiler is a kind of "improved c++", it contains a "foreach" statement: http://www.digitalmars.com/d/statement.html#foreach Usage example: foreach(int i, inout int p; v1) p = i; Is equal to Python: for i in xrange(len(v)): v[i] = i That is: v1 = range(len(v1)) (Some people us

Py 3.0 print

2005-11-17 Thread bearophileHUGS
There is/was a long discussion about the replacement for print in Python 3.0 (I don't know if this discussion is finished): http://mail.python.org/pipermail/python-dev/2005-September/055968.html There is also a wiki page that collects the ideas: http://wiki.python.org/moin/PrintAsFunction There i

Re: Underscores in Python numbers

2005-11-19 Thread bearophileHUGS
Steven D'Aprano: > Perhaps Python should concatenate numeric literals at compile time: > 123 456 is the same as 123456. I think using the underscore it is more explicit: n = 123_456 Alternatively the underscore syntax may be used to separate the number from its base: 22875 == 22875_10 == 595b_16

Re: Underscores in Python numbers

2005-11-19 Thread bearophileHUGS
Roy Smith>We already have a perfectly good syntax for entering octal and hex integers, There is this syntax: 1536 == int("600", 16) that accepts strings only, up to a base of 36. There are the hex() and oct() functions. There is the %x and %o sintax, that isn't easy to remember. There are the 0x60

Re: Underscores in Python numbers

2005-11-20 Thread bearophileHUGS
Peter Hansen>Or maybe one should instead interpret this as "numeric literals need more bells and whistles, and I don't care which of these two we add, but we have to do *something*!". :-) The purpose of my words was: when you think about adding a new syntax/functionality to a language, you have to

Mixed types and variants

2005-11-23 Thread bearophileHUGS
Notes: - This email is about Mark Dufour's Shed Skin (SS) (http://shed-skin.blogspot.com), but the errors/ingenuousness it contains are mine. My experience with C++ is limited still. - The following code comes from a discussion with Mark. One of the purposes of SS is to produce fast-running progr

Re: Computer Language Shootout

2005-11-29 Thread bearophileHUGS
This is a direct translation of the D code, maybe it's not the faster Python implementation, and surely it's not the shorter one. But Psyco makes it much faster (Psyco likes "low level" style code). ShedSkink is (almost) able to compile it too, producing a really fast executable (with some "smart a

Re: Computer Language Shootout

2005-11-30 Thread bearophileHUGS
malv: >Hi bearophileH, bearophile is enough :-) >Could you post some more information about ShedSkink? ShedSkin (SS) is a Python -> C++ compiler (or translator) written in Python, created by Mark Dufour. Its development was initially "financed" by the summer of code by Google. It contains some

Re: ANN: Dao Language v.0.9.6-beta is release!

2005-12-01 Thread bearophileHUGS
>From "An Introduction to Dao": >So I realized the goodness of scripting languages, and spent about two weeks >to write some Perl scripts to retrieve informa- tion from GO and construct the >DAG. But that experience with Perl was not very nice, because of its >complicated syntax. Then I started

Re: for x in list that maximizes f(x)] <--newbie help

2005-12-01 Thread bearophileHUGS
If the elements of mylist can be compared (es. not complex values), then this can be a solution for you: from math import sin as f mylist = [float(2*i)/10 for i in xrange(10)] pairs = [(f(x), x) for x in mylist] ymax = max(pairs)[1] print pairs, "\n" print ymax You can also try this, for Py2.4: p

str attributes

2005-12-06 Thread bearophileHUGS
I don't know if this was already discussed. I think that maybe Python 2.5 can add some attributes to the str object: >>> str.ascii_letters 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' >>> str.hexdigits '0123456789abcdefABCDEF' etc. And maybe this too: str.maketrans(from, to) (I think s

Re: Other notes

2005-01-05 Thread bearophileHUGS
Thank you to all the gentle people that has given me some comments, and sorry for bothering you... Doug Holton: >This will also likely never appear in Python. I know, that's why I've defined it "wild". >Also, you might request the NetLogo and StarLogo developers to support Jython (in addition

Re: generator expressions: performance anomaly?

2005-01-16 Thread bearophileHUGS
Nick Coghlan: >There's a similar performance glitch associated with constructing a tuple from a generator expression (with vanilla 2.4, detouring via list is actually faster) You look right: .from time import clock .print "[x for x in l], list(x for x in l), aux = list(x for x in l); tuple(aux),

set, dict and other structures

2005-01-31 Thread bearophileHUGS
I'm frequently using Py2.4 sets, I find them quite useful, and I like them, even if they seem a little slower than dicts. Sets also need the same memory of dicts (can they be made to use less memory, not storing values? Maybe this requires too much code rewriting). I presume such sets are like this

Re: set, dict and other structures

2005-01-31 Thread bearophileHUGS
You are really gentle Raymond Hettinger, but surely I'm not asking you/anyone to write some code just for me; I don't have "real applications", I'm just learning/playing. Your words are quite good answers to most of my questions. The only left small topic is about the group/set-like operations/meth

Re: set, dict and other structures

2005-02-02 Thread bearophileHUGS
Leif K-Brooks: >They look exactly the same speed-wise to me: There's a little overhead, you can see it with a bigger test: .from time import clock .n = 1*10**6 . .t1 = clock() .d = set() .for i in xrange(n): . d.add(i) .t2 = clock() .for i in xrange(n): . d.remove(i) .t3 = clock() .d = set(xra

Re: set, dict and other structures

2005-02-02 Thread bearophileHUGS
r = {} for x in a: if x not in b: r[x] = r[a] for x in b: if x not in a: r[x] = r[b] I know, this is wrong :-] This looks better: r = {} for x in a: if x not in b: r[x] = a[x] for x in b: if x not in a: r[x] = b[x] Bearophile -- http://mail.python.org/mailman/listinfo/python-list

Spaces and tabs again

2005-08-13 Thread bearophileHUGS
Hello, I know this topic was discussed a *lot* in the past, sorry if it bores you... >From the Daily Python-URL I've seen this interesting Floating Point Benchmark: http://www.fourmilab.ch/fourmilog/archives/2005-08/000567.html This is the source pack: http://www.fourmilab.ch/fbench/fbench.zip I

Re: Please Criticize My Code

2005-08-20 Thread bearophileHUGS
Two versions of mine, one of the fastest (not using Psyco) and one of the shortest: . from itertools import groupby . . def audioactiveFast(n): . strl = {("1","1","1"): "31", ("1","1"): "21", ("1",): "11", . ("2","2","2"): "32", ("2","2"): "22", ("2",): "12", . ("3","3"

Re: Bug in string.find

2005-08-28 Thread bearophileHUGS
I agree with Bryan Olson. I think it's a kind of bug, and it has to be fixed, like few other things. But I understand that this change can give little problems to the already written code... Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Command config, quitting, binary, Timer

2005-09-03 Thread bearophileHUGS
Hello, I have four things to ask or to suggest, sorry if they seem basic or already discussed. --- I am still ignorant about Tkinter. This little program, after pressing the "Go" eats more and more RAM, is it normal? Can it be avoided? (In normal programs this is isn't a real prob

Re: Command config, quitting, binary, Timer

2005-09-04 Thread bearophileHUGS
Witn your suggestions and with some tests and work I've solved most of the problems, thank you all for the comments. Peter Hansen: >What did you expect to happen with the infinite loop inside dogo()?< I expected that the same memory used by the b.config(command=...) can be used by the successive

Re: Command config, quitting, binary, Timer

2005-09-06 Thread bearophileHUGS
Dennis Lee Bieber: >Yes, but only when ref-counts go to 0... it may be that this tight loop never >allowed stuff to go to 0 ref-counts. It definitely never returned control, so >besides eating memory that way, any events for the GUI framework were also not >being handled and had to be queued.<

Re: Command config, quitting, binary, Timer

2005-09-06 Thread bearophileHUGS
Bearophile>This can be fixed with a different dictionary that doesn't contain the leading 0s,< No other dict is necessary: ! _nibbles = {"0":"", "1":"0001", "2":"0010", "3":"0011", ! "4":"0100", "5":"0101", "6":"0110", "7":"0111", ! "8":"1000", "9":"1001", "A":"1010",

Re: sorting tuples...

2005-09-17 Thread bearophileHUGS
Uhm, if the file is clean you can use something like this: data = """\ 200501221530 John *** long string here *** 200504151625 Clyde *** clyde's long string here *** 200503130935 Jeremy *** jeremy string here """ records = [rec.split("\n") for rec in data.split("\n\n")] records.sort() print

C#3.0 and lambdas

2005-09-18 Thread bearophileHUGS
On Slashdot there is a discussion about the future C#3.0: http://developers.slashdot.org/developers/05/09/18/0545217.shtml?tid=109&tid=8 http://msdn.microsoft.com/vcsharp/future/ There are many differences, but it looks a bit more like Python: http://download.microsoft.com/download/9/5/0/9503e33e

Re: graph visualisation

2005-02-08 Thread bearophileHUGS
This isn't a visualisation routine, but it contains some of them, and with few mod you can adapt them for your needs: http://gato.sourceforge.net/ Gato - the Graph Animation Toolbox - is a software which visualizes algorithms on graphs. Bearophile -- http://mail.python.org/mailman/listinfo/pyt

Re: lambda and for that matter goto not forgetting sugar

2005-02-11 Thread bearophileHUGS
Nick Coghlan wrote: > Anyway, check out AlternateLambdaSyntax on the python.org Wiki It's an interesting page: http://www.python.org/moin/AlternateLambdaSyntax Some days ago I suggested something different: maybe def can become a function, then it can work as lambda (and still as the old def) too.

Re: builtin functions for and and or?

2005-02-13 Thread bearophileHUGS
In Python there are so many ways to do things... This looks like another one, I haven't tested it: not False in imap(pred, iterable) As usual tests are required to measure the faster one. I agree with Roose, there are are some "primitive" operations (like this, and flatten, partition, mass remova

Graph

2005-02-18 Thread bearophileHUGS
This is the first version of the graph module I was developing... In the meantime I've seen that there are already lots of graph implementations, even a compiled one: ftp://xray.imsb.au.dk/pub/python/packages/Python2.1/RPMS/python-kjbuckets-2.2-7.i686.rpm (This makes my work less important, but it

Re: exercise: partition a list by equivalence

2005-02-19 Thread bearophileHUGS
David Eppstein: > However it might be easier to treat the input pairs as the edges of a > graph and apply a depth-first-search based graph connected components > algorithm. || This would be O(n), though. Is the DFS the best one here (instead of BFS)? With the graph implementation that I've just s

Re: exercise: partition a list by equivalence

2005-02-19 Thread bearophileHUGS
Bearophile: > I presume the complexity is O(n+a); n (the nodes) > is proportional to the number of pairs, and a > (the arcs) depends on the "intricacy" of the input pairs. Opps... n (the number of nodes) is the number of different numbers contained in the pairs :-] Bearophile -- http://mail.pyt

Re: exercise: partition a list by equivalence

2005-02-19 Thread bearophileHUGS
John Machin>FWIW, here's a brief UAT report: Here is something else for you. Note: for more correct comparisons, for the following tests I've disabled the use of Psyco in Graph (usually enabled, if present). This looks faster than merge2 for this (quite sparse) random pairs test: . import graph #

Re: exercise: partition a list by equivalence

2005-02-20 Thread bearophileHUGS
John Machin: >Perhaps I'm missing a posting of yours -- what are merge2 and merge4? What is "this random pairs test"? What is xMax (nPairs isn't hard to guess), and how are you generating your input data?< merge2 and this random pairs test comes from the post by Brian Beck. merge4 is the first in

Re: Real-Time Fluid Dynamics for Games...

2005-02-20 Thread bearophileHUGS
Your two email addresses bouce emails back, so I post a shortened version of my comment here. I haven't installed: PyOpenGL-2.0.2.01.py2.4-numpy23 glut-3.7.6 Therefore at the moment I cannot try your interesting code. What's the speed of this Python code on your computer? I'd like to see a screensh

Re: intersection of 2 list of pairs

2005-02-22 Thread bearophileHUGS
The use of frozenset can okay when sub-sequences are longer, but for this problem it's slow, and anyway there are situations of repeated data like this that have to be considered: frozenset( ('a', 'a') ) ==> frozenset(['a']) For Py2.4 the faster and better solution seems Peter Otten one. James St

Jigsaw solver

2005-03-01 Thread bearophileHUGS
This can be interesting: http://science.slashdot.org/science/05/03/01/2340238.shtml Bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Is there a short-circuiting dictionary "get" method?

2005-03-09 Thread bearophileHUGS
Maybe this can help: value = d.get('x', lambda: bigscaryfunction()) Bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Itertools wishlists

2005-03-13 Thread bearophileHUGS
Thank you for your very good and interesting answer Raymond. In the Itertool library there are functions not really simple to use/remember, but a flatten() and a partition() can probably be easy to remember (your window() function is probably a sliding window, so it's not a partition(), I presume).

Re: Itertools wishlists

2005-03-14 Thread bearophileHUGS
Thank you for your answers, Raymond Hettinger. >The options also suggest that the abstraction is not as basic or universal as we would hope.< I don't understand, but this is normal. > ll = open("namefile").read().split() > r = partition(map(float, ll), 4) >If you need that to be flattened one

Re: code for Computer Language Shootout

2005-03-16 Thread bearophileHUGS
Michael Spencer's version is nice, this is a bit shortened version. The main() isn't useful for this very short loop, and you can use shorter variable names to make lines shorter (this code isn't much readable, it's just for the Shootout, "production quality" code has probably to be more readable.

Re: list of unique non-subset sets

2005-03-17 Thread bearophileHUGS
s1 = set(['a','b','c']) s2 = set(['a','c']) s3 = set(['a','d','e','f']) s4 = set(['r','k','l']) s5 = set(['r','k','l']) ls = [s1,s2,s3,s4,s5] result1 = [s1, s3, s5] A result can contain s4 or s5 at random. This problem looks like the one of searching the correct hyperedges for a hypergraph. s1-5 a

Re: list of unique non-subset sets

2005-03-18 Thread bearophileHUGS
Looking at all the hyperedges in the connected component is a big waste... You can look at just the hyperedges that share one or more nodes. (Nodes are the original letters contained in the sets, and they must be hashable). If nodes aren't integers in [0, len(l)) then you can use this simpler code

Google's MapReduce

2004-12-08 Thread bearophileHUGS
(This Google article suggestion comes from the CleverCS site): http://labs.google.com/papers/mapreduce-osdi04.pdf "MapReduce is a programming model and an associated implementation for processing and generating large data sets. Users specify a map function that processes a key/value pair to gener

Recursive structures

2004-12-20 Thread bearophileHUGS
(This is a repost from another python newsgroup). While using some nested data structures, I've seen that I'd like to have a function that tells me if a given data structure contains one or more cyclic references (a way to recognise a cycle in a graph is to do a depth-first search, marking vertices

Re: Recursive structures

2004-12-20 Thread bearophileHUGS
Thank you very much Thomas Güttler for you quick answer, but I think your program doesn't contain an algorithm to spot cycles (like the usual cyclic graph algorithm). In my first post there was an assert to spot this problem: l = [0] m = [l, l] print m print isrecursive(m) Gives: [[0], [0]] 1 m

Re: Recursive structures

2004-12-20 Thread bearophileHUGS
Leif K-Brooks: >http://python.org/doc/current/lib/module-pprint.html#l2h-749 Thank you very much, I see that the function is already there, even with the same name :-) I've seen that it doesn't work for all my tests, like this one with n = 3000: from pprint import isrecursive from time import cl

Optional Static Typing

2004-12-23 Thread bearophileHUGS
Adding Optional Static Typing to Python looks like a quite complex thing, but useful too: http://www.artima.com/weblogs/viewpost.jsp?thread=85551 I have just a couple of notes: Boo (http://boo.codehaus.org/) is a different language, but I like its "as" instead of ":" and "->", to have: def min(a

Re: Optional Static Typing

2004-12-23 Thread bearophileHUGS
Doug Holton: >And there are some disadvantages to doing it this way. >It means Python is more flexible to use than Boo, I've just suggested the *syntax* that I like more. Bye, Bearophile -- http://mail.python.org/mailman/listinfo/python-list

Other notes

2004-12-28 Thread bearophileHUGS
Here are some questions and suggestions of mine that I've collected in the last weeks on the language (please note that some (most?) of them are probably wrong/useless/silly, but I've seen that such notes help me understand a lot of things and to find my weak spots.) 1) I've seen that list pop/app

Re: Pre-PEP: Dictionary accumulator methods

2005-03-22 Thread bearophileHUGS
R.H.: > The setdefault() method would continue to exist but > would likely not make it into Py3.0. I agee to remove the setdefault. I like the new count method, but I don't like the appendlist method, because I think it's too much specilized. I too use sets a lot; recently I've suggested to add

English to a bit of code

2005-03-24 Thread bearophileHUGS
It's still a toy, but it looks interesting. It converts in "Python, Lisp and Java", and the shown image looks like Python: http://www.trnmag.com/Stories/2005/032305/Tool_turns_English_to_code_032305.html Google cache for a draft about it: http://www.google.com/search?q=http%3A%2F%2Fweb.media.mit.

Re: String Splitter Brain Teaser

2005-03-28 Thread bearophileHUGS
This is shorter: map(list,' '.join(s).replace(' / ','').split()) but for very long genomes Michael Spencer's nice version can be faster. Hugs, Bearophile -- http://mail.python.org/mailman/listinfo/python-list

Suggesting methods with similar names

2005-03-30 Thread bearophileHUGS
I have a class Surface with many methods. Working in the interactive window I receive an error like this when I write the wrong method name: >>> table.addGlas() Traceback (most recent call last): File "", line 1, in ? AttributeError: 'Surface' object has no attribute 'addGlas' Is it possibile t

Re: Suggesting methods with similar names

2005-03-30 Thread bearophileHUGS
Thank you, __getattr__ does what I need :-) A smart help can be designed easely... Bear hugs, Bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Suggesting methods with similar names

2005-03-30 Thread bearophileHUGS
Raymond Hettinger>When you're done, consider posting the result as an ASPN cookbook recipe.< I still cannot write in the cookbook... I think I have problems with the registration. So you can put it there... I've found that difflib is good enough for the string matching. This idea isn't fully mine,

Re: Suggesting methods with similar names

2005-03-30 Thread bearophileHUGS
Diez B. Roggisch>it will make an object return always _something_ - and thus you don't catch misspellings in non-interactive< Uhm, I'm sorry, I don't understand you. If you look at the code I've just posted, you can see that it still raises AttributeError, the difference is just the error message.

Re: unittest vs py.test?

2005-04-01 Thread bearophileHUGS
Nigel Rowe>Have you seen Grig Gheorghiu's 3 part comparison of unittest, and py.test?< Very interesting articles, thank you. Testing seems something still in quick development. For small functions the doctests are useful, but py.test has some advantages. Probably something even better that py.tes

Re: Suggesting methods with similar names

2005-04-01 Thread bearophileHUGS
Suggesting method names based on a wrong method name can be useful, but I think the "smart help" can be improved: it can also be useful to have a suggestion for method names on the basis on a short description (or keywords) about what I want to do to/with the object. Maybe some people here can give

Pseudocode in the wikipedia

2005-04-01 Thread bearophileHUGS
The free wikipedia is adopting a standard pseudocode: http://en.wikipedia.org/wiki/Wikipedia_talk:Wikicode/Specification MShonle says something nice: I support the idea of wikicode. Basically I think we should present code in a Python-like language that doesn't carry so much baggage. For example,

Re: Suggesting methods with similar names

2005-04-02 Thread bearophileHUGS
Is that last idea so stupid? Still, I'd like to know if you know some little Python search engines for such purpose. Thank you, Bearophile -- http://mail.python.org/mailman/listinfo/python-list

On slashdot

2005-04-03 Thread bearophileHUGS
There is a discussion about "Python Moving into the Enterprise" on Slashdot: http://it.slashdot.org/it/05/04/03/0715209.shtml?tid=156&tid=8 Bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: sorting a list and counting interchanges

2005-04-07 Thread bearophileHUGS
Tim's solution is very nice, it comes from basic things often taught in good computer science courses. In Python when you have to do many (-1)**n you can do: (1-2*(n%2)) This seems quite faster. Bearophile -- http://mail.python.org/mailman/listinfo/python-list

Smart help again

2005-04-10 Thread bearophileHUGS
Hello, here I extend the idea of the smart help I've discussed recently. When I receive an error like: TypeError: fun() takes exactly 2 arguments (1 given) I'd also like to see that method/function parameters (or the first line of its docstring). >From a discussion with gentle programmers in anot

Re: Smart help again

2005-04-11 Thread bearophileHUGS
>You can create your own Exception class, based on this recipe:< Thank you for your answer, the recipe you have suggested gives a very big output, but it doesn't contain what I've asked for... :-) I was asking to see that faulty method/function parameters (or the first line of its docstring). Prob

Re: recording data between [ and ]

2005-04-21 Thread bearophileHUGS
Diez B. Roggisch>But as the world is complex and people want solutions to their complex problems, IMHO programming will always be about such nitty gritty details.< REs are like assembly, but high-level languages show us that for a mammal there are (often) better (higher) ways to program a computer

Re: Bounding box on clusters in a 2D list

2005-04-23 Thread bearophileHUGS
I hope this is what you need, sometimes understanding the question is one of the hardest parts :-) If you can use a graph data structure, you can create a graph, and then you can find the lenght of all its connected components (indentations reduced to 2 spaces): . def mat2graph(g, m, good=None, w

Re: Bounding box on clusters in a 2D list

2005-04-24 Thread bearophileHUGS
[EMAIL PROTECTED]: > hi Bearphile! That really gives me an idea.Thanks much for that. Yes as > you said the algorithm reaches a maximium recursion depth for larger > sets i tried. You can improve the little flood filling function, avoiding the "bad" Python recursivity. > Do you see where I am he

Re: Bounding box on clusters in a 2D list

2005-04-25 Thread bearophileHUGS
In my first post you can find two URLs with better flood filling algorithms. You can also modify the easy recursive function, using a list-based stack intead of recursive calls. Bye, Bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Bounding box on clusters in a 2D list

2005-04-25 Thread bearophileHUGS
Then you can probably use something like this: . def boxesArea(m, foreground=1, background=0): . maxr = len(m) . maxc = len(m[0]) . newCol = 2 . oldCol = foreground . for r,row in enumerate(m): . for c,e in enumerate(row): . if e == oldCol: .

Re: large dictionary creation takes a LOT of time.

2005-04-29 Thread bearophileHUGS
Ville Vainio: > This is a good place to use 'get' method of dict: > frequency[word] = frequency.get(word,0) + 1 I think Kent Johnson is longer, but a bit faster... Bye, Bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Sorting an Edge List

2005-04-29 Thread bearophileHUGS
Anthony D'Agostino, this is my first raw version, it can fail in lots of ways depending on your input list l (and surely there are better ways to do it), but it's a start: . l = [('A','Y'), ('J','A'), ('Y','J')] . pairs = dict(l) . result = [] . key = pairs.iterkeys().next() . while pairs: . v

Syntax and speed

2005-12-12 Thread bearophileHUGS
ShedSkin (http://shed-skin.blogspot.com) has taught me something: simple syntax and high speed can often go together, in a computer language. This means two things: 1) A "fast language" can have a simple (python-like) syntax. For example a language fast as C++ can allow: d = {"hello":1} as a synt

Online Ruby

2005-12-14 Thread bearophileHUGS
Maybe a page like this for Python exists already, or it can be useful to create it: http://tryruby.hobix.com/ Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: special operator =+

2005-12-15 Thread bearophileHUGS
kenny Nguyen>Does anyone know the operator "=+"? It isn't an operator, it's equivalent to = (assignment) only. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Guido at Google

2005-12-22 Thread bearophileHUGS
This is interesting. With more Python time in Guido's hands maybe Py 3.0 is a bit closer... :-) I don't know if this is a silly idea: A small part of the wealth of a modern state is probably determined by the software it uses/produces, and a small part of this software is open source or free. This

Re: Guido at Google

2005-12-23 Thread bearophileHUGS
This topic is discussed on Slashdot too: http://slashdot.org/articles/05/12/22/1832226.shtml?tid=217 There are some interesting comments, for example from curious Java or Perl programmers, etc. Some of them can probably appreciate this: http://cheeseshop.python.org/pypi/typecheck Among the noise

Re: GUI and graph

2005-12-23 Thread bearophileHUGS
Maybe this graph library can be useful to you: http://sourceforge.net/projects/pynetwork/ Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Distributions, RE-verb and the like

2005-12-29 Thread bearophileHUGS
Psyco is finished now, and it works on the x86, for Win, the new macs, many linux boxes, etc, and it's quite useful, so maybe it can be added to the standard Python distribution. PyChecker (and the other similar ones that work differently) is very useful too, and it's pure Python, so maybe it too

  1   2   3   4   5   6   7   8   9   10   >