Re: slice notation as values?

2005-12-10 Thread Steven Bethard
Antoon Pardon wrote: > On 2005-12-10, Steven Bethard <[EMAIL PROTECTED]> wrote: > >>Antoon Pardon wrote: >> >>>So lets agree that tree['a':'b'] would produce a subtree. Then >>>I still would prefer the possibility to do something like

Re: double underscore attributes?

2005-12-10 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > Every time I use dir(some module) I get a lot of attributes with double > underscore, for example __add__. Ok, I thought __add__ must be a method > which I can apply like this > 5.__add(8) > > However Python responded > SyntaxError: invalid syntax > > I tried > >>

Re: instance + classmethod question

2005-12-11 Thread Steven Bethard
Laszlo Zsolt Nagy wrote: > > Hello, > > Is it possible to tell, which instance was used to call the classmethod > that is currently running? > [snip] > > processor = SQLProcessors.StdOutProcessor() # Print to stdout > PostgreSQLConnection.process_create_tables(processor,dbdef) # This > soul

Re: instance + classmethod question

2005-12-11 Thread Steven Bethard
Laszlo Zsolt Nagy wrote: > In my methods, most code is about string manipulation and calling other > classmethods. > There are only a few places where I can use an instance, but it is not > required. > I would like to reuse as most code as possible, so I do not want to > create two different > m

Re: lambda (and reduce) are valuable

2005-12-11 Thread Steven Bethard
Paul Rubin wrote: > Chris Mellon <[EMAIL PROTECTED]> writes: > >>As someone who does a tremendous amount of event-driven GUI >>programming, I'd like to take a moment to speak out against people >>using us as a testament to the virtues of lamda. Event handlers are >>the most important part of event

Re: IsString

2005-12-12 Thread Steven Bethard
Tuvas wrote: > I need a function that will tell if a given variable is a character or > a number. Is there a way to do this? Thanks! What's your use case? This need is incommon in Python... STeVe -- http://mail.python.org/mailman/listinfo/python-list

Re: IsString

2005-12-12 Thread Steven Bethard
Steven D'Aprano wrote: > Judging by the tone of the original poster's question, I'd say for sure he > is an utter Python newbie, probably a newbie in programming in general, > so I bet that what (s)he really wants is something like this: > > somefunction("6") > -> It is a number. > > somefunction

Re: "0 in [True,False]" returns True

2005-12-12 Thread Steven Bethard
Pierre Quentel wrote: > In some program I was testing if a variable was a boolean, with this > test : if v in [True,False] > > My script didn't work in some cases and I eventually found that for v = > 0 the test returned True This seems like a strange test. What is this code trying to do? If

Re: Python Graph API

2005-12-13 Thread Steven Bethard
Nathan Gilbert wrote: > Has there been any work done lately on the Python Graph API? Well there doesn't really seem to be a standard one. The wiki was last updated in August. http://wiki.python.org/moin/PythonGraphApi STeVe -- http://mail.python.org/mailman/listinfo/python-list

Re: ?: in Python

2005-12-14 Thread Steven Bethard
Andy Leszczynski wrote: > How can do elegantly in Python: > > if condition: >a=1 > else: >a=2 > > like in C: > > a=condition?1:2 Step (1): Wait for Python 2.5[1] Step (2): Write the code:: a = 1 if condition else 2 STeVe [1]http://www.python.org/peps/pep-0308.html -- http://mai

Re: Try Python update

2006-01-05 Thread Steven Bethard
Mike Meyer wrote: > The url is http://www.mired.org/home/mwm/try_python/. Reports of > problems would appreciated. You're probably already aware of this, but the online help utility doesn't work. It exits before you can type anything into it:

Re: how to test for a dependency

2006-01-09 Thread Steven Bethard
Darren Dale wrote: > I would like to test that latex is installed on a windows, mac or linux > machine. What is the best way to do this? This should work: > > if os.system('latex -v'): > print 'please install latex' > > but I dont actually want the latex version information to print to screen

Re: Why keep identity-based equality comparison?

