Re: Why less emphasis on private data?

2007-01-08 Thread Andrea Griffini
Steven D'Aprano wrote: > That is total and utter nonsense and displays the most appalling > misunderstanding of probability, not to mention a shocking lack of common > sense. While I agree that the programming job itself is not a program and hence the "consider any possibility" simply doesn't mak

Re: Why less emphasis on private data?

2007-01-07 Thread Andrea Griffini
Bruno Desthuilliers wrote: >> ... and on >> the opposite I didn't expect that fighting with object >> leaking in complex python applications was that difficult >> (I've heard of zope applications that just gave up and >> resorted to the "reboot every now and then" solution). >> > Zope is a specia

Re: Why less emphasis on private data?

2007-01-07 Thread Andrea Griffini
Paul Rubin wrote: > Yes I've had plenty of > pointer related bugs in C programs that don't happen in GC'd > languages, so GC in that sense saves my ass all the time. My experience is different, I never suffered a lot for leaking or dangling pointers in C++ programs; and on the opposite I didn't

Re: Pythonic style involves lots of lightweight classes (for me)

2006-12-14 Thread Andrea Griffini
user = Record(name="Andrea Griffini", email="[EMAIL PROTECTED]") and then access the fields using user.name syntax HTH Andrea -- http://mail.python.org/mailman/listinfo/python-list

Re: Inconsistency in dictionary behaviour: dict(dict) not calling __setitem__

2006-12-12 Thread Andrea Griffini
Mitja Trampus wrote: ... > At least, I know it surprised me when I first met this behavior. Or is > my reasoning incorrect? Why len() doesn't call iteritems() ? :-) Kidding apart for example it would be ok for __setitem__ to call either an internal "insert_new_item" or "update_existing_item" de

Re: Lookup caching

2006-12-12 Thread Andrea Griffini
MRAB wrote: ... > What are you using for the timestamp? Are you calling a function to > read a timer? For timestamp I used a static variable; to update the timestamp for a dictionary I used d->timestamp = ++global_dict_timestamp; I'm using a single counter for all dicts so that when doi

Re: Lookup caching

