Re: except clause syntax question

2012-01-30 Thread Mel Wilson
Charles Yeomans wrote: > To catch more than one exception type in an except block, one writes > > except (A, B, C) as e: > > I'm wondering why it was decided to match tuples, but not lists: > > except [A, B, C] as e: > > The latter makes more sense semantically to me -- "catch all exception >

Re: except clause syntax question

2012-01-31 Thread Mel Wilson
Charles Yeomans wrote: > To catch more than one exception type in an except block, one writes > > except (A, B, C) as e: > > I'm wondering why it was decided to match tuples, but not lists: > > except [A, B, C] as e: > > The latter makes more sense semantically to me -- "catch all exception >

Re: except clause syntax question

2012-01-31 Thread Mel Wilson
Chris Angelico wrote: > On Wed, Feb 1, 2012 at 9:03 AM, Duncan Booth > wrote: >> Abitrarily nested tuples of exceptions cannot contain loops so the code >> simply needs to walk through the tuples until it finds a match. > > Is this absolutely guaranteed? The C API for CPython provides: > (Py2) h

Re: Question about name scope

2012-02-01 Thread Mel Wilson
Dave Angel wrote: > I tried your experiment using Python 2.7 and Linux 11.04 > > > def f(a): > from math import sin, cos > return sin(a) + cos(a) > > print f(45) > > Does what you needed, and neatly. The only name added to the global > namspace is f, of type function. > > I was a b

Re: python reliability with EINTR handling in general modules

2012-02-02 Thread Mel Wilson
Dennis Lee Bieber wrote: > On Wed, 1 Feb 2012 23:25:36 -0800 (PST), oleg korenevich > wrote: > > >>Thanks for help. In first case all vars is python integers, maybe >>math.floor is redundant, but i'm afraid that same error with math >>module call will occur in other places of app, where math is

Re: difference between random module in python 2.6 and 3.2?

2012-02-06 Thread Mel Wilson
Steven D'Aprano wrote: > A more explicit note will help, but the basic problem applies: how do you > write deterministic tests given that the random.methods (apart from > random.random itself) can be changed without warning? Biting the bullet would mean supplying your own PRNG, under your control

Re: M2crypto

2012-02-12 Thread Mel Wilson
zigi wrote: > Hello, > M2crypto > > __init__(self, alg, key, iv, op, key_as_bytes=0, d='md5', > salt='12345678', i=1, padding=1) > > I wont write app, using M2crypto and I can not understand what are the > arguments: > key, iv, op, salt ? > What they do ? I assume you're reading in

Re: name of a sorting algorithm

2012-02-14 Thread Mel Wilson
Jabba Laci wrote: > Could someone please tell me what the following sorting algorithm is > called? > > Let an array contain the elements a_1, a_2, ..., a_N. Then: > for i in xrange (N-1): for j in xrange (i, N): if a[j] < a[i]: a[i], a[j] = a[j], a[i] > > It's so simple t

RE: name of a sorting algorithm

2012-02-14 Thread Mel Wilson
Prasad, Ramit wrote: >> > for i in xrange (N-1): > for j in xrange (i, N): > if a[j] < a[i]: > a[i], a[j] = a[j], a[i] >> It's what Wikipedia says a selection sort is: put the least element in >> [0], the least of the remaining elements in [1], etc. > > If your only requi

Re: name of a sorting algorithm

2012-02-14 Thread Mel Wilson
Den wrote: > I disagree. In a bubble sort, one pointer points to the top element, > while another descents through all the other elements, swapping the > elements at the pointers when necessary. 'When I use a word,' Humpty Dumpty said, in rather a scornful tone, 'it means just what I choose it

Re: atexit.register in case of errors

