Re: Coding style

2006-07-18 Thread Patrick Maupin
Carl Banks wrote: Here's another reason not to use if lst. Say you have a function that looks like this: def process_values(lst): if not lst: return do_expensive_initialization_step() for item in lst: do_something_with(item)

Re: Coding style

2006-07-18 Thread Patrick Maupin
Daniel Dittmar wrote: Premature generalization: the new 'premature optimization'. Premature specialization: the new 'static typing'. -- Pat -- http://mail.python.org/mailman/listinfo/python-list

Re: Coding style

2006-07-17 Thread Patrick Maupin
PTY wrote: It looks like there are two crowds, terse and verbose. I thought terse is perl style and verbose is python style. BTW, lst = [] was not what I was interested in :-) I was asking whether it was better style to use len() or not. It's not canonical Python to use len() in this

Re: list comprehension

2006-01-24 Thread Patrick Maupin
Duncan Booth wrote: I prefer writing an 'if' statement here, Bryan prefers 'get', that's just a choice of style. But 'setdefault' here, that has no style. Well, I'm often told I have no style, and I _did_ admit that it's an abuse of setdefault. However, I often use setdefault to populate

Re: list comprehention

2006-01-23 Thread Patrick Maupin
Duncan Booth showed how to solve a problem posed by Mathijs. This is very similar to Duncan's solution, except I (ab)use setdefault on a regular basis... def occurrences(t): ... res = {} ... for item in t: ... res.setdefault(item,[0])[0] += 1 ... return res ... ref =

Re: Apology Re: Is 'everything' a refrence or isn't it?

2006-01-09 Thread Patrick Maupin
Mike Meyer wrote: This is where we disagree. I think their understanding of references is dead on. What's broken is their understanding of what variables are and what assignments mean. Once you fix that, the rest falls into place. (Steven D'Aprano wrote:) The fact that call by object is

Re: Apology Re: Is 'everything' a refrence or isn't it?

2006-01-09 Thread Patrick Maupin
Mike Meyer wrote: This is where we disagree. I think their understanding of references is dead on. What's broken is their understanding of what variables are and what assignments mean. Once you fix that, the rest falls into place. (Steven D'Aprano wrote:) The fact that call by object is

Re: Apology Re: Is 'everything' a refrence or isn't it?

2006-01-09 Thread Patrick Maupin
Mike Meyer wrote: This is where we disagree. I think their understanding of references is dead on. What's broken is their understanding of what variables are and what assignments mean. Once you fix that, the rest falls into place. (Steven D'Aprano wrote:) The fact that call by object is

Re: Apology Re: Is 'everything' a refrence or isn't it?

2006-01-09 Thread Patrick Maupin
Mike Meyer wrote: This is where we disagree. I think their understanding of references is dead on. What's broken is their understanding of what variables are and what assignments mean. Once you fix that, the rest falls into place. (Steven D'Aprano wrote:) The fact that call by object is

Re: Occasional OSError: [Errno 13] Permission denied on Windows

2006-01-05 Thread Patrick Maupin
Alec Wysoker wrote: Using Python 2.3.5 on Windows XP, I occasionally get OSError: [Errno 13] Permission denied when calling os.remove(). This can occur with a file that is not used by any other process on the machine, and is created by the python.exe invocation that is trying to delete it.

Re: Occasional OSError: [Errno 13] Permission denied on Windows

2006-01-05 Thread Patrick Maupin
Tim Peters wrote: In that case, anything that burns some time and tries again will work better. Replacing gc.collect() with time.sleep() is an easy way to test that hypothesis; because gc.collect() does an all-generations collection, it can consume measurable time. An slight enhancement

Re: Translate this to python?

2006-01-03 Thread Patrick Maupin
for (i = nPoints-1, j = 0; j nPoints; i = j, j++) A simple translation of this would be: i = npoints-1 for j in range(npoints): ... (your code here) i = j HTH, Pat -- http://mail.python.org/mailman/listinfo/python-list

Re: Translate this to python?

2006-01-03 Thread Patrick Maupin
for (i = nPoints-1, j = 0; j nPoints; i = j, j++) Alternatively, if you don't like the initial setup of i and would prefer your setup code at the top of the loop: for j in range(npoints): i = (j-1) % npoints ... (your code here) Finally, you could always do something like this:

Re: Calling GPL code from a Python application

2006-01-03 Thread Patrick Maupin
Mike Meyer wrote: . Note that I'm *not* interpreting the GPL. I'm interpreting what the FSF says about the GPL. If the goal is to avoid a lawsuit, the latter is what you have to pay attention to, as they're telling you what actions you can take without getting sued. The text comes into play

Re: Calling GPL code from a Python application

2006-01-03 Thread Patrick Maupin
Mike Meyer wrote: . Note that I'm *not* interpreting the GPL. I'm interpreting what the FSF says about the GPL. If the goal is to avoid a lawsuit, the latter is what you have to pay attention to, as they're telling you what actions you can take without getting sued. The text comes into play

Re: Calling GPL code from a Python application

