Re: grouping a flat list of number by range

2006-06-04 Thread Steven Bethard
[EMAIL PROTECTED] wrote: ... _, first_n = group[0] what is the meaning of the underscore _ ? is it a special var ? or should it be readed as a way of unpacking a tuple in a non useful var ? like lost, first_n = group[0] Yep, it's just another name. lost would have worked just

Re: Max function question: How do I return the index of the maximum value of a list?

2006-06-04 Thread Steven Bethard
jj_frap wrote: I'm new to programming in Python and am currently writing a three-card poker simulator. I have completed the entire simulator other than determining who has the best hand (which will be far more difficult than the aspects I've codes thus far)...I store each player's hand in a

Re: Max function question: How do I return the index of the maximum value of a list?

2006-06-04 Thread Steven Bethard
Robert Kern wrote: Steven Bethard wrote: Can you do something like:: max_val, max_index = max((x, i) for i, x in enumerate(my_list)) ? If any two x values are equal, this will return the one with the lower index. Don't know if that matters to you. Wouldn't it return the one

Re: grouping a flat list of number by range

2006-06-03 Thread Steven Bethard
Gerard Flanagan wrote: [EMAIL PROTECTED] wrote: hello, i'm looking for a way to have a list of number grouped by consecutive interval, after a search, for example : [3, 6, 7, 8, 12, 13, 15] = [[3, 4], [6,9], [12, 14], [15, 16]] (6, not following 3, so 3 = [3:4] ; 7, 8 following 6 so

Re: Proposed new PEP: print to expand generators

2006-06-03 Thread Steven Bethard
James J. Besemer wrote: 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 recursively print each of the items in order. I don't feel like searching for the specific

Re: grouping a flat list of number by range

2006-06-02 Thread Steven Bethard
[EMAIL PROTECTED] wrote: i'm looking for a way to have a list of number grouped by consecutive interval, after a search, for example : [3, 6, 7, 8, 12, 13, 15] = [[3, 4], [6,9], [12, 14], [15, 16]] Know your itertools. From the examples section[1]: # Find runs of consecutive numbers

Re: Conditional Expressions in Python 2.4

2006-06-02 Thread Steven Bethard
A.M wrote: Do we have the conditional expressions in Python 2.4? bruno at modulix wrote: No, AFAIK they'll be in for 2.5 Yep: Python 2.5a2 (trunk:46491M, May 27 2006, 14:43:55) [MSC v.1310 32 bit (Intel)] on win32 Yes if 1 == 1 else No 'Yes' In the meanwhile, there are (sometime trickyà

Re: argmax

2006-06-01 Thread Steven Bethard
David Isaac wrote: 2. Is this a good argmax (as long as I know the iterable is finite)? def argmax(iterable): return max(izip( iterable, count() ))[1] In Python 2.5: Python 2.5a2 (trunk:46491M, May 27 2006, 14:43:55) [MSC v.1310 32 bit (Intel)] on win32 iterable = [5, 8, 2, 11, 6] import

Re: Using metaclasses to inherit class variables

2006-05-22 Thread Steven Bethard
[EMAIL PROTECTED] wrote: OK no question. I'm only posting b/c it may be something another newbie will want to google in the future. Now that I've worked thru the process this turns out to be fairly easy. However, if there are better ways please let me know. Module = ClassVars.py import

Re: Using metaclasses to inherit class variables

2006-05-22 Thread Steven Bethard
[EMAIL PROTECTED] wrote: Oops! This isn't working. As the sequence I'm trying for is def set_classvars(**kwargs): ... def __metaclass__(name, bases, classdict): ... for name, value in kwargs.iteritems(): ... if name not in classdict: ...

Re: Using metaclasses to inherit class variables

2006-05-22 Thread Steven Bethard
[EMAIL PROTECTED] wrote: Fresh copies of class vars so the first one is the correct: ('foo', 'bar', [], False) Ahh, yeah, then you definitely need the copy.copy call. import copy class ClassVars(type): ... def __init__(cls, name, bases, dict): ... for name, value in

Re: Using metaclasses to inherit class variables