2012-02-15 Thread Mel Wilson
Andrea Crotti wrote: > I have the following very simplified situation > > from atexit import register > > > def goodbye(): > print("saying goodbye") > > > def main(): > while True: > var = raw_input("read something") > > > if __name__ == '__main__': > register(goodby

Re: PyWart: Language missing maximum constant of numeric types!

2012-02-24 Thread Mel Wilson
Rick Johnson wrote: > I get sick and tired of doing this!!! > > if maxlength == UNLIMITED: > allow_passage() > elif len(string) > maxlength: > deny_passage() > > What Python needs is some constant that can be compared to ANY numeric > type and that constant will ALWAYS be larger! Easily

Re: Is it necessary to call Tk() when writing a GUI app with Tkinter?

2012-03-02 Thread Mel Wilson
Terry Reedy wrote: > The problem was another subtle bug in the current example": > self.hi_there["text"] = "Hello", > > The spurious comma at the end makes the value of the 'text' attribute a > one-elememt tuple and not just a string. I presume tcl-based tk handles > that in the manner a

Re: A 'Python like' language

2012-03-03 Thread Mel Wilson
Paul Rubin wrote: > dreamingforw...@gmail.com writes: >>> hanging out on the Prothon list now and then, at least until we get >>> the core language sorted out? >> >> Haha, a little late, but consider this a restart. > > It wasn't til I saw the word "Prothon" that I scrolled back and saw you > wer

Re: Python is readable

2012-03-16 Thread Mel Wilson
Steven D'Aprano wrote: > On Fri, 16 Mar 2012 17:53:24 +, Neil Cerutti wrote: > >> On 2012-03-16, Steven D'Aprano >> wrote: >>> Ah, perhaps you're talking about *prescriptivist* grammarians, who >>> insist on applying grammatical rules that exist only in their own >>> fevered imagination. Sor

Re: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct

2012-03-17 Thread Mel Wilson
Antti J Ylikoski wrote: > > In his legendary book series The Art of Computer Programming, > Professor Donald E. Knuth presents many of his algorithms in the form > that they have been divided in several individual phases, with > instructions to GOTO to another phase interspersed in the text of th

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: Best search algorithm to find condition within a range

2015-04-08 Thread Mel Wilson
On Tue, 07 Apr 2015 23:19:49 -0700, jonas.thornvall wrote: > And you have just created 429496729 unique symbols ;), in a pencil > stroke. No. You did that, when you said base 429496729. Representing the symbols in a computer is no problem, any Python long int can do that. To display the symb

Re: Best search algorithm to find condition within a range

2015-04-08 Thread Mel Wilson
On Wed, 08 Apr 2015 07:56:05 -0700, jonas.thornvall wrote: > There is no need for inventing a new set of characters representing > 32-bit numbers. You will not be able to learn them by heart anyway, > unless they build on a interpretation system binaries, decimals. See Jorge Luis Borges, _Funes t

Re: New to Python - block grouping (spaces)

2015-04-19 Thread Mel Wilson
On Sun, 19 Apr 2015 09:03:23 -0700, Rustom Mody wrote: > Now if Thomson and Ritchie (yeah thems the guys) could do it in 1970, > why cant we revamp this 45-year old archaic program=textfile system > today? Dunno. Why not? There's half of you right there. -- https://mail.python.org/mailman/lis

Re: New to Python - block grouping (spaces)

2015-04-19 Thread Mel Wilson
On Mon, 20 Apr 2015 03:53:08 +1000, Steven D'Aprano wrote: > On Mon, 20 Apr 2015 02:03 am, Rustom Mody wrote: >> Well evidently some people did but fortunately their managers did not >> interfere. > > You are assuming they had managers. University life isn't exactly the > same as corporate cultu

Re: How to properly apply OOP in the bouncing ball code

2015-05-08 Thread Mel Wilson
On Fri, 08 May 2015 08:40:34 -0700, Tommy C wrote: > I'm trying to apply OOP in this bouncing ball code in order to have > multiple balls bouncing around the screen. The objective of this code is > to create a method called settings, which controls all the settings for > the screen and the bouncin

Re: functions, optional parameters

2015-05-08 Thread Mel Wilson
On Sat, 09 May 2015 03:49:36 +1000, Chris Angelico wrote: > Yes, but can you *distinguish* them in terms of default argument versus > code object creation? How do you know that the function's code object > was created when compile() happened, rather than being created when the > function was defin