2006-01-03 Thread Patrick Maupin
Mike Meyer wrote: . Note that I'm *not* interpreting the GPL. I'm interpreting what the FSF says about the GPL. If the goal is to avoid a lawsuit, the latter is what you have to pay attention to, as they're telling you what actions you can take without getting sued. The text comes into play

Re: Translate this to python?

2006-01-03 Thread Patrick Maupin
Peter Hansen wrote: Though, without knowing what the body does, one can't be sure that's going to be a faithful translation. The for loop in Python always iterates over the entire set of items given to it, unless it's told to break early. But if j or nPoints is modified in the body of the

Re: Problem overriding sys.excepthook

2006-01-02 Thread Patrick Maupin
Lunchtimemama wrote: What is the superior method of exception handling: ... For a start, note that the exception hook does not _really_ have to be in the main module, just imported before any protected code is to be executed. Having said that, what I personally typically do for exception

Re: Problem overriding sys.excepthook

2006-01-01 Thread Patrick Maupin
Lunchtimemama wrote: Yo all, I'm getting into Python for the first time and I'm really having a blast. I've hit a bit of a snag and was wondering if someone could lend some insight. Here be the code: import sys def myexcepthook(type, value, tb): import traceback rawreport =

Re: Problem overriding sys.excepthook

2006-01-01 Thread Patrick Maupin
Lunchtimemama wrote: Forgive my ignorance, but I'm not quite sure what you mean. I tried importing the traceback module at the beginning of the script, but that didn't make a difference. Could you provide example code to illustrate your comment? Thanks. Assume your main module has your

Re: global variables shared across modules

2005-09-09 Thread Patrick Maupin
MackS wrote: print inside fun(): + global_var ... How can I get the changed value to persist in such a way that it isn't reset when control leaves fun()? Why is it even reset in the first place? After all, the module has already been imported (and the initialization of global_var

Re: Possible improvement to slice opperations.

2005-09-06 Thread Patrick Maupin
Ron Adam wrote: This should never fail with an assertion error. You will note that it shows that, for non-negative start and end values, slicing behavior is _exactly_ like extended range behavior. Yes, and it passes for negative start and end values as well. Umm, no: . for stride in [-3,

Re: Proposal: add sys to __builtins__

2005-09-06 Thread Patrick Maupin
Sybren Stuvel wrote: A programming language should not be ambiguous. The choice between importing a module and calling a function should not depend on the availability of a (local) variable. Yeah, this behavior would be as ambiguous as if we had a system-defined search-path for modules, where

Re: Possible improvement to slice opperations.

2005-09-05 Thread Patrick Maupin
No one has yet explained the reasoning (vs the mechanics) of the returned value of the following. L = range(10) L[3::-1] So far every attempt to explain it has either quoted the documents which don't address that particular case, or assumed I'm misunderstanding something, or

Re: Possible improvement to slice opperations.

2005-09-05 Thread Patrick Maupin
I previously wrote (in response to a query from Ron Adam): In any case, you asked for a rationale. I'll give you mine: L = range(10) L[3:len(L):-1] == [L[i] for i in range(3,len(L),-1)] True After eating supper, I just realized that I could probably make my point a bit clearer with a

Re: Possible improvement to slice opperations.

2005-09-04 Thread Patrick Maupin
After considering several alternatives and trying out a few ideas with a modified list object Bengt Richter posted, (Thank You), I think I've found a way to make slice operation (especially far end indexing) symmetrical and more consistent. I don't know that it makes it more consistent. I

Re: $6 into $1000ands this actually works!

2005-07-01 Thread Patrick Maupin
Thomas wrote: TURN $6 INTO $15,000 IN ONLY 30 DAYS...HERES HOW! $ REMEMBER, IT IS 100% LEGAL! DON'T PASS THIS UP! and I thought this was about some new currency/decimal module implementation which remembers units and does the conversion correctly... --

Re: PEP 304 - is anyone really interested?

2005-06-24 Thread Patrick Maupin
John Roth wrote: I'd like to suggest a different mechanism, at least for packages (top level scripts don't generate .pyc files anyway.) Put a system variable in the __init__.py file. Something like __obj__ = path would do nicely. Then when Python created the __init__.pyc file, it would

Re: formatted xml output from ElementTree inconsistency

2005-06-24 Thread Patrick Maupin
Jarek Zgoda wrote: Why want you to read an XML document by hand? It's a machine related data chunk. I see this attitude all the time, and frankly I don't understand it. Please explain why XML is in ASCII/unicode instead of binary. Is it because it is easier for a machine to parse? No, I

Re: formatted xml output from ElementTree inconsistency

2005-06-24 Thread Patrick Maupin
Dennis Bieber wrote: Off hand, I'd consider the non-binary nature to be because the internet protocols are mostly designed for text, not binary. A document at http://www.w3.org/TR/REC-xml/ lists the design goals for XML. One of the listed goals is XML documents should be human-legible and

Re: PEP 304 - is anyone really interested?

2005-06-22 Thread Patrick Maupin
Skip Montanaro wrote: I wrote PEP 304, Controlling Generation of Bytecode Files: ... If someone out there is interested in this functionality and would benefit more from its incorporation into the core, I'd be happy to hand it off to you. I am quite interested in this PEP. What, exactly,

<    1   2   3   4