2006-05-19 Thread Steven Bethard
[EMAIL PROTECTED] wrote: I want to inherit fresh copies of some class variables. So I set up a metaclass and meddle with the class variables there. Now it would be convenient to run thru a dictionary rather than explicitly set each variable. However getattr() and setattr() are out because

Re: Broken essays on python.org

2006-05-12 Thread Steven Bethard
Brian Cole wrote: I'm not sure if this is the proper place to post this... A lot of the essays at http://www.python.org/doc/essays/ have a messed up layout in Firefox and IE. The proper place to post this is to follow the Report website bug link at the bottom of the sidebar and post a

Re: python equivalent of the following program

2006-05-11 Thread Steven Bethard
AndyL wrote: What would by a python equivalent of following shell program: #!/bin/sh prog1 file1 prog2 file2 If you're just going for quick-and-dirty, Rob's suggestion of os.system is probably a reasonable way to go. If you want better error reporting, I suggest using

Re: NEWBIE: Tokenize command output

2006-05-11 Thread Steven Bethard
Lorenzo Thurman wrote: This is what I have so far: // #!/usr/bin/python import os cmd = 'ntpq -p' output = os.popen(cmd).read() // The output is saved in the variable 'output'. What I need to do next is select the line from that output that starts with the '*' [snip] From

elementtidy, \0 chars and parsing from a string

2006-05-09 Thread Steven Bethard
So I see that elementtidy doesn't like strings with \0 characters in them: import urllib from elementtidy import TidyHTMLTreeBuilder url = 'http://news.bbc.co.uk/1/hi/world/europe/492215.stm' url_file = urllib.urlopen(url) tree = TidyHTMLTreeBuilder.parse(url_file) Traceback (most

optparse and counting arguments (not options)

2006-05-09 Thread Steven Bethard
I feel like I must be reinventing the wheel here, so I figured I'd post to see what other people have been doing for this. In general, I love the optparse interface, but it doesn't do any checks on the arguments. I've coded something along the following lines a number of times: class

Re: best way to determine sequence ordering?

2006-04-30 Thread Steven Bethard
Kay Schluehr wrote: * building a dict of indicies:: positions = dict((item, i) for i, item in enumerate(L)) if positions['A'] positions['D']: # do some stuff You'll only get a gain from this version if you need to do several comparisons instead of just one.

python-dev Summary for 2006-01-16 through 2006-01-31

2006-04-29 Thread Steven Bethard
Sorry the summaries are so late. We were late already, and it's taken me a bit of time to get set up with the new python.org site. But I should be all good now, and hopefully we'll get caught up with all the summaries by the end of May. Hope you all weren't too depressed without your bi-weekly

python-dev Summary for 2006-03-01 through 2006-03-15

