Re: assymetry between a == b and a.__eq__(b)

2004-12-03 Thread Mel Wilson
In article <[EMAIL PROTECTED]>, Steven Bethard <[EMAIL PROTECTED]> wrote: >I believe what Peter Otten was pointing out is that calling __eq__ is >not the same as using ==, presumably because the code for == checks the >types of the two objects and returns False if they're different before >the __eq

Re: assymetry between a == b and a.__eq__(b)

2004-12-04 Thread Mel Wilson
In article <[EMAIL PROTECTED]>, Steven Bethard <[EMAIL PROTECTED]> wrote: >Mel Wilson wrote: >> In article <[EMAIL PROTECTED]>, >> Steven Bethard <[EMAIL PROTECTED]> wrote: >> >>>I believe what Peter Otten was pointing out is that calling __e

Re: assymetry between a == b and a.__eq__(b)

2004-12-05 Thread Mel Wilson
In article <[EMAIL PROTECTED]>, Peter Otten <[EMAIL PROTECTED]> wrote: >Tim Peters wrote: > >> See the Python (language, not library) reference manual, section 3.3.8 >> ("Coercion rules"), bullet point starting with: >> >> Exception to the previous item: if the left operand is an >> instanc

Re: exec'ing functions

2004-12-09 Thread Mel Wilson
In article <[EMAIL PROTECTED]>, Steven Bethard <[EMAIL PROTECTED]> wrote: >Jeff Shannon wrote: >> I was referring to functions which have an internal exec statement, not >> functions which are created entirely within an exec -- i.e., something >> like this: > >Thanks for the clarification. Here's

Re: newbie questions

2004-12-11 Thread Mel Wilson
In article <[EMAIL PROTECTED]>, "houbahop" wrote: >Thank you everyone, but I still not understand why such a comon feature like >passing parameters byref that is present in most serious programming >languages is not possible in a clean way,here in python. > >I have the habit to never use globals a

Re: Suggestion for "syntax error": ++i, --i

2004-12-13 Thread Mel Wilson
In article <[EMAIL PROTECTED]>, Christian Ergh <[EMAIL PROTECTED]> wrote: >Ah, ok, i misunderstood you. Well, to mark it as a syntax error sounds >good, and at the Moment I would not know a case where this conflicts >with a implementation. Well, you can overload prefix `+` and `-` operators on

Re: exec'ing functions

2004-12-10 Thread Mel Wilson
In article <[EMAIL PROTECTED]>, Peter Otten <[EMAIL PROTECTED]> wrote: >Mel Wilson wrote: >> The thing is, that once you drop local-namespace >> optimization, the entire function gets slowed down, possibly >> by 40%: >It's not that bad as most of the ext

Re: how to improve this simple block of code

2006-01-11 Thread Mel Wilson
py wrote: > Say I have... > x = "132.00" > > but I'd like to display it to be "132" ...dropping the trailing > zeros... print '%g' % (float(x),) might work. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: Question about idioms for clearing a list