2006-12-11 Thread Andrea Griffini
Gabriel Genellina wrote: > At Saturday 9/12/2006 23:04, Andrea Griffini wrote: > >> I implemented that crazy idea and seems working... in its >> current hacked state can still pass the test suite (exluding > > What crazy idea? And what is this supposed to do? > The

Lookup caching

2006-12-09 Thread Andrea Griffini
Hello, I implemented that crazy idea and seems working... in its current hacked state can still pass the test suite (exluding the tests that don't like self generated output on stdout from python) and the stats after the quicktest are IMO impressing: LOAD_GLOBAL = 13666473 globals miss = 58988 bu

Re: merits of Lisp vs Python

2006-12-09 Thread Andrea Griffini
Alex Mizrahi wrote: ... > so we can see PyDict access. moreover, it's inlined, since it's very > performance-critical function. > but even inlined PyDict access is not fast at all. ma_lookup is a long and > hairy function containing the loop. I once had a crazy idea about the lookup speed prob

Re: Unicode/ascii encoding nightmare

2006-11-07 Thread Andrea Griffini
John Machin wrote: > Indeed yourself. What does the above mean ? > Have you ever considered reading posts in > chronological order, or reading all posts in a thread? I do no think people read posts in chronological order; it simply doesn't make sense. I also don't think many do read threads com

Re: Unicode/ascii encoding nightmare

2006-11-06 Thread Andrea Griffini
John Machin wrote: > The fact that C3 and C2 are both present, plus the fact that one > non-ASCII byte has morphoploded into 4 bytes indicate a double whammy. Indeed... >>> x = u"fødselsdag" >>> x.encode('utf-8').decode('iso-8859-1').encode('utf-8') 'f\xc3\x83\xc2\xb8dselsdag' Andrea -- http

Re: Name bindings for inner functions.

2006-10-28 Thread Andrea Griffini
[EMAIL PROTECTED] wrote: > The following code: > > def functions(): > l=list() > for i in range(5): > def inner(): > return i > l.append(inner) > return l > > > print [f() for f in functions()] > > > returns [4,4,4,4,4], rather than the hoped for [0,1,2,

Re: Where do nested functions live?

2006-10-28 Thread Andrea Griffini
Fredrik Lundh wrote: > Ben Finney wrote: > >> If you want something that can be called *and* define its attributes, >> you want something more complex than the default function type. Define >> a class that has a '__call__' attribute, make an instance of that, and >> you'll be able to access attrib

Re: Arrays? (Or lists if you prefer)

2006-10-22 Thread Andrea Griffini
Neil Cerutti wrote: > >>> b =[range(2), range(2)] I often happened to use b = [[0] * N for i in xrange(N)] an approach that can also scale up in dimensions; for example for a cubic NxNxN matrix: b = [[[0] * N for i in xrange(N)] for j in xrange(N)] Andrea -- htt

Re: Is Python a Zen language?

2006-02-26 Thread Andrea Griffini
I think that the classification has some meaning, even if of course any language has different shades of both sides. I'd say that with python is difficult to choose one of the two categories because it's good both as a pratical language and as a mind-opener language. IMO another language that woul

Re: How can I find the remainder when dividing 2 integers

2006-02-26 Thread Andrea Griffini
Writing a while loop with ++x to increment the index was the first mistake i made with python. "++x" unfortunately is valid, it's not a single operator but a double "unary plus" Andrea -- http://mail.python.org/mailman/listinfo/python-list

Re: Augmented assignment

2006-02-20 Thread Andrea Griffini
I think it heavily depends on what is "x". If x is bound to a mutable x=x+1 and x+=1 can not only have different speed but indeed can do two very unrelate things (the former probably binding to a new object, the latter probably modifying the same object). For example consider what happens with list

Re: Multiple assignment and the expression on the right side

2006-02-20 Thread Andrea Griffini
While I think that the paragraph is correct still there is IMO indeed the (low) risk of such a misunderstanding. The problem is that "the statement executes" can IMO easily be understood as "the statements execute" (especially if your background includes only languages where there's no multiple ass

Re: Wheel-reinvention with Python

2005-07-31 Thread Andrea Griffini
On Sun, 31 Jul 2005 02:23:39 -0700, Robert Kern <[EMAIL PROTECTED]> wrote: >Like PyGUI, more or less? > >http://www.cosc.canterbury.ac.nz/~greg/python_gui/ We ended up using (py)Qt, and it's a nice library but to my eyes is a lot un-pythonic. In many cases there are convoluted solutions that seem

Re: Folding in vim

2005-07-03 Thread Andrea Griffini
On Sun, 3 Jul 2005 22:42:17 -0500, Terry Hancock <[EMAIL PROTECTED]> wrote: >It seems to be that it isn't robust against files >with lots of mixed tabs and spaces. My suggestion is: - never ever use tabs; tabs were nice when they had a de-facto meaning (tabbing to next 8-space boundary) nowd

Re: Proposal: reducing self.x=x; self.y=y; self.z=z boilerplate code

2005-07-03 Thread Andrea Griffini
On Sat, 2 Jul 2005 03:04:09 -0700 (PDT), "Ralf W. Grosse-Kunstleve" <[EMAIL PROTECTED]> wrote: >Hi fellow Python coders, > >I often find myself writing:: > >class grouping: > >def __init__(self, x, y, z): >self.x = x >self.y = y >self.z = z >

Re: references/addrresses in imperative languages

2005-06-21 Thread Andrea Griffini
On 20 Jun 2005 23:30:40 -0700, "Xah Lee" <[EMAIL PROTECTED]> wrote: >Dear Andrea Griffini, > >Thanks for explaning this tricky underneath stuff. Actually it's the very logical consequence of the most basic rule about python. Variables are just pointers to values;

Re: references/addrresses in imperative languages

2005-06-20 Thread Andrea Griffini
On Sun, 19 Jun 2005 22:25:13 -0500, Terry Hancock <[EMAIL PROTECTED]> wrote: >> PS is there any difference between >> t=t+[li] >> t.append(li) > >No, but Yes, a big one. In the first you're creating a new list and binding the name t to it, in the second you're extending a list by adding one more

Re: Loop until condition is true

2005-06-18 Thread Andrea Griffini
On Sat, 18 Jun 2005 13:35:16 -, Grant Edwards <[EMAIL PROTECTED]> wrote: >AFAICT, the main use for do/while in C is when you want to >define a block of code with local variables as a macro: When my job was squeezing most out of the CPU (videogame industry) I remember that the asm code generat

Re: exceptions considered harmful

2005-06-18 Thread Andrea Griffini
On Fri, 17 Jun 2005 20:00:39 -0400, Roy Smith <[EMAIL PROTECTED]> wrote: >This sounds like a very C++ view of the world. In Python, for example, >exceptions are much more light weight and perfectly routine. The problem with exceptions is coping with partial updatd state. Suppose you call a comp

Re: What is different with Python ?

2005-06-18 Thread Andrea Griffini
On 18 Jun 2005 00:26:04 -0700, "Michele Simionato" <[EMAIL PROTECTED]> wrote: >Your position reminds me of this: > >http://www.pbm.com/~lindahl/real.programmers.html Yeah, but as I said I didn't use a TRS-80, but an Apple ][. But the years were those ;-) Andrea -- http://mail.python.org/mailman

Re: What is different with Python ?

2005-06-17 Thread Andrea Griffini
On 17 Jun 2005 21:10:37 -0700, "Michele Simionato" <[EMAIL PROTECTED]> wrote: >Andrea Griffini wrote: >> Why hinder ? > ... >To be able to content himself with a shallow knowledge >is a useful skill ;) Ah! ... I agree. Currently for example my knowledge of Zope

Re: What is different with Python ?

2005-06-17 Thread Andrea Griffini
On 17 Jun 2005 06:35:58 -0700, "Michele Simionato" <[EMAIL PROTECTED]> wrote: >Claudio Grondi: ... >>From my >>overall experience I infer, that it is not only possible >>but has sometimes even better chances for success, >>because one is not overloaded with the ballast of deep >>understanding whic

Re: What is different with Python ?

2005-06-17 Thread Andrea Griffini
On Fri, 17 Jun 2005 08:40:47 -0400, Peter Hansen <[EMAIL PROTECTED]> wrote: >And the fact that he's teaching C++ instead of just C seems to go >against your own theories anyway... (though I realize you weren't >necessarily putting him forth as a support for your position). He's strongly advocat

Re: What is different with Python ?

2005-06-17 Thread Andrea Griffini
On 17 Jun 2005 05:30:25 -0700, "Michele Simionato" <[EMAIL PROTECTED]> wrote: >I fail to see the relationship between your reply and my original >message. >I was complaining about the illusion that in the old time people were >more >interested in programming than now. Instead your reply is about l

Re: What is different with Python ?

2005-06-17 Thread Andrea Griffini
On 17 Jun 2005 01:25:29 -0700, "Michele Simionato" <[EMAIL PROTECTED]> wrote: >I don't think anything significant changed in the percentages. Then why starting from print "Hello world" that can't be explained (to say better it can't be *really* understood) without introducing a huge amount

Re: What is different with Python ?

2005-06-17 Thread Andrea Griffini
On Thu, 16 Jun 2005 07:36:18 -0400, Roy Smith <[EMAIL PROTECTED]> wrote: >Andrea Griffini <[EMAIL PROTECTED]> wrote: >> That strings in python are immutable it's surely >> just a detail, and it's implementation specific, >> but this doesn't means

Re: What is different with Python ?

2005-06-16 Thread Andrea Griffini
On Thu, 16 Jun 2005 10:30:04 -0400, "Jeffrey Maitland" <[EMAIL PROTECTED]> wrote: >Also I think the fact that you think your were diteriating just goes to show >how dedicated you are to detail, and making sure you give the right advice >or ask the right question. [totally-OT] Not really, unfo

Re: What is different with Python ?

2005-06-15 Thread Andrea Griffini
On Tue, 14 Jun 2005 12:49:27 +0200, Peter Maas <[EMAIL PROTECTED]> wrote: > > Depends if you wanna build or investigate. > >Learning is investigating. Yeah, after thinking to this phrase I've to agree. Sometimes learning is investigating, sometimes it's building. Since I discovered programming I'

Re: What is different with Python ?

2005-06-15 Thread Andrea Griffini
On Wed, 15 Jun 2005 10:27:19 +0100, James <[EMAIL PROTECTED]> wrote: >If you're thinking of things like superstrings, loop quantum gravity >and other "theories of everything" then your friend has gotten >confused somewhere. More likely I was the one that didn't understand. Reading what wikipedia

Re: What is different with Python ?

2005-06-15 Thread Andrea Griffini
On Tue, 14 Jun 2005 16:40:42 -0500, Mike Meyer <[EMAIL PROTECTED]> wrote: >Um, you didn't do the translation right. Whoops. So you know assembler, no other possibility as it's such a complex language that unless someone already knows it (and in the specific architecture) what i wrote is pure lin

Re: What is different with Python ?

2005-06-14 Thread Andrea Griffini
On 14 Jun 2005 00:37:00 -0700, "Michele Simionato" <[EMAIL PROTECTED]> wrote: >It looks like you do not have a background in Physics research. >We *do* build the world! ;) > > Michele Simionato Wow... I always get surprises from physics. For example I thought that no one could drop

Re: What is different with Python ?

2005-06-14 Thread Andrea Griffini
On Tue, 14 Jun 2005 04:18:06 GMT, Andrew Dalke <[EMAIL PROTECTED]> wrote: >In programming you're often given a result ("an inventory >management system") and you're looking for a solution which >combines models of how people, computers, and the given domain work. Yes, at this higher level I agree

Re: What is different with Python ?

2005-06-14 Thread Andrea Griffini
On Mon, 13 Jun 2005 22:19:19 -0500, D H <[EMAIL PROTECTED]> wrote: >The best race driver doesn't necessarily know the most about their car's >engine. The best baseball pitcher isn't the one who should be teaching >a class in physics and aerodynamics. Yes, both can improve their >abilities by

Re: What is different with Python ?

2005-06-14 Thread Andrea Griffini
On Mon, 13 Jun 2005 21:33:50 -0500, Mike Meyer <[EMAIL PROTECTED]> wrote: >But this same logic applies to why you want to teach abstract things >before concrete things. Since you like concrete examples, let's look >at a simple one: > > a = b + c > ... >In a very >few languages (BCPL being one),

Re: What is different with Python ?

2005-06-13 Thread Andrea Griffini
On Mon, 13 Jun 2005 22:23:39 +0200, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: >Being familiar with >fondamental *programming* concepts like vars, branching, looping and >functions proved to be helpful when learning C, since I only had then to >focus on pointers and memory management. If y

Re: What is different with Python ?

2005-06-13 Thread Andrea Griffini
On Mon, 13 Jun 2005 01:54:53 -0500, Mike Meyer <[EMAIL PROTECTED]> wrote: >Andrea Griffini <[EMAIL PROTECTED]> writes: >>>In short, you're going to start in the middle. >> >> I've got "bad" news for you. You're always in the >> mi

Re: What is different with Python ?

2005-06-13 Thread Andrea Griffini
On Mon, 13 Jun 2005 13:35:00 +0200, Peter Maas <[EMAIL PROTECTED]> wrote: >I think Peter is right. Proceeding top-down is the natural way of >learning. Depends if you wanna build or investigate. To build top down is the wrong approach (basically because there's no top). Top down is however great

Re: What is different with Python ?

2005-06-13 Thread Andrea Griffini
On Mon, 13 Jun 2005 09:22:55 +0200, Andreas Kostyrka <[EMAIL PROTECTED]> wrote: >Yep. Probably. Without a basic understanding of hardware design, one cannot >many of todays artifacts: Like longer pipelines and what does this >mean to the relative performance of different solutions. I think that p

Re: What is different with Python ?

2005-06-12 Thread Andrea Griffini
On Sun, 12 Jun 2005 21:52:12 -0400, Peter Hansen <[EMAIL PROTECTED]> wrote: >I'm curious how you learned to program. An HP RPN calculator, later TI-57. Later Apple ][. With Apple ][ after about one afternoon spent typing in a basic program from a magazine I gave up with basic and started with 650

Re: What is different with Python ?

2005-06-12 Thread Andrea Griffini
On Sun, 12 Jun 2005 19:53:29 -0500, Mike Meyer <[EMAIL PROTECTED]> wrote: >Andrea Griffini <[EMAIL PROTECTED]> writes: >> On Sat, 11 Jun 2005 21:52:57 -0400, Peter Hansen <[EMAIL PROTECTED]> >> wrote: >> Also concrete->abstract shows a clear path; startin

Re: What is different with Python ?

2005-06-12 Thread Andrea Griffini
On Sun, 12 Jun 2005 20:22:28 -0400, Roy Smith <[EMAIL PROTECTED]> wrote: >How far down do you have to go? What makes bytes of memory, data busses, >and CPUs the right level of abstraction? They're things that can be IMO genuinely accept as "obvious". Even "counting" is not the lowest level in m

Re: What is different with Python ?

2005-06-12 Thread Andrea Griffini
On Sat, 11 Jun 2005 21:52:57 -0400, Peter Hansen <[EMAIL PROTECTED]> wrote: >I think new CS students have more than enough to learn with their >*first* language without having to discover the trials and tribulations >of memory management (or those other things that Python hides so well). I'm no

Re: Abstract and concrete syntax

2005-06-09 Thread Andrea Griffini
On Thu, 09 Jun 2005 03:32:12 +0200, David Baelde <[EMAIL PROTECTED]> wrote: >I tried python, and do like it. Easy to learn and read This is a key point. How easy is to *read* is considered more important than how easy is to *write*. Re-read the absence of a ternary operator or the limitations of

Re: time consuming loops over lists

2005-06-07 Thread Andrea Griffini
On Tue, 07 Jun 2005 23:38:29 +0200, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: >> I don't see a "break" so why the "/2" ? also IIUC the > >That was the assumption of an equal distribution of the data. In >O-notationn this would be O(n) of course. It was a joke ... the issue is that there was

Re: programmnig advise needed

2005-06-07 Thread Andrea Griffini
On 7 Jun 2005 12:14:45 -0700, [EMAIL PROTECTED] wrote: >I am writing a Python program that needs to read XML files and contruct >a tree object from the XML file (using wxTree). Supposing your XML file has a single top level node (so that it's a legal XML file) then the following code should be ab

Re: time consuming loops over lists

2005-06-07 Thread Andrea Griffini
On Tue, 07 Jun 2005 18:13:01 +0200, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: >Another optimization im too lazy now would be to do sort of a "tree >search" of data[i] in rngs - as the ranges are ordered, you could find >the proper one in log_2(len(rngs)) instead of len(rngs)/2. I don't see

Re: What are OOP's Jargons and Complexities?

2005-06-05 Thread Andrea Griffini
On Sun, 05 Jun 2005 16:30:18 +0200, Matthias Buelow <[EMAIL PROTECTED]> wrote: >Quite embarrassing, but it's a runtime bug and got nothing to do with >the language per se. And it certainly manifests itself after the >hey-days of Turbo Pascal (when Borland seems to have lost interest in >maintaini

Re: What are OOP's Jargons and Complexities?

2005-06-04 Thread Andrea Griffini
On Wed, 01 Jun 2005 23:25:00 +0200, Matthias Buelow <[EMAIL PROTECTED]> wrote: >Of course it is a language, just not a standardized one (if you include >Borland's extensions that make it practical). The history of "runtime error 200" and its handling from borland is a clear example of what I mean

Re: What are OOP's Jargons and Complexities?

2005-06-01 Thread Andrea Griffini
On Wed, 01 Jun 2005 16:07:58 +0200, Matthias Buelow <[EMAIL PROTECTED]> wrote: >With a few relaxations and extensions, you can get a surprisingly useful >language out of the rigid Pascal, as evidenced by Turbo Pascal, one of >the most popular (and practical) programming languages in the late 80ies

Re: empty lists vs empty generators

2005-05-03 Thread Andrea Griffini
On 2 May 2005 21:49:33 -0700, "Michele Simionato" <[EMAIL PROTECTED]> wrote: >Starting from Python 2.4 we have tee in the itertools >module, so you can define the following: > >from itertools import tee > >def is_empty(it): >it_copy = tee(it)[1] >try: >it_copy.next() >except St

Re: Speed revisited

2005-01-10 Thread Andrea Griffini
On Mon, 10 Jan 2005 17:52:42 +0100, Bulba! <[EMAIL PROTECTED]> wrote: >I don't see why should deleting element from a list be O(n), while >saying L[0]='spam' when L[0] previously were, say, 's', not have the >O(n) cost, if a list in Python is just an array containing the >objects itself? > >Why s

Re: Speed revisited

2005-01-09 Thread Andrea Griffini
On 9 Jan 2005 16:03:34 -0800, "John Machin" <[EMAIL PROTECTED]> wrote: >My wild guess: Not a common use case. Double-ended queue is a special >purpose structure. > >Note that the OP could have implemented the 3-tape update simulation >efficiently by reading backwards i.e. del alist[-1] Note that

Re: Speed revisited

2005-01-09 Thread Andrea Griffini
On 9 Jan 2005 12:39:32 -0800, "John Machin" <[EMAIL PROTECTED]> wrote: >Tip 1: Once you have data in memory, don't move it, move a pointer or >index over the parts you are inspecting. > >Tip 2: Develop an abhorrence of deleting data. I've to admit that I also found strange that deleting the first

Re: mysterious buggy behavior

2005-01-09 Thread Andrea Griffini
On 8 Jan 2005 20:40:37 -0800, [EMAIL PROTECTED] (Sean McIlroy) wrote: >def newGame(): >BOARD = [blank]*9 >for x in topButtons+midButtons+botButtons: x['text'] = '' Do you know that "BOARD" here is a local variable and has nothing to do with the global BOARD ? You can change that by doing

Re: Help with generators outside of loops.

2004-12-08 Thread Andrea Griffini
David Eppstein wrote: In article <[EMAIL PROTECTED]>, "Robert Brewer" <[EMAIL PROTECTED]> wrote: But I'm guessing that you can't index into a generator as if it is a list. row = obj.ExecSQLQuery(sql, args).next() I've made it a policy in my own code to always surround explicit calls to next()