2006-04-29 Thread Steven Bethard
python-dev Summary for 2006-03-01 through 2006-03-15 .. contents:: [The HTML version of this Summary is available at http://www.python.org/dev/summary/2006-03-01_2006-03-15] = Announcements = ---

python-dev Summary for 2006-02-01 through 2006-02-15

2006-04-29 Thread Steven Bethard
python-dev Summary for 2006-02-01 through 2006-02-15 .. contents:: [The HTML version of this Summary is available at http://www.python.org/dev/summary/2006-02-01_2006-02-15] = Announcements =

python-dev Summary for 2006-02-16 through 2006-02-28

2006-04-29 Thread Steven Bethard
python-dev Summary for 2006-02-16 through 2006-02-28 .. contents:: [The HTML version of this Summary is available at http://www.python.org/dev/summary/2006-02-16_2006-02-28] = Announcements = ---

Re: best way to determine sequence ordering?

2006-04-29 Thread Steven Bethard
nikie wrote: Steven Bethard wrote: nikie wrote: Steven Bethard wrote: John Salerno wrote: If I want to make a list of four items, e.g. L = ['C', 'A', 'D', 'B'], and then figure out if a certain element precedes another element, what would be the best way to do that? Looking

Re: self modifying code

2006-04-29 Thread Steven Bethard
John J. Lee wrote: Robin Becker [EMAIL PROTECTED] writes: When young I was warned repeatedly by more knowledgeable folk that self modifying code was dangerous. Is the following idiom dangerous or unpythonic? def func(a): global func, data data = somethingcomplexandcostly()

Re: best way to determine sequence ordering?

2006-04-29 Thread Steven Bethard
nikie wrote: That's what this thread was all about. Now, I don't really see what you are trying to say: Are you still trying to convince the OP that he should write a Python function like one of those you suggested, for performance reasons? Sure, if it really matters. Code it in C, and you

Re: best way to determine sequence ordering?

2006-04-29 Thread Steven Bethard
Steven Bethard wrote: John Salerno wrote: If I want to make a list of four items, e.g. L = ['C', 'A', 'D', 'B'], and then figure out if a certain element precedes another element, what would be the best way to do that? Looking at the built-in list functions, I thought I could do something

Re: best way to determine sequence ordering?

2006-04-29 Thread Steven Bethard
Edward Elliott wrote: Remember kids: 1. Numbers can show anything 2. Know your data set 3. Premature optimizations are evil Amen. =) STeVe -- http://mail.python.org/mailman/listinfo/python-list

Re: best way to determine sequence ordering?

2006-04-29 Thread Steven Bethard
John Salerno wrote: If I want to make a list of four items, e.g. L = ['C', 'A', 'D', 'B'], and then figure out if a certain element precedes another element, what would be the best way to do that? Looking at the built-in list functions, I thought I could do something like: if

Re: OOP techniques in Python

2006-04-28 Thread Steven Bethard
Dennis Lee Bieber wrote: On Thu, 27 Apr 2006 14:32:15 -0500, Philippe Martin [EMAIL PROTECTED] declaimed the following in comp.lang.python: What then is the point of the double underscore (if any) ?: To prevent masking/shadowing of inherited attributes... Note that it can fail to do

Re: best way to determine sequence ordering?

2006-04-28 Thread Steven Bethard
John Salerno wrote: If I want to make a list of four items, e.g. L = ['C', 'A', 'D', 'B'], and then figure out if a certain element precedes another element, what would be the best way to do that? Looking at the built-in list functions, I thought I could do something like: if

Re: best way to determine sequence ordering?

2006-04-28 Thread Steven Bethard
nikie wrote: Steven Bethard wrote: John Salerno wrote: If I want to make a list of four items, e.g. L = ['C', 'A', 'D', 'B'], and then figure out if a certain element precedes another element, what would be the best way to do that? Looking at the built-in list functions, I thought I could

python-dev Summary for 2006-01-16 through 2006-01-31

2006-04-28 Thread Steven Bethard
Sorry the summaries are so late. We were late already, and it's taken me a bit of time to get set up with the new python.org site. But I should be all good now, and hopefully we'll get caught up with all the summaries by the end of May. Hope you all weren't too depressed without your bi-weekly

python-dev Summary for 2006-02-01 through 2006-02-15

2006-04-28 Thread Steven Bethard
python-dev Summary for 2006-02-01 through 2006-02-15 .. contents:: [The HTML version of this Summary is available at http://www.python.org/dev/summary/2006-02-01_2006-02-15] = Announcements =

python-dev Summary for 2006-02-16 through 2006-02-28

2006-04-28 Thread Steven Bethard
python-dev Summary for 2006-02-16 through 2006-02-28 .. contents:: [The HTML version of this Summary is available at http://www.python.org/dev/summary/2006-02-16_2006-02-28] = Announcements = ---

python-dev Summary for 2006-03-01 through 2006-03-15

2006-04-28 Thread Steven Bethard
python-dev Summary for 2006-03-01 through 2006-03-15 .. contents:: [The HTML version of this Summary is available at http://www.python.org/dev/summary/2006-03-01_2006-03-15] = Announcements = ---

Re: OOP techniques in Python

2006-04-27 Thread Steven Bethard
Panos Laganakos wrote: we usually define private properties and provide public functions to access them, in the form of: get { ... } set { ... } Should we do the same in Python: self.__privateAttr = 'some val' def getPrivateAttr(self): return self.__privateAttr Or there's no

Re: OOP techniques in Python

2006-04-27 Thread Steven Bethard
[Please don't top-post] Steven Bethard wrote: Panos Laganakos wrote: we usually define private properties and provide public functions to access them, in the form of: get { ... } set { ... } Should we do the same in Python: self.__privateAttr = 'some val' def getPrivateAttr

Re: Updated PEP 359: The make statement

2006-04-21 Thread Steven Bethard
Tim Roberts wrote: Steven Bethard [EMAIL PROTECTED] wrote: Steven Bethard wrote: I've updated PEP 359 with a bunch of the recent suggestions. ... Guido has pronounced on this PEP: http://mail.python.org/pipermail/python-3000/2006-April/000936.html Consider it dead. =) I tried

Updated PEP 359: The make statement

2006-04-18 Thread Steven Bethard
Apr 2006) $ Author: Steven Bethard [EMAIL PROTECTED] Status: Draft Type: Standards Track Content-Type: text/x-rst Created: 05-Apr-2006 Python-Version: 2.6 Post-History: 05-Apr-2006, 06-Apr-2006, 13-Apr-2006 Abstract This PEP proposes a generalization of the class-declaration syntax

Re: Updated PEP 359: The make statement

2006-04-18 Thread Steven Bethard
Steven Bethard wrote: I've updated PEP 359 with a bunch of the recent suggestions. The patch is available at: http://bugs.python.org/1472459 and I've pasted the full text below. I've tried to be more explicit about the goals -- the make statement is mostly syntactic sugar

Re: PEP 359: The make Statement

2006-04-16 Thread Steven Bethard
Tim Hochberg wrote: Tim Hochberg wrote: I don't think that's correct. I think that with a suitably designed HtmlDocument object, the following should be possible: with HtmlDocument(Title) as doc: with doc.element(body): doc.text(before first h1) with doc.element(h1,

Re: PEP 359: The make Statement

2006-04-14 Thread Steven Bethard
Nicolas Fleury wrote: Steven Bethard wrote: Ok, I finally have a PEP number. Here's the most updated version of the make statement PEP. I'll be posting it shortly to python-dev. Thanks again for the previous discussion and suggestions! I find it very interesting. My only complaint

Re: PEP 359: The make Statement

2006-04-14 Thread Steven Bethard
Duncan Booth wrote: Steven Bethard wrote: Should users of the make statement be able to determine in which dict object the code is executed? The make statement could look for a ``__make_dict__`` attribute and call it to allow things like:: make Element html: make Element

Re: PEP 359: The make Statement

2006-04-14 Thread Steven Bethard
Steven Bethard wrote: Duncan Booth wrote: Steven Bethard wrote: Should users of the make statement be able to determine in which dict object the code is executed? The make statement could look for a ``__make_dict__`` attribute and call it to allow things like:: make Element html

and ... (WAS PEP 359: The make Statement)

2006-04-14 Thread Steven Bethard
Felipe Almeida Lessa wrote: Em Sex, 2006-04-14 às 09:31 -0600, Steven Bethard escreveu: [1] Here's the code I used to test it. def make(callable, name, args, block_string): ... try: ... make_dict = callable.__make_dict__ ... except AttributeError

Re: PEP 359: The make Statement

2006-04-14 Thread Steven Bethard
Rob Williscroft wrote: Steven Bethard wrote in news:[EMAIL PROTECTED] in comp.lang.python: Open Issues === Does the ``make`` keyword break too much code? Originally, the make statement used the keyword ``create`` (a suggestion due to Nick Coghlan). However, investigations

Re: PEP 359: The make Statement

2006-04-14 Thread Steven Bethard
Tim Hochberg wrote: Steven Bethard wrote: Steven Bethard wrote: Duncan Booth wrote: make Element html: make Element body: make Element p: text('But this ') make Element strong: text('could') text(' be made to work

Re: PEP 359: The make Statement

2006-04-14 Thread Steven Bethard
Steven Bethard wrote: Tim Hochberg wrote: Steven Bethard wrote: Steven Bethard wrote: Duncan Booth wrote: make Element html: make Element body: make Element p: text('But this ') make Element strong: text('could') text(' be made

Re: list.clear() missing?!?

2006-04-13 Thread Steven Bethard
Raymond Hettinger wrote: [Steven Bethard] I think these are all good reasons for adding a clear method, but being that it has been so hotly contended in the past, I don't think it will get added without a PEP. Anyone out there willing to take out the best examples from this thread and turn

PEP 359: The make Statement

2006-04-13 Thread Steven Bethard
:36:24 -0600 (Thu, 13 Apr 2006) $ Author: Steven Bethard [EMAIL PROTECTED] Status: Draft Type: Standards Track Content-Type: text/x-rst Created: 05-Apr-2006 Python-Version: 2.6 Post-History: 05-Apr-2006, 06-Apr-2006 Abstract This PEP proposes a generalization of the class-declaration

Re: namespace issue

2006-04-13 Thread Steven Bethard
Daniel Nogradi wrote: I would like to give the same name to a keyword argument of a class method as the name of a function, with the function and the class living in the same namespace and the class method using the aforementioned function. So far I've been unsuccesfully trying to go along

Re: list.clear() missing?!?

2006-04-12 Thread Steven Bethard
Steven D'Aprano wrote: On Tue, 11 Apr 2006 14:49:04 -0700, Ville Vainio wrote: John Salerno wrote: Thanks guys, your explanations are really helpful. I think what had me confused at first was my understanding of what L[:] does on either side of the assignment operator. On the left, it just

Re: list.clear() missing?!?

2006-04-12 Thread Steven Bethard
John Salerno wrote: Steven Bethard wrote: I think these are all good reasons for adding a clear method, but being that it has been so hotly contended in the past, I don't think it will get added without a PEP. Anyone out there willing to take out the best examples from this thread

Re: updated pre-PEP: The create statement

2006-04-11 Thread Steven Bethard
Michele Simionato wrote: Peter Hansen wrote: Michele Simionato wrote: You can pull out the example in the official PEP, if you like. Please do. If this is supposed to have anything to do with namespaces, it has nothing to do with the type of data structures XML is capable of and the

Re: list.clear() missing?!?

2006-04-11 Thread Steven Bethard
Ville Vainio wrote: I tried to clear a list today (which I do rather rarely, considering that just doing l = [] works most of the time) and was shocked, SHOCKED to notice that there is no clear() method. Dicts have it, sets have it, why do lists have to be second class citizens? This gets

Re: pre-PEP: The create statement

2006-04-11 Thread Steven Bethard
John J. Lee wrote: Michele Simionato [EMAIL PROTECTED] writes: [...] This agrees with my scan (except I also found an occurrence of 'create' in Tkinter). BTW, I would be curious to see the script you are using for the scanning. Are you using tokenize too? In am quite fond of the tokenize

Re: Python 3.0 or Python 3000?

2006-04-09 Thread Steven Bethard
John Salerno wrote: Is 'Python 3000' just a code name for version 3.0, or will it really be called that when it's released? Actually, there's an official response these days in `PEP 3000`_: Naming Python 3000, Python 3.0 and Py3K are all names for the same thing. The project is called

Re: updated pre-PEP: The create statement

2006-04-07 Thread Steven Bethard
Carl Banks wrote: Steven Bethard wrote: I've updated the PEP based on a number of comments on comp.lang.python. The most updated versions are still at: http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt http://ucsu.colorado.edu/~bethard/py/pep_create_statement.html

Re: pre-PEP: The create statement

2006-04-06 Thread Steven Bethard
Michael Ekstrand wrote: Something it could be useful to try to add, if possible: So far, it seems that this create block can only create class-like things (objects with a name, potentially bases, and a namespace). Is there a natural way to extend this to other things, so that function creation

Re: pre-PEP: The create statement

2006-04-06 Thread Steven Bethard
Tim N. van der Leeuw wrote: Could this still make it in Python 2.5 even? If it's pushed hard enough? I don't know if this has been discussed on the python-dev mailing lists and what the reactions of python-devs and GvR was? Unlikely. I haven't posted it to python-dev yet, and they've basically

Re: pre-PEP: The create statement

2006-04-06 Thread Steven Bethard
Carl Banks wrote: Steven Bethard wrote: This PEP proposes a generalization of the class-declaration syntax, the ``create`` statement. The proposed syntax and semantics parallel the syntax for class definition, and so:: create callable name tuple: block is translated

updated pre-PEP: The create statement

2006-04-06 Thread Steven Bethard
to be applied to a wider variety of callables; the latter keeps a better parallel with the class statement. PEP: XXX Title: The create statement Version: $Revision: 1.4 $ Last-Modified: $Date: 2003/09/22 04:51:50 $ Author: Steven Bethard [EMAIL PROTECTED] Status: Draft Type: Standards Track Content

Re: pre-PEP: The create statement

2006-04-06 Thread Steven Bethard
Michele Simionato wrote: Carl Banks wrote: create module mod: This creates a sub-module named mod with an f1 function def f1(): ... Let's not do this, really. A module should be one-to-one with a file, and you should be able to import any module.

Re: updated pre-PEP: The create statement

2006-04-06 Thread Steven Bethard
Michele Simionato wrote: Steven Bethard wrote: I've updated the PEP based on a number of comments on comp.lang.python. The most updated versions are still at: http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt http://ucsu.colorado.edu/~bethard/py

Re: updated pre-PEP: The create statement

2006-04-06 Thread Steven Bethard
Steven Bethard wrote: I've updated the PEP based on a number of comments on comp.lang.python. The most updated versions are still at: http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt http://ucsu.colorado.edu/~bethard/py/pep_create_statement.html In this post, I'm

Re: pre-PEP: The create statement

2006-04-06 Thread Steven Bethard
Terry Reedy wrote: Michele Simionato [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] This is a very relevant question. I would expect the new keyword would break lots of modules. However measuring is better than speculating. Please run also with alternatives, such as 'make'. I

Re: updated pre-PEP: The create statement

2006-04-06 Thread Steven Bethard
and so far I (Steven Bethard) have not been able to implement Steven the feature without the keyword. Someone mentioned using make instead of create. In both my own code as well as the Python source, use of make is much less prevalent than create. Yep. The next version of the PEP

pre-PEP: The create statement

2006-04-05 Thread Steven Bethard
: $Revision: 1.4 $ Last-Modified: $Date: 2003/09/22 04:51:50 $ Author: Steven Bethard [EMAIL PROTECTED] Status: Draft Type: Standards Track Content-Type: text/x-rst Created: 05-Apr-2006 Python-Version: 2.6 Post-History: 05-Apr-2006 Abstract This PEP proposes a generalization of the class

Re: New-style Python icons

2006-03-27 Thread Steven Bethard
Robin Becker wrote: Steven Bethard wrote: ... http://www.doxdesk.com/img/software/py/icons.zip I just wanted to say that I've been using these icons for almost a week now and I love them! I'd like to reiterate EuGeNe's request that these go into the Python 2.5 release if at all

Re: pondering about the essence of types in python

2006-03-26 Thread Steven Bethard
gangesmaster wrote: i dont think it's possible, to create proxy classes, but even if i did, calling remote methods with a `self` that is not an instance of the remote class would blow up. I don't understand you here. Why can't you just do something like: class RemoteClass(object): ...

Re: maximum() efficency

2006-03-26 Thread Steven Bethard
Steve R. Hastings wrote: I was looking at a Python function to find the maximum from a list. The original was more complicated; I simplified it. The built-in max() function can replace the simplified example, but not the original. What's the original? Are you sure max can't solve it with an

Re: New-style Python icons

2006-03-26 Thread Steven Bethard
[EMAIL PROTECTED] wrote: Personally, I *like* the new website look, and I'm glad to see Python having a proper logo at last! I've taken the opportunity to knock up some icons using it, finally banishing the poor old standard-VGA-palette snake from my desktop. If you like, you can grab them

Re: maximum() efficency

2006-03-26 Thread Steven Bethard
Steve R. Hastings wrote: On Sun, 26 Mar 2006 10:34:16 -0700, Steven Bethard wrote: What's the original? def minimum(cmp, lst): minimum(cmp, lst) Returns the minimal element in non-empty list LST with elements compared via CMP() which should return values with the same semantics

Re: pondering about the essence of types in python

2006-03-25 Thread Steven Bethard
gangesmaster wrote: but __mro__ is a readonly attribute, and deriving from instances is impossible (conn.modules.wx.Frame is a PROXY to the class)... Maybe I'm misunderstanding, but why is an instance a proxy to a class? Why don't you make a class a proxy to the class? STeVe --

Re: Python types

2006-03-24 Thread Steven Bethard
Salvatore wrote: I've read several articles where it's said that Python is weakly typed. I'm a little surprised. All objects seem to have a perfectly defined type Hoping to head off another debate: http://wiki.python.org/moin/StrongVsWeakTyping STeVe --

Re: multiple assignment

2006-03-23 Thread Steven Bethard
Anand wrote: Wouldn't it be nice to say id, *tokens = line.split(',') id, tokens_str = line.split(',', 1) But then you have to split tokens_str again. id, tokens_str = line.split(',', 1) tokens = tokens_str.split(',') Sorry, it wasn't clear that you needed the tokens from the original

Re: Per instance descriptors ?

2006-03-23 Thread Steven Bethard
bruno at modulix wrote: Steven Bethard wrote: Could you explain again why you don't want baaz to be a class-level attribute? Because the class is a decorator for many controller functions, and each controller function will need it's own set of descriptors, so I don't want to mess

Re: Per instance descriptors ?

2006-03-23 Thread Steven Bethard
bruno at modulix wrote: Using a class as a decorator, I have of course only one instance of it per function - and for some attributes, I need an instance per function call. Per function call? And you want the attributes on the function, not the result of calling the function? If so, that'd

Re: multiple assignment

2006-03-22 Thread Steven Bethard
Anand wrote: Wouldn't it be nice to say id, *tokens = line.split(',') id, tokens_str = line.split(',', 1) STeVe -- http://mail.python.org/mailman/listinfo/python-list

Re: Per instance descriptors ?

2006-03-22 Thread Steven Bethard
bruno at modulix wrote: Hi I'm currently playing with some (possibly weird...) code, and I'd have a use for per-instance descriptors, ie (dummy code): class DummyDescriptor(object): def __get__(self, obj, objtype=None): if obj is None: return self return getattr(obj,

Re: Why class exceptions are not deprecated?

2006-03-21 Thread Steven Bethard
Gregory Petrosyan wrote: 1) From 2.4.2 documentation: There are two new valid (semantic) forms for the raise statement: raise Class, instance raise instance Check `PEP 8`_ -- the latter form is preferred: When raising an exception, use raise ValueError('message') instead of the older form

Re: strange math?

2006-03-18 Thread Steven Bethard
[EMAIL PROTECTED] wrote: f(01) 43 f(02) 44 f(010) 50 42+010 50 The first f(01) was a mistake. I accidentally forgot to delete the zero, but to my suprise, it yielded the result I expected. So, I tried it again, and viola, the right answer. So, I decided to really try and throw it

Re: int - str asymmetric

2006-03-16 Thread Steven Bethard
Schüle Daniel wrote: however we lack the reverse functionality the logical str(10,2) Traceback (most recent call last): File stdin, line 1, in ? TypeError: str() takes at most 1 argument (2 given) fails it would not break anything if str interface would be changed what do you

Re: Python Documentation Standards

2006-03-16 Thread Steven Bethard
Colin J. Williams wrote: Doc strings provide us with a great opportunity to illuminate our code. In the example below, __init__ refers us to the class's documentation, but the class doc doesn't help much. It doesn't? print list.__doc__ list() - new list list(sequence) - new list

Re: stdin or optional fileinput

2006-03-15 Thread Steven Bethard
the.theorist wrote: I was writing a small script the other day with the following CLI prog [options] [file]* I've used getopt to parse out the possible options, so we'll ignore that part, and assume for the rest of the discussion that args is a list of file names (if any provided). I

Re: elementtree and gbk encoding

2006-03-15 Thread Steven Bethard
Fredrik Lundh wrote: Steven Bethard wrote: I'm having trouble using elementtree with an XML file that has some gbk-encoded text. (I can't read Chinese, so I'm taking their word for it that it's gbk-encoded.) I always have trouble with encodings, so I'm sure I'm just screwing something

Re: elementtree and gbk encoding

2006-03-15 Thread Steven Bethard
Fredrik Lundh wrote: Steven Bethard wrote: Hmm... I downloaded the newest cElementTree (and I already had the newest ElementTree), and here's what I get: tree = myparser(filename, 'gbk') Traceback (most recent call last): File interactive input, line 1, in ? File interactive

Re: Cheese Shop: some history for the new-comers

2006-03-14 Thread Steven Bethard
A.M. Kuchling wrote: On Sun, 12 Mar 2006 10:25:19 +0100, Fredrik Lundh [EMAIL PROTECTED] wrote: and while you're at it, change python-dev to developers and psf to foundation (or use a title on that link). I've changed the PSF link, but am not sure what to do about the python-dev

elementtree and gbk encoding

2006-03-14 Thread Steven Bethard
I'm having trouble using elementtree with an XML file that has some gbk-encoded text. (I can't read Chinese, so I'm taking their word for it that it's gbk-encoded.) I always have trouble with encodings, so I'm sure I'm just screwing something simple up. Can anyone help me? Here's the

Re: elementtree and gbk encoding

2006-03-14 Thread Steven Bethard
Diez B. Roggisch wrote: Steven Bethard schrieb: I'm having trouble using elementtree with an XML file that has some gbk-encoded text. (I can't read Chinese, so I'm taking their word for it that it's gbk-encoded.) I always have trouble with encodings, so I'm sure I'm just screwing

Re: elementtree and gbk encoding

2006-03-14 Thread Steven Bethard
Diez B. Roggisch wrote: Here's what I get with the prepending hack: et.fromstring('?xml version=1.0 encoding=gbk?\n' + open(filename).read()) Traceback (most recent call last): File interactive input, line 1, in ? File C:\Program

Re: PEP 8 example of 'Function and method arguments'

2006-03-13 Thread Steven Bethard
Martin P. Hellwig wrote: While I was reading PEP 8 I came across this part: Function and method arguments Always use 'self' for the first argument to instance methods. Always use 'cls' for the first argument to class methods. Now I'm rather new to programming and unfamiliar to

Re: Accessing overridden __builtin__s?

2006-03-13 Thread Steven Bethard
[EMAIL PROTECTED] wrote: I'm having a scoping problem. I have a module called SpecialFile, which defines: def open(fname, mode): return SpecialFile(fname, mode) class SpecialFile: def __init__(self, fname, mode): self.f = open(fname, mode) ... [snip] How do I tell

Re: question about slicing with a step length

2006-03-09 Thread Steven Bethard
John Salerno wrote: Given: numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] can someone explain to me why numbers[10:0:-2] results in [10, 8, 6, 4, 2]? I've filed a bug report: http://bugs.python.org/1446619 I suggest the following rewording for extended slices: To get the slice of s

Re: New python.org website

2006-03-09 Thread Steven Bethard
Roy Smith wrote: I'm OK with bold for stuff like this, but the wording could be better. The last sentence: Many Python programmers report substantial productivity gains and feel the language encourages the development of higher quality, more maintainable code. reads

Re: Why property works only for objects?

2006-03-09 Thread Steven Bethard
Michal Kwiatkowski wrote: Code below shows that property() works only if you use it within a class. Yes, descriptors are only applied at the class level (that is, only class objects call the __get__ methods). Is there any method of making descriptors on per-object basis? I'm still not

Re: question about slicing with a step length

2006-03-08 Thread Steven Bethard
John Salerno wrote: Given: numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] can someone explain to me why numbers[10:0:-2] results in [10, 8, 6, 4, 2]? I always have trouble with these. Given the docs[1]: The slice of s from i to j with step k is defined as the sequence of items with index

Re: New python.org website

2006-03-07 Thread Steven Bethard
Phoe6 wrote: beta.python.org evolved very nice and noticed today the new python.org website going live. There is a change in the look n feel, wherein it looks more official and maximum possible information about python is now directly accessible from the home page itself. Kudoes to the

Re: Suggesting the use of StandardError as base of error Exceptions.

2006-03-06 Thread Steven Bethard
Antoon Pardon wrote: I then took a look at http://docs.python.org/lib/module-exceptions.html which describes the exception heirarchy as follows: Exception +-- SystemExit +-- StopIteration +-- StandardError | + | + All kind of error exceptions | +

Re: Opening files without closing them

2006-03-05 Thread Steven Bethard
Sandra-24 wrote: I was reading over some python code recently, and I saw something like this: contents = open(file).read() And of course you can also do: open(file, w).write(obj) Why do they no close the files? Is this sloppy programming or is the file automatically closed when the

<    3   4   5   6   7   8   9   10   11   12   >