2006-02-06 Thread Mel Wilson
Fredrik Lundh wrote: > (del doesn't work on dictionaries) ... or rather [:] doesn't work on dictionaries ... Python 2.4.2 (#1, Jan 23 2006, 21:24:54) [GCC 3.3.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> d={'a':1, 'b':2, 'c':3} >>> print d {'a': 1, 'c

Re: lambda

2006-04-21 Thread Mel Wilson
[EMAIL PROTECTED] wrote: > Hello, > > I need your help understanding lambda (and doing it a better way > without). > > f = lambda x : x*x [ ... ] > # the idea is now to give the definition of the multiplication of > functions and integers > # (f * c)(xx) := f(x)*c > [lambda xx: f(xx)*y for y in

Re: Generate a sequence of random numbers that sum up to 1?

2006-04-21 Thread Mel Wilson
Anthony Liu wrote: > I am at my wit's end. > > I want to generate a certain number of random numbers. > This is easy, I can repeatedly do uniform(0, 1) for > example. > > But, I want the random numbers just generated sum up > to 1 . > > I am not sure how to do this. Any idea? Thanks. number

Re: simultaneous assignment

2006-05-02 Thread Mel Wilson
Roger Miller wrote: > Steve R. Hastings wrote: > > >>a = 0 >>b = 0 >>a is b # always true > > > Is this guaranteed by the Python specification, or is it an artifact of > the current implementation? AFAIK it's an artifact. The performance hit it Python stopped sharing small integers could b

Re: Tuple assignment and generators?

2006-05-05 Thread Mel Wilson
vdrab wrote: > I guess the take-away lesson is to steer clear from any reliance on > object identity checks, if at all possible. Are there any other such > "optimizations" one should like to know about? Object identity checks are just the thing/numero uno/ichiban for checking object identity. A

Re: printing list

2006-05-07 Thread Mel Wilson
Tim Chase wrote: > compboy wrote: > >> How do you print elements of the list in one line? >> >> alist = [1, 2, 5, 10, 15] >> >> so it will be like this: >> 1, 2, 5, 10, 15 > > > >>> print ', '.join(alist) > 1, 2, 5, 10, 15 ??? Python 2.4.2 (#1, Jan 23 2006, 21:24:54) [GCC 3.3.4] on linux2 Typ

Re: Complex evaluation bug

2006-05-18 Thread Mel Wilson
of wrote: > a = 1+3j > complex(str(a)) > > Why does this not work ? It should It would be nice. Looks like str(1+3j) is returning an expression in string form. Maybe there is no actual complex literal. eval (str(1+3j)) works. Python 2.4.2 (#1, Jan 23 2006, 21:24:54) [GCC 3.3.4] on linux2 Type

Re: [silly] Does the python mascot have a name ?

2006-05-18 Thread Mel Wilson
Steve wrote: > Carl J. Van Arsdall wrote: >> John D Salt wrote: >> hon-list/2003-September/185612.html > "Odi" must be the Dutch for "Monty". Nope. If it was Dutch it would probably be Odie >>> Damn. >>> >> Odi(e) was a punk. I'm gonna be a rebel without a cause and stay with >> M

Re: Question about exausted iterators

2006-05-19 Thread Mel Wilson
[EMAIL PROTECTED] wrote: > Consider this example: > X = range(5) Y = iter(X) Z = iter(Y) > > As you can see, X is a container, and Y is an iterator. > They are simliar in that "iter" works on them both. > > Cristoph claims that this causes confusion. > Why? Because "iter" doesn't

Re: [silly] Does the python mascot have a name ?

2006-05-19 Thread Mel Wilson
John D Salt wrote: > Mel Wilson <[EMAIL PROTECTED]> wrote in news:_s2bg.8867$aa4.296233 > @news20.bellglobal.com: > > [Snips] >> Just reinforces the central truth. The mascot doesn't >> *have* a name. Most things don't. > > Most things don'

Re: "Thinking like CS" problem I can't solve

2006-05-23 Thread Mel Wilson
Alex Pavluck wrote: > Hello. On page 124 of "Thinking like a Computer Scientist". There is > an exercise to take the following code and with the use of TRY: / > EXCEPT: handle the error. Can somone help me out? Here is the code: > [ ... ] What error? Python 2.4.2 (#1, Jan 23 2006, 21:24:54) [

Re: list comprehensions put non-names into namespaces!

2006-05-26 Thread Mel Wilson
[EMAIL PROTECTED] wrote: > Lonnie> List comprehensions appear to store their temporary result in a > Lonnie> variable named "_[1]" (or presumably "_[2]", "_[3]" etc for > Lonnie> nested comprehensions) > > Known issue. Fixed in generator comprehensions. Dunno about plans to fix > it

Re: genexp surprise (wart?)

2006-05-26 Thread Mel Wilson
Paul Rubin wrote: > "Paul Du Bois" <[EMAIL PROTECTED]> writes: >> The second is that you don't like the late-binding behavior of >> generator expressions. PEP 289 has this to say: >> >>> After much discussion, it was decided that the first (outermost) >>> for-expression should be evaluated immediat

Re: "Learning Python" 2nd ed. p479 error?

2006-05-26 Thread Mel Wilson
[EMAIL PROTECTED] wrote: > Hello all. > > On page 479, the 2nd edition of the "Learning Python" book, this code > appears > > class Derived(Base): > def __init__(self, arg, *args, **kw): > self.__init__(self, *args, **kw) > > Surely self.__init__ should be > >

Re: how to clear up a List in python?

2006-05-26 Thread Mel Wilson
[EMAIL PROTECTED] wrote: > The original post only mentions deleting the values in the list, not > the list itself. Given that you want to keep the list and just ditch > the values it contains I'd go with: > > list1 = [] Depends what you mean by "keep the list". Consider class C (object):

Re: using import * with GUIs?

2006-05-31 Thread Mel Wilson
John Salerno wrote: > Hi all. Quick question (but aren't they all?) :) > > Do you think it's a good idea to use the 'from import *' > statement when using a GUI module? It seems on wxPython's site, they > recommend using import wx nowadays, but I wonder if that advice is > followed. Also, I'm

Re: carshing the interpreter in two lines

2006-06-03 Thread Mel Wilson
sam wrote: > tomer: > > It is my opinion that you would loose performance if the Python > interpreter had the additional task of verifying byte code. It might be > more appropriate to have a preprocessor that did the verifying as it > compiled the byte code. Possibly. A good book on the topic is

Re: carshing the interpreter in two lines

2006-06-04 Thread Mel Wilson
ing with an idea for "oracles", where a computation would be allowed to call out sometimes to a non-computational process to obtain some required result. Used maybe by interactive debugging programs. Cheers,Mel. > Mel Wilson wrote: [ ... ] >>Douglas Hofstad

Re: Proposed new PEP: print to expand generators

2006-06-04 Thread Mel Wilson
Terry Reedy wrote: > "James J. Besemer" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> I propose that we extend the semantics of "print" such that if the object >> to >> be printed is a generator then print would iterate over the resulting >> sequence of sub-objects and recursiv

Re: type = "instance" instead of "dict"

2006-02-28 Thread Mel Wilson
James Stroud wrote: > Fredrik Lundh wrote: > >> James Stroud wrote: >> >> >>> Perhaps you did not know that you can inheret directly from dict, which >>> is the same as {}. For instance: >>> >>> class Dict({}): >>> pass > > > I must have been hallucinating. I swear I did this before and it wor

Re: inserting into a list

2006-03-07 Thread Mel Wilson
John Salerno wrote: > Christoph Haas wrote: >> L[2:2]=[3] [ ... ] What if you wanted to insert an actual list into that slot? Would > you have to wrap it in double brackets? Yep. It's a strong-typing thing. Slices of lists are lists, and therefore what you assign to one has got to be a list,

Re: list.clear() missing?!?

2006-04-12 Thread Mel Wilson
Ville Vainio wrote: > Fredrik Lundh wrote: >>because Python already has a perfectly valid way to clear a list, >>perhaps ? >> >>del l[:] > > > Ok. That's pretty non-obvious but now that I've seen it I'll probably > remember it. I did a stupid "while l: l.pop()" loop myself. Actually, it's in

Re: list.clear() missing?!?

2006-04-13 Thread Mel Wilson
Alan Morgan wrote: > In article <[EMAIL PROTECTED]>, > Raymond Hettinger <[EMAIL PROTECTED]> wrote: >>* s.clear() is more obvious in intent > > Serious question: Should it work more like "s=[]" or more like > "s[:]=[]". I'm assuming the latter, but the fact that there is > a difference is an argu

Re: list.clear() missing?!?

2006-04-13 Thread Mel Wilson
Steven D'Aprano wrote: > Convenience and obviousness are important for APIs -- that's why lists > have pop, extend and remove methods. The only difference I can see between > a hypothetical clear and these is that clear can be replaced with a > one-liner, while the others need at least two, e.g. fo

Re: How to get the previous line in a file?

2007-03-18 Thread Mel Wilson
Qilong Ren wrote: > Hi, Shane, > > Thanks for fast reply. > > What I used is : >for line in open(FILE): > > I don't want to store all lines in a list because sometimes the file is very > large. We need to store the value of the previous line in a variable. Is that > right?

Re: exit to interpreter?

2007-03-23 Thread Mel Wilson
belinda thom wrote: > On Mar 23, 2007, at 11:04 AM, [EMAIL PROTECTED] wrote: > >> On Mar 23, 12:52 pm, belinda thom <[EMAIL PROTECTED]> wrote: >>> Hi, >>> >>> I'm writing a function that polls the user for keyboard input, >>> looping until it has determined that the user has entered a valid >>> st

Re: Fortran vs Python - Newbie Question

2007-03-28 Thread Mel Wilson
Terry Reedy wrote: > "Tim Roberts" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > | Once upon a time, > | Basic enthusiasts would have used the word "tokenized" to describe .pyc > files. > > Perhaps, but they would, I think, have been wrong. Tokenized Basic to the > best of my

Re: Need help on reading line from file into list

2007-04-03 Thread Mel Wilson
bahoo wrote: [ ... ] > Thanks, this helped a lot. > I am now using the suggested > map(str.strip, open('source.txt').readlines()) > > However, I am a C programmer, and I have a bit difficulty > understanding the syntax. > I don't see where the "str" came from, so perhaps the output of > "open('sou

Re: [optparse] Problem with getting an option value

2007-04-06 Thread Mel Wilson
Peter Otten wrote: > Lucas Malor wrote: > >> Hello all. I'm trying to do a little script. Simply I want to make a list >> of all options with them default values. If the option is not specified in >> the command line, the script must try to read it in a config.ini file. If >> it's not present also

Re: tuples, index method, Python's design

2007-04-08 Thread Mel Wilson
7stud wrote: > On Apr 7, 8:27 am, Carsten Haese <[EMAIL PROTECTED]> wrote: >> Adding useless features always makes a product worse. What's your use >> case for tuple.index? > I'll trade you an index method for tuples for the whole complex number > facility. Actually, I've found the use cases for

Re: Lists and Tuples and Much More

2007-04-12 Thread Mel Wilson
Scott wrote: > Now I read somewhere that you could change the list inside that tupple. But > I can't find any documentation that describes HOW to do it. The only things > I CAN find on the subject say, "Don't do it because its more trouble than > it's worth." But that doesn't matter to me, be

Re: Python Feature Request: Allow changing base of member indices to 1

2007-04-14 Thread Mel Wilson
jamadagni wrote: > OK fine. It is clear that this feature must be implemented if at all > only on a per-module basis. So can we have votes for per-module > implementation of this feature? The only way that can work is if the API to the module doesn't expose ANY sequence indices. It would be a gr

Re: Python Feature Request: Add the "using" keyword which works like "with" in Visual Basic

2007-04-14 Thread Mel Wilson
[EMAIL PROTECTED] wrote: > In Visual Basic there is the keyword "with" which allows an object- > name to be declared as governing the following statements. For > example: > > with quitCommandButton > .enabled = true > .default = true > end with > > This is syntactic sugar for: > > quitCommandB

Re: List of Objects

2007-04-19 Thread Mel Wilson
[EMAIL PROTECTED] wrote: > Howdy, a (possibly) quick question for anyone willing to listen. > I have a question regarding lists and Classes; I have a class called > "gazelle" with several attributes (color, position, etc.) and I need > to create a herd of them. I want to simulate motion of individu

Re: When are immutable tuples *essential*? Why can't you just use lists *everywhere* instead?

2007-04-23 Thread Mel Wilson
Neil Cerutti wrote: > The interpreter explains it: "A list is not a hashable object." > Choosing a hash table instead of some kind of balanced tree seems > to be just an optimization. ;) Even with a balanced tree, if a key in a node changes value, you may have to re-balance the tree. Nothing in

Re: Numbers and truth values

2007-04-28 Thread Mel Wilson
John Nagle wrote: > "True", "False", and "None" should be reserved words in Python. > "None" already is. The permissiveness makes it less painful to upgrade to new versions of Python. True and False only recently got assigned conventional values, but you can still import old modules withou

Re: number generator

2007-03-10 Thread Mel Wilson
Gerard Flanagan wrote: > On Mar 9, 4:17 pm, "cesco" <[EMAIL PROTECTED]> wrote: >> On Mar 9, 3:51 pm, Paul Rubin wrote: >> >>> "cesco" <[EMAIL PROTECTED]> writes: I have to generate a list of N random numbers (integer) whose sum is equal to M. If, for example, I

Re: [python 2.4] unable to construct tuple with one item

2007-05-06 Thread Mel Wilson
Vyacheslav Maslov wrote: > So, the main question is why using syntax like [X] python constuct list > with > one item, but when i try to construct tuple with one item using similar > syntax (X) python do nothing? Because `(` and `)` are used in expressions to bracket sub-expressions. a = (4 + 3)