Re: Instead of deciding between Python or Lisp for a programming intro course...What about an intro course that uses *BOTH*? Good idea?

2015-05-10 Thread Mel Wilson
On Sun, 10 May 2015 13:43:03 -0700, Chris Seberino wrote: > Instead of learning only Scheme or only Python for a one semester intro > course, what about learning BOTH? Maybe that could somehow get the > benefits of both? > > I'm thinking that for the VERY beginning, Scheme is the fastest languag

Re: anomaly

2015-05-11 Thread Mel Wilson
On Sun, 10 May 2015 14:12:44 -0500, boB Stepp wrote: > I have to admit being surprised by this, too. I am just now studying on > how to write my own classes in Python, and have come to realize that > doing this is *possible*, but the *surprise* to me is why the language > design allowed this to ac

Re: anomaly

2015-05-11 Thread Mel Wilson
On Tue, 12 May 2015 02:35:23 +1000, Steven D'Aprano wrote: > On Mon, 11 May 2015 11:37 pm, Mel Wilson wrote: > >> On Sun, 10 May 2015 14:12:44 -0500, boB Stepp wrote: >> >>> I have to admit being surprised by this, too. I am just now studying >>> on h

Re: Use and usefulness of the as syntax

2011-11-12 Thread Mel Wilson
candide wrote: > First, could you confirm the following syntax > > import foo as f > > equivalent to > > import foo > f = foo > > > > Now, I was wondering about the usefulness in everyday programming of the > as syntax within an import statement. [ ... ] It gives you an out in a case like

Re: Close as Many Files/External resourcs as possible in the face of exceptions

2011-11-21 Thread Mel Wilson
GZ wrote: > Here is my situation. A parent object owns a list of files (or other > objects with a close() method). The close() method can sometimes fail > and raise an exception. When the parent object's close() method is > called, it needs to close down as many files it owns as possible, even >

Re: correct usage of a generator?

2011-11-28 Thread Mel Wilson
Tim wrote: > Hi, I need to generate a list of file names that increment, like this: > fname1 > fname2 > fname3 and so on. > > I don't know how many I'll need until runtime so I figure a generator is > called for. > > def fname_gen(stem): > i = 0 > while True: > i = i+1 >

Re: Making the case for "typed" lists/iterators in python

2011-12-16 Thread Mel Wilson
Chris Angelico wrote: > It's no more strange than the way some people omit the u from colour. :) Bonum Petronio Arbiteri, bonum mihi. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-22 Thread Mel Wilson
Chris Angelico wrote: > On Fri, Dec 23, 2011 at 1:13 AM, Hans Mulder wrote: >> How about: >> >> >> ... >> >> >> More more readable! And it's a standard! > > Unfortunately it's not Pythonic, because indentation is insignificant. Easy-peasy: Mel. > We need to ado

Re: Early and late binding [was Re: what does 'a=b=c=[]' do]

2011-12-23 Thread Mel Wilson
Steven D'Aprano wrote: > On Fri, 23 Dec 2011 13:13:38 +, Neil Cerutti wrote: >> On 2011-12-23, Neil Cerutti wrote: >> ...you know, assuming it wouldn't break existing code. ;) > > It will. Python's default argument strategy has been in use for 20 years. > Some code will rely on it. I know min

Re: mutually exclusive arguments to a constructor

2011-12-30 Thread Mel Wilson
Adam Funk wrote: > (Warning: this question obviously reflects the fact that I am more > accustomed to using Java than Python.) > > Suppose I'm creating a class that represents a bearing or azimuth, > created either from a string of traditional bearing notation > ("N24d30mE") or from a number indi

Re: verify the return value of a function

2012-01-20 Thread Mel Wilson
Jean-Michel Pichavant wrote: > isinstance is fine, if you could find the source where it is > discouraged... Could be a consequence of some specific context. > However, checking types in OOP is in general a failure. Unitary tests > are possibly an exception. I think it's discouraged when people t

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: 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: 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: 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: 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: [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)

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: 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: 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: 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