2006-01-10 Thread Steven Bethard
Mike Meyer wrote: > [EMAIL PROTECTED] writes: > >> My question is, what reasons are left for leaving the current default >> equality operator for Py3K, not counting backwards-compatibility? >> (assume that you have idset and iddict, so explicitness' cost is only >> two characters, in Guido's examp

Re: Why keep identity-based equality comparison?

2006-01-11 Thread Steven Bethard
Mike Meyer wrote: > Steven Bethard writes: > >> Not to advocate one way or the other, but how often do you use >> heterogeneous containers? > > Pretty much everything I do has heterogenous containers of some sort > or another. Sorry, I should have been a lit

Re: Help with super()

2006-01-13 Thread Steven Bethard
David Hirschfield wrote: > Here's an example that's giving me trouble, I know it won't work, but it > illustrates what I want to do: > > class A(object): >_v = [1,2,3] > def _getv(self): >if self.__class__ == A: >return self._v >return super(self.__class__,sel

Re: decode unicode string using 'unicode_escape' codecs

2006-01-13 Thread Steven Bethard
aurora wrote: > I have some unicode string with some characters encode using python > notation like '\n' for LF. I need to convert that to the actual LF > character. There is a 'unicode_escape' codec that seems to suit my purpose. > encoded = u'A\\nA' decoded = encoded.decode('unicod

Re: Shrinky-dink Python (also, non-Unicode Python build is broken)

2006-01-16 Thread Steven Bethard
Larry Hastings wrote: > Of course, it's not the most important thing in the world--after all, > I'm the first person to even *notice*, right? But it seems a shame > that > one can break the build so easily. If it pleases the stewards of > Python, I would be happy to submit patches that fix the no

Re: Arithmetic sequences in Python

2006-01-17 Thread Steven Bethard
Antoon Pardon wrote: > Why don't we give slices more functionality and use them. > These are a number of ideas I had. (These are python3k ideas) > > 1) Make slices iterables. (No more need for (x)range) > > 2) Use a bottom and stop variable as default for the start and >stop attribute. top wo

Re: magical expanding hash

2006-01-17 Thread Steven Bethard
Paul Rubin wrote: > Hmm, > >x[a][b][c][d] = e# x is a "magic" dict > > becomes > >x.setdefault(a,{}).setdefault(b,{}).setdefault(c,{})[d] = e > > if I understand correctly. Ugh. Agreed. I really hope that Python 3.0 applies Raymond Hettinger's suggestion "Improved default value

Re: Arithmetic sequences in Python

2006-01-17 Thread Steven Bethard
Gregory Petrosyan wrote: > Hey guys, this proposal has already been rejected (it is the PEP 204). No, this is a subtly different proposal. Antoon is proposing *slice* literals, not *range* literals. Note that "confusion between ranges and slice syntax" was one of the reasons for rejection of `

Re: magical expanding hash

2006-01-17 Thread Steven Bethard
Steve Holden wrote: > Steven Bethard wrote: >> Agreed. I really hope that Python 3.0 applies Raymond Hettinger's >> suggestion "Improved default value logic for Dictionaries" from >> http://wiki.python.org/moin/Python3%2e0Suggestions >> >> Th

Re: Arithmetic sequences in Python

2006-01-18 Thread Steven Bethard
Alex Martelli wrote: > Tom Anderson <[EMAIL PROTECTED]> wrote: >> Sounds good. More generally, i'd be more than happy to get rid of list >> comprehensions, letting people use list(genexp) instead. That would >> obviously be a Py3k thing, though. > > I fully agree, but the BDFL has already (tentat

use cases for a defaultdict

2006-01-18 Thread Steven Bethard
Steven Bethard wrote: > Agreed. I really hope that Python 3.0 applies Raymond Hettinger's > suggestion "Improved default value logic for Dictionaries" from > http://wiki.python.org/moin/Python3%2e0Suggestions > > This would allow you to make the setdef

list(...) and list comprehensions (WAS: Arithmetic sequences in Python)

2006-01-18 Thread Steven Bethard
ut the BDFL has already (tentatively, I hope) > Pronounced that the [...] form will stay in Py3K as syntax sugar for > list(...). I find that to be a truly hateful prospect, but that's the > prospect:-(. Steven Bethard wrote: > I'm not sure I find it truly hateful, but definitely u

Re: Arithmetic sequences in Python

2006-01-19 Thread Steven Bethard
Steven D'Aprano wrote: > Steven Bethard wrote: > >> I'm not sure I find it truly hateful, but definitely unnecessary. >> TOOWTDI and all... > [snip] > > Even when people mean One Obvious and not Only One, it is still harmful > because the emphasis is wr

[OT] no goto (WAS: Python code written in 1998...)

2006-01-19 Thread Steven Bethard
Carl Cerecke wrote: > Python has no goto. Not in the standard library. You have to download the module: http://www.entrian.com/goto/ ;) STeVe -- http://mail.python.org/mailman/listinfo/python-list

Re: PyXML: SAX vs. DOM

2006-01-20 Thread Steven Bethard
Matthias Kaeppler wrote: > I have to say I am confused about the documentation on pyxml.sf.net. > When I want to use DOM, I effectively am using a class called Sax2? ^^ > I also have to catch SAXExceptions, which reside in xml.sax._exceptions. > > I thought DOM and SAX are two completely different

[ANN] The argparse module

2006-08-02 Thread Steven Bethard
tation of this module, so the APIs are still subject to change. If you find it of interest, and you'd like to help improve it, I'd be glad to open the project up to more developers. Bug reports can be made through Trac at: http://argparse.python-hosting.com/newticket Steven Bethard -- http://mail.python.org/mailman/listinfo/python-list

python-dev summary for 2006-06-16 to 2006-06-30

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

Re: What is the best way to print the usage string ?

2006-08-03 Thread Steven Bethard
Leonel Gayard wrote: > Hi all, > > I had to write a small script, and I did it in python instead of > shell-script. My script takes some arguments from the command line, > like this. > > import sys > args = sys.argv[1:] > if args == []: > print """Concat: concatenates the arguments with a col

Re: What is the best way to print the usage string ?

2006-08-04 Thread Steven Bethard
Ben Finney wrote: > "Leonel Gayard" <[EMAIL PROTECTED]> writes: > >> import sys >> args = sys.argv[1:] >> if args == []: >> print """Concat: concatenates the arguments with a colon (:) between >> them >> Usage: concat arg1 [arg2...] >> Example: concat a b c prints \"a.jar:b.jar:c/\ >>

Re: #!/usr/bin/python or #!/usr/bin/env python?

2006-08-08 Thread Steven Bethard
John Salerno wrote: > I understand the difference, but I'm just curious if anyone has any > strong feelings toward using one over the other? I was reading that a > disadvantage to the more general usage (i.e. env) is that it finds the > first python on the path, and that might not be the proper

Re: outputting a command to the terminal?

2006-08-14 Thread Steven Bethard
John Salerno wrote: > Here's my new project: I want to write a little script that I can type > at the terminal like this: > > $ scriptname package1 [package2, ...] > > where scriptname is my module name and any subsequent arguments are the > names of Linux packages to install. Running the scrip

Re: outputting a command to the terminal?

2006-08-14 Thread Steven Bethard
John Salerno wrote: > Steven Bethard wrote: >> scriptname.py >> import argparse # http://argparse.python-hosting.com/ >> import subprocess >> import sys >> >> def outputfile(filename): >>

Re: outputting a command to the terminal?

2006-08-14 Thread Steven Bethard
Yu-Xi Lim wrote: > Steven Bethard wrote: >> import argparse # http://argparse.python-hosting.com/ >> import subprocess >> import sys > > Why not the standard lib's optparse? The page referenced above gives a variety of reasons, but the two most important thin

Re: modifying __new__ of list subclass

2006-08-14 Thread Steven Bethard
Ken Schutte wrote: > I want an int-derived class that is initilized to one greater than what > it's constructor is given: > > class myint(int): > def __new__(cls, intIn): > newint = int(intIn+1) > return int.__new__(cls, newint) Or simply: class myint(int): def __new__(cls, int_i

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

2006-08-14 Thread steven . bethard
python-dev Summary for 2006-07-01 through 2006-07-15 .. contents:: [The HTML version of this Summary is available at http://www.python.org/dev/summary/2006-07-01_2006-07-15] = Announcements = --- Pyth

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

2006-08-14 Thread steven . bethard
python-dev Summary for 2006-07-16 through 2006-07-31 .. contents:: [The HTML version of this Summary is available at http://www.python.org/dev/summary/2006-07-16_2006-07-31] = Announcements = --- Pyth

Re: modifying __new__ of list subclass

2006-08-15 Thread Steven Bethard
Ken Schutte wrote: > Steven Bethard wrote: >> >> The __new__ method is for immutable types. So things like str and int >> do their initialization in __new__. But for regular mutable types, >> you should do your initialization in __init__:: > > I see...

Re: groupby and itemgetter

2006-10-06 Thread Steven Bethard
Roman Bertle wrote: > Hello, > > there is an example how to use groupby in the itertools documentation > (http://docs.python.org/lib/itertools-example.html): > > # Show a dictionary sorted and grouped by value from operator import itemgetter d = dict(a=1, b=2, c=1, d=2, e=1, f=2, g=3) >

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

2006-10-09 Thread steven . bethard
python-dev Summary for 2006-08-01 through 2006-08-15 .. contents:: [The HTML version of this Summary is available at http://www.python.org/dev/summary/2006-08-01_2006-08-15] = Summaries = Mix

[ANN] argparse 0.1 - Command-line parsing library

2006-10-09 Thread Steven Bethard
Announcing argparse 0.1 --- argparse home: http://argparse.python-hosting.com/ argparse at PyPI: http://www.python.org/pypi/argparse/0.1.0 argparse module download: http://argparse.python-hosting.com/file/trunk/argparse.py?format=raw About this release ===

Re: [ANN] argparse 0.1 - Command-line parsing library

2006-10-10 Thread Steven Bethard
Steven Bethard wrote: > Announcing argparse 0.1 > --- > > argparse home: > http://argparse.python-hosting.com/ > > argparse at PyPI: > http://www.python.org/pypi/argparse/0.1.0 > > argparse module download: > http://argparse.python-h

elementsoap with Python 2.5

2006-10-10 Thread Steven Bethard
I was trying to get elementsoap_ working with just xml.etree from Python 2.5 (and no standalone elementtree installation). I think I got everything working by changing the imports and copying in the FancyTreeBuilder class (since only TreeBuilder and XMLTreeBuilder are in the xml.etree.ElementT

Re: Alternative constructors naming convention

2006-10-11 Thread Steven Bethard
Will McGugan wrote: > Is there a naming convention regarding alternative constructors? ie > static methods where __new__ is called explicity. Are you really using staticmethod and calling __new__? It's often much easier to use classmethod, e.g.:: class Color(object): ...

Re: Loops Control with Python

2006-10-13 Thread Steven Bethard
hg wrote: > How about a thread on GOTOs ? ;-) A thread? No need! There's a module: http://entrian.com/goto/ ;-) STeVe -- http://mail.python.org/mailman/listinfo/python-list

Re: optparse: add trailing text in help message?

2006-10-14 Thread Steven Bethard
Count László de Almásy wrote: > Is there a standard way with optparse to include a blurb of text after > the usage section, description, and the list of options? This is > often useful to include examples or closing comments when the help > message is printed out. Many of the GNU commands do this

Re: optparse: add trailing text in help message?

2006-10-14 Thread Steven Bethard
Duncan Booth wrote: from optparse import OptionParser usage = "usage: %prog [options] arg1 arg2" epilog = "that's all folks!" parser = OptionParser(usage=usage, epilog=epilog) parser.parse_args(['', '--help']) > Usage: [options] arg1 arg2 > > Options: > -h, --help show

classroom constraint satisfaction problem

2006-10-15 Thread Steven Bethard
I'm trying to solve a constraint-satisfaction problem, and I'm having some troubles framing my problem in such a way that it can be efficiently solved. Basically, I want to build groups of two teachers and four students such that [1]: * Students are assigned to exactly one group * Teachers are

Re: Tertiary Operation

2006-10-17 Thread Steven Bethard
abcd wrote: > x = None > result = (x is None and "" or str(x)) > print result, type(result) > > --- > OUTPUT > --- > None > > [snip] > ...what's wrong with the first operation I did with x? You weren't using Python 2.5: Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MS

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

2006-10-18 Thread steven . bethard
python-dev Summary for 2006-08-16 through 2006-08-31 .. contents:: [The HTML version of this Summary is available at http://www.python.org/dev/summary/2006-08-16_2006-08-31] = Announcements =

Re: How to execute a linux command by python?

2006-10-18 Thread Steven Bethard
Daniel Nogradi wrote: >> > How to execute a linux command by python? >> > for example: execute "ls" or "useradd oracle" >> > Who can help me? >> >> start here: >> >> http://www.python.org/doc/lib/ > > And continue here: > > http://www.python.org/doc/lib/os-process.html You probably should

Re: Why can't you pickle instancemethods?

2006-10-20 Thread Steven Bethard
Chris wrote: > Why can pickle serialize references to functions, but not methods? Here's the recipe I use:: def _pickle_method(method): func_name = method.im_func.__name__ obj = method.im_self cls = method.im_class return _unpickle_method, (func_name, obj,

Re: classroom constraint satisfaction problem

2006-10-23 Thread Steven Bethard
Carl Banks wrote: > Steven Bethard wrote: >> Basically, I want to build groups of two teachers and four students such >> that [1]: >> >> * Students are assigned to exactly one group >> * Teachers are assigned to approximately the same number of groups >>

[ANN] argparse 0.2 - Command-line parsing library

2006-10-24 Thread Steven Bethard
Announcing argparse 0.2 --- argparse home: http://argparse.python-hosting.com/ argparse single module download: http://argparse.python-hosting.com/file/trunk/argparse.py?format=raw argparse bundled downloads at PyPI: http://www.python.org/pypi/argparse/ About this releas

Re: The status of Python and SOAP?

2006-10-24 Thread Steven Bethard
Larry Bates wrote: > I would venture to guess that this is the one I would lean towards > if I needed SOAP support: > > http://www.effbot.org/downloads/#elementsoap > > I know is says "experimental" but Fredrik Lundh's idea of experimental > always seems to be everyone else's idea of a shipping p

Re: Is there a python development site for putting up python libraries that people might be interest in working on?

2006-10-25 Thread Steven Bethard
Kenneth McDonald wrote: > I would like to avoid putting this up on sourceforge as I think it would > do much better at a site aimed specifically at Python development. I've been using python-hosting.com for the argparse module and found it to be a pretty good solution. They offer free Trac/Subv

Re: What's the best IDE?

2006-10-25 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > Recently I've had some problems with PythonWin when I switched to > Py2.5, tooka long hiatus, and came back. So now I'm without my god sent > helper, and I'm looking for a cool replacement, or some advocation to > reinstall/setup PyWin. But the Python website's list is ir

Re: Sorting by item_in_another_list

2006-10-26 Thread Steven Bethard
Cameron Walsh wrote: > Which brings me to the question, would this solution: > > B = set(B) > A = B + list(x for x in A if x not in B) > > be faster than this solution: > > B = set(B) > A.sort(key=B.__contains__, reverse=True) > > My guess is yes, since while the __contains__ method is only run

Re: Sorting by item_in_another_list

2006-10-26 Thread Steven Bethard
Paul Rubin wrote: > Steven Bethard <[EMAIL PROTECTED]> writes: >> Cameron Walsh wrote: >>> Which brings me to the question, would this solution: >>> B = set(B) >>> A = B + list(x for x in A if x not in B) >>> be faster than this solution: >>

python-dev Summary for 2006-09-16 through 2006-09-30

2006-11-03 Thread steven . bethard
python-dev Summary for 2006-09-16 through 2006-09-30 .. contents:: [The HTML version of this Summary is available at http://www.python.org/dev/summary/2006-09-16_2006-09-30] = Summaries = --- Import features

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

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

Re: Python Distilled

2006-11-06 Thread Steven Bethard
Simon Wittber wrote: > I want to build a Python2.5 interpreter for an embedded system. I only > have 4MB of RAM to play with, so I want to really minimise the python > binary. [snip] > Google tells me that people have done this before, back in Python1.5.2 > days. Has anyone tried to do this recentl

Re: Python development time is faster.

2006-11-13 Thread Steven Bethard
Chris Brat wrote: > I've seen a few posts, columns and articles which state that one of the > advantages of Python is that code can be developed x times faster than > languages such as <>. > > Does anyone have any comments on that statement from personal > experience? I had to work at a laborator

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

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 consecut

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 (sometim

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:

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 specif

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 wo

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. Do

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

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

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

2006-06-06 Thread Steven Bethard
me rewriting of the tools that currently do string extraction using ``_()``, so the idea was rejected. Contributing thread: - `The "i" string-prefix: I18n'ed strings <http://mail.python.org/pipermail/python-dev/2006-April/063488.html>`__ --- PEP 359:

python-dev Summary for 2006-04-16 through 2006-04-30

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

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

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

Re: python-dev Summary for 2006-05-01 through 2006-05-15

2006-06-14 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > This summary is tagged as being in ISO-8859-1 encoding: > Content-Type: text/plain; charset=ISO-8859-1; format=flowed > However, it really is in UTF-8 Hmm... I guess Gmail's automatic encoding selection isn't working for the summaries. I've changed my Gmail settings

Re: __lt__ slowing the "in" operator even if not called

2006-06-16 Thread Steven Bethard
Emanuele Aina wrote: > [EMAIL PROTECTED] dettagliò: > >>> Someone can explain me why? >> The list's __contains__ method is very simple > > [...] > >> So if you define "__lt__" in your object then the type gets a richcmp >> function and your == test implicit in the 'in' search always incurs the >

Re: add elements to indexed list locations

2006-06-16 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > # I have a list of names: > names = ['clark', 'super', 'peter', 'spider', 'bruce', 'bat'] > > # and another set of names that I want to insert into > # the names list at some indexed locations: > surnames = { 1: 'kent', 3:'parker', 5:'wayne' } > > # The thing I couldn't

Re: add elements to indexed list locations

2006-06-17 Thread Steven Bethard
levent wrote: > Thanks for the answers. Enumerating in reverse is indeed quite a smart > idea. > > The fact is though, I overly simplified the task in the super-hero > example. In the real case, the dictionary keys are not necessarily the > indices for inserts; that is to say, the inserts do not n

aligning SGML to text

2006-06-18 Thread Steven Bethard
I have some plain text data and some SGML markup for that text that I need to align. (The SGML doesn't maintain the original whitespace, so I have to do some alignment; I can't just calculate the indices directly.) For example, some of my text looks like: TNF binding induces release of AIP1

Re: aligning SGML to text

2006-06-18 Thread Steven Bethard
Gerard Flanagan wrote: > Steven Bethard wrote: >> I have some plain text data and some SGML markup for that text that I >> need to align. (The SGML doesn't maintain the original whitespace, so I >> have to do some alignment; I can't just calculate the indices direc

Re: mapping None values to ''

2006-06-18 Thread Steven Bethard
Scott David Daniels wrote: > Roberto Bonvallet wrote: >> imho <[EMAIL PROTECTED]>: >>> map(lambda x:"" , [i for i in [a,b,c] if i in ("None",None) ]) >> You don't need map when using list comprehensions: >>["" for i in [a, b, c] if i in ("None", None)] >> > More like: > > [(i, "")[i in ("N

Re: aligning SGML to text

2006-06-18 Thread Steven Bethard
Steven Bethard wrote: > I have some plain text data and some SGML markup for that text that I > need to align. (The SGML doesn't maintain the original whitespace, so I > have to do some alignment; I can't just calculate the indices directly.) [snip] > Note that the SGML i

Re: Formatted string to object

2006-06-19 Thread Steven Bethard
janama wrote: > can such a thing be done somehow? > > aaa = self.aaa > bbb = %s.%s % ('parent', 'bbb') > > Can you use strings or %s strings like in the above or > > aaa = 'string' > aaa.%s() % 'upper' Use the getattr() function:: >>> class parent(object): ... class bbb(object):

Re: returning index of minimum in a list of lists

2006-06-21 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > Is there a simple python function to return the list index of the > minimum entry in a list of lists? > ie, for [[3,3,3,3], [3,3,3,1], [3,3,3,3]] to return 2,4. > Or, same question but just for a list of numbers, not a list of lists. In Python 2.5: Python 2.5a2 (trun

Re: returning index of minimum in a list of lists

2006-06-21 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > [EMAIL PROTECTED] wrote: >> Is there a simple python function to return the list index of the >> minimum entry in a list of lists? >> ie, for [[3,3,3,3], [3,3,3,1], [3,3,3,3]] to return 2,4. >> Or, same question but just for a list of numbers, not a list of lists. > >

Re: The code that could not be...

2006-06-22 Thread Steven Bethard
Alex A. Naanou wrote: > The object's __dict__ can only be a dict derivative and at that none of > the Python's mapping API will be used (the dict is accessed directly). [snip] > I wrote a patch some time back, it appears rather stable and is being > production tested. > > you can download it here:

Re: Registry of Methods via Decorators

2006-06-22 Thread Steven Bethard
bayerj wrote: > I want to make a registry of methods of a class during creation. I think you're going to need a metaclass for this, e.g.:: >>> import inspect >>> def registered(func): ... func.registered = True ... return func ... >>> class RegisterFuncs(type): ... def __init__(cls

Re: Clearing pythonwin environment

2006-06-23 Thread Steven Bethard
Network Ninja wrote: > I want to restart the environment occasionally to default (like I > restarted pythonwin). I wrote this script. I know why it doesn't work, > cause it deletes my variable (item) on each iteration. My question is: > is it possible to do this? What other things might I try? > >

Re: optparse multiple arguments

2006-06-30 Thread Steven Bethard
Ritesh Raj Sarraf wrote: > Now if someone uses it as: > ./foo --my-option a b c > > I want somehow to store all the three arguments Currently optparse doesn't support options with an arbitrary number of arguments. I'm currently working on a optparse-inspired replacement which does support this

Re: Concatenating strings

2006-06-30 Thread Steven Bethard
John Henry wrote: > I have a list of strings (some 10,000+) and I need to concatenate them > together into one very long string. The obvious method would be, for > example: > > alist=["ab","cd","ef",.,"zzz"] > blist = "" > for x in alist: >blist += x > > But is there a cleaner and faster

doctest, sys.stderr, SystemExit and unused return values

2006-07-01 Thread Steven Bethard
I have an optparse-like module and though I have a full unittest-style suite of tests for it, I'd also like to be able to run doctest on the documentation to make sure my examples all work. However, I see that doctest (1) doesn't capture anything from sys.stderr, and (2) unlike the normal inte

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

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

Re: split a line, respecting double quotes

2006-07-07 Thread Steven Bethard
Jim wrote: > Is there some easy way to split a line, keeping together double-quoted > strings? > > I'm thinking of > 'a b c "d e"' --> ['a','b','c','d e'] > . I'd also like > 'a b c "d \" e"' --> ['a','b','c','d " e'] > which omits any s.split('"')-based construct that I could come up with.

Re: Attaching functions to objects as methods

2006-07-07 Thread Steven Bethard
tac-tics wrote: > Python is a crazy language when it comes to object versatility. I know > I can do: > class test: > ...def __init__(self): > ... pass x = test() def fun(): > ... print "fun" x.fun = fun x.fun() > fun > > However, experimenting shows that t

Re: Attaching functions to objects as methods

2006-07-07 Thread Steven Bethard
John Machin wrote: > Injecting a "private" method into a particular instance is not much more > complicated: > > >>> def own(self, arg): > ...print "own" > ...self.ozz = arg > ... > >>> p = K() > >>> import types > >>> p.metho = types.MethodType(own, p) > >>> p.metho("plugh") > own >

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

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

Re: language design question

2006-07-09 Thread Steven Bethard
Gregory Guthrie wrote: > For example, >- why is len() not a member function of strings? Instead one says len(w). Why would ``x.len()`` be any more convenient than ``len(x)``? Your preference here seems pretty arbitrary. > - Why doesn't sort() return a value? > > This would allow thing

Re: language design question

2006-07-09 Thread Steven Bethard
guthrie wrote: > Steven Bethard wrote: >> Why would ``x.len()`` be any more convenient than ``len(x)``? Your >> preference here seems pretty arbitrary. > -- Perhaps; > but having all standard operations as a method seems more regular (to > me), and allows a simple chain

<    5   6   7   8   9   10   11   12   13   14   >