Re: I18n issue with optik

2007-04-01 Thread Steven Bethard
Thorsten Kampe wrote: > I guess the culprit is this snippet from optparse.py: > > # used by test suite > def _get_encoding(self, file): > encoding = getattr(file, "encoding", None) > if not encoding: > encoding = sys.getdefaultencoding() > return encoding > > def print_help(se

Re: Sorting a multidimensional array by multiple keys

2007-04-02 Thread Steven Bethard
Thomas Krüger wrote: > Alex Martelli schrieb: >> Thomas Krüger <[EMAIL PROTECTED]> wrote: >>> def sorter(a, b): >>> return cmp(a.id, b.id) >>> >>> obj_lst.sort(sorter) >> A MUCH better way to obtain exactly the same semantics would be: >> >> def getid(a): >> return a.id >> >> obj_list.sort(

Re: getattr/setattr q.

2007-04-02 Thread Steven Bethard
Paulo da Silva wrote: > In a class C, I may do setattr(C,'x',10). > > Is it possible to use getattr/setattr for variables not inside > classes or something equivalent? I mean with the same result as > exec("x=10"). If you're at the module level, you can do:: globals()['x'] = 10 If you're i

Re: getattr/setattr q.

2007-04-03 Thread Steven Bethard
Steve Holden wrote: > You don't need setattr/getattr if you know in advance the name of the > attribute you need to access and you can get a reference to the object > whose attribute it is. So: > > >>> x = "Hello, Paulo" > >>> import sys > >>> sys.modules['__main__'].x > 'Hello, Paulo' a.k.a

Re: troubles building python 2.5 on Windows XP x64 Windows Server 2003 sp1 Platform SDK

2007-04-03 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > I am needing to build python 2.5 on Windows XP x64 Windows Server 2003 > sp1 Platform SDK and am not finding anything documented on the process > to use. Has anyone had any success with this? If so has anyone > documented it? The documentation that resides in pcbuild/read

Re: File Object behavior

2007-04-03 Thread Steven Bethard
Michael Castleton wrote: > When I open a csv or txt file with: > > infile = open(sys.argv[1],'rb').readlines() > or > infile = open(sys.argv[1],'rb').read() > > and then look at the first few lines of the file there is a carriage return > + > line feed at the end of each line - \r\n > This is f

Re: troubles building python 2.5 on Windows XP x64 Windows Server 2003 sp1 Platform SDK

2007-04-03 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > On Apr 3, 2:04 pm, Steven Bethard <[EMAIL PROTECTED]> wrote: >> [EMAIL PROTECTED] wrote: >>> I am needing to build python 2.5 on Windows XP x64 Windows Server 2003 >>> sp1 Platform SDK and am not finding anything documented on the proce

Re: troubles building python 2.5 on Windows XP x64 Windows Server 2003 sp1 Platform SDK

2007-04-03 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > This doc has not been updated since the 64 bit compilers came out > officially. It doesn't make a whole lot of sense of what steps you > should follow to build python. I saw a link on the comp.lang.python > that had the steps, but that link doesn't go anywhere now. I had

Re: how to remove multiple occurrences of a string within a list?

2007-04-03 Thread Steven Bethard
bahoo wrote: > The larger problem is, I have a list of strings that I want to remove > from another list of strings. If you don't care about the resulting order:: >>> items = ['foo', 'bar', 'baz', 'bar', 'foo', 'frobble'] >>> to_remove = ['foo', 'bar'] >>> set(items) - set(to_remov

Re: optparse option prefix

2007-04-04 Thread Steven Bethard
Mathias Waack wrote: > We've integrated python into a legacy application. Everything works fine (of > course because its python;). There's only one small problem: the > application reads the commandline and consumes all arguments prefixed with > a '-' sign. Thus its not possible to call a python mo

Re: how to remove multiple occurrences of a string within a list?

2007-04-04 Thread Steven Bethard
Ayaz Ahmed Khan wrote: > "kyosohma" typed: > >> If you want to get really fancy, you could do a list comprehension >> too: >> >> your_list = ["0024","haha","0024"] >> new_list = [i for i in your_list if i != '0024'] > > Or, just: > > In [1]: l = ["0024","haha","0024"] > In [2]: filter(lambda x:

function for counting items in a sequence

2007-04-04 Thread Steven Bethard
Alex Martelli wrote: > If we had a "turn sequence into bag" function somewhere > (and it might be worth having it for other reasons): > > def bagit(seq): > import collections > d = collections.defaultdict(int) > for x in seq: d[x] += 1 > return d I use this function all the time --

Re: Review/commit patch?

2007-04-05 Thread Steven Bethard
Kevin Walzer wrote: > How long does it take for a patch at the Python SF tracker to be > reviewed and/or committed? I am unfamiliar with how the process works. Raymond's given you the details on your particular patch. It's also worth noting that some folks on python-dev offer the following deal:

Re: RFC: Assignment as expression (pre-PEP)

2007-04-05 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > On Apr 5, 4:22 pm, Duncan Booth <[EMAIL PROTECTED]> wrote: >> Can you come up with a real example where this happens and which cannot be >> easily rewritten to provide better, clearer code without the indentation? >> >> I'll admit to having occasionally had code not entir

Re: RFC: Assignment as expression (pre-PEP)

2007-04-05 Thread Steven Bethard
Steven Bethard wrote: > [EMAIL PROTECTED] wrote: >> On Apr 5, 4:22 pm, Duncan Booth <[EMAIL PROTECTED]> wrote: >>> Can you come up with a real example where this happens and which >>> cannot be >>> easily rewritten to provide better, clearer code withou

Re: Why is __getslice__ still implemented?

2007-04-10 Thread Steven Bethard
Torsten Bronger wrote: > Hallöchen! > > According to , > __getslice__ is deprecated. At the moment, I derive an own class > from unicode and want to implement my own slicing. I found that I > have to override __getslice__ since __getitem__ isn't

Re: Why is __getslice__ still implemented?

2007-04-10 Thread Steven Bethard
Jean-Paul Calderone wrote: > On Tue, 10 Apr 2007 08:35:56 -0600, Steven Bethard > <[EMAIL PROTECTED]> wrote: >> Yes, you do still need to implement __getslice__ if you're subclassing >> a class (like unicode or list) which provides it. The __getslice__ >> m

Re: Why is __getslice__ still implemented?

2007-04-10 Thread Steven Bethard
Torsten Bronger wrote: > Hallöchen! > > Steven Bethard writes: > >> Torsten Bronger wrote: >> >>> [...] >>> >>> [...] It forces people to implement a deprecated function after >>> all. I think the docs should say that you still have t

Re: Code Explaination: Spelling correction code

2007-04-11 Thread Steven Bethard
Drew wrote: > I recently saw this website: http://www.norvig.com/spell-correct.html > > All the code makes sense to me save one line: > > def known_edits2(word): > return set(e2 for e1 in edits1(word) for e2 in edits1(e1) if e2 in > NWORDS) This is the same as: result = set() for

Re: Code Explaination: Spelling correction code

2007-04-12 Thread Steven Bethard
Drew wrote: > On Apr 11, 11:27 pm, Steven Bethard <[EMAIL PROTECTED]> wrote: >> Drew wrote: >>> def known_edits2(word): >>> return set(e2 for e1 in edits1(word) for e2 in edits1(e1) if e2 in >>> NWORDS) >> >> This is the same as: &

Re: Class Dependancy Injection

2007-04-13 Thread Steven Bethard
Robert Rawlins - Think Blue wrote: > For instance, in my application I have a configuration bean which > contains all the applications configuration information. Now in one of > other classes I need access to those configuration settings. What I > would have done in my ColdFusion/JAVA type appli

Re: attribute save restore

2007-04-13 Thread Steven Bethard
Carl K wrote: > Is there a more elegant way of coding this: > > x=o.p # save .p > o.p=0 > o.m() > o.p=x # restore .p > > seems very push/pop to me - like there should be a way that doesn't need > a var (x) or the save/set lines should be done in one command. With the appropriate context mange

Re: vocab question

2007-04-13 Thread Steven Bethard
Bruno Desthuilliers wrote: > Alan G Isaac a écrit : >> Pardon the vocab question; >> I'm not a computer science type. >> According to the Reference Manual, >> a class defintion has the structure:: >> >> classdef ::= "class" classname [inheritance] ":" suite >> >> What is the entire part b

Re: vocab question

2007-04-13 Thread Steven Bethard
James Stroud wrote: > Alan G Isaac wrote: >> According to the Reference Manual, >> a class defintion has the structure:: >> >> classdef ::= "class" classname [inheritance] ":" suite >> >> What is the entire part before the suite called? >> (Just pointing to a reference is fine & helpful,

Re: proposed PEP: iterator splicing

2007-04-15 Thread Steven Bethard
Paul Rubin wrote: > The boilerplate > > def some_gen(): >... >for x in some_other_gen(): >yield x >... > > is so common (including the case where some_other_gen is the same as > some_gen, i.e. it's a recursive call) that I find myself wanting > a more d

Re: working of round()

2007-04-15 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > Does round() always perfectly return the output expected or are there > some artifacts which don't allow perfect functionality > > Using python 2.5: round(12.234, 2) > 12.23 round(12.234, 3) > 12.234 round(12.234, 1) > 12.199 > > but was expec

Re: pyparsing Catch-22

2007-04-15 Thread Steven Bethard
7stud wrote: > For as hard as you push pyparsing on this forum, I would think you > would make it easier to download and install your module. In my > opinion, the wiki should provide detailed installation instructions > for all supported os's, and the sourceforge downloading process is too > comp

Re: rewrite for achieving speedup

2007-04-17 Thread Steven Bethard
Steve Holden wrote: > Johnny Blonde wrote: >> Hello Group! >> >> I really tried hard for two hours to rewrite the following expression >> (python 2.4): >> -- >> teilnehmer = [] >> for r in Reisen.select(AND(Reisen.q.RESVON <= datum, Reisen.q.RESBIS >>> = datum)): >> for

Re: Passing parameters at the command line (New Python User)

2007-09-24 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > Hi there. I just wondered whether anyone could recommend the correct > way I should be passing command line parameters into my program. I am > currently using the following code: > > def main(argv = None): > > > file1= "directory1" > file2 = "directory2" > >

Re: Can a base class know if a method has been overridden?

2007-09-24 Thread Steven Bethard
Ratko wrote: > I was wondering if something like this is possible. Can a base class > somehow know if a certain method has been overridden by the subclass? You can try using the __subclasses__() method on the class:: >>> def is_overridden(method): ... for cls in method.im_class.__su

Re: sorteddict PEP proposal [started off as orderedict]

2007-09-25 Thread Steven Bethard
Mark Summerfield wrote: > PEP: XXX > Title: Sorted Dictionary [snip] > In addition, the keys() method has two optional arguments: > > keys(firstindex : int = None, secondindex : int = None) -> list of keys > > The parameter names aren't nice, but using say "start" and "end" would >

Re: sorteddict PEP proposal [started off as orderedict]

2007-09-25 Thread Steven Bethard
Paul Hankin wrote: > On Sep 25, 12:51 pm, Mark Summerfield <[EMAIL PROTECTED]> > wrote: >> On 25 Sep, 12:19, Paul Hankin <[EMAIL PROTECTED]> wrote: >> >> >> >>> Recall sorted... >>> sorted(iterable, cmp=None, key=None, reverse=False) --> new sorted >>> list >>> So why not construct sorteddicts

Re: getopt with negative numbers?

2007-09-27 Thread Steven Bethard
Casey wrote: > Is there an easy way to use getopt and still allow negative numbers as > args? [snip] > Alternatively, does optparse handle this? Peter Otten wrote: > optparse can handle options with a negative int value; "--" can be used to > signal that no more options will follow: > import

Re: Numeric command-line options vs. negative-number arguments

2007-09-27 Thread Steven Bethard
Ben Finney wrote: > Steven Bethard <[EMAIL PROTECTED]> writes: > >> In most cases, argparse (http://argparse.python-hosting.com/) >> supports negative numbers right out of the box, with no need to use >> '--': >> >> >>>

Re: Numeric command-line options vs. negative-number arguments

2007-09-28 Thread Steven Bethard
Ben Finney wrote: > Steven Bethard <[EMAIL PROTECTED]> writes: >> Argparse knows what your option flags look like, so if you specify >> one, it knows it's an option. Argparse will only interpret it as a >> negative number if you specify a negative number that

Re: getopt with negative numbers?

2007-09-28 Thread Steven Bethard
Casey wrote: > Ben Finney wrote: >> I believe they shouldn't because the established interface is that a >> hyphen always introduced an option unless (for those programs that >> support it) a '--' option is used, as discussed. > > Not "THE" established interface; "AN" established interface. There

Re: Numeric command-line options vs. negative-number arguments

2007-09-28 Thread Steven Bethard
Carl Banks wrote: > On Sep 28, 9:51 am, Steven Bethard <[EMAIL PROTECTED]> wrote: >> It was decided that practicality beats purity here. Arguments with >> leading hyphens which look numeric but aren't in the parser are >> interpreted as negative numbers. Argu

Re: Can I overload the compare (cmp()) function for a Lists ([]) index function?

2007-09-28 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > On Sep 28, 8:30 pm, xkenneth <[EMAIL PROTECTED]> wrote: >> Looking to do something similair. I'm working with alot of timestamps >> and if they're within a couple seconds I need them to be indexed and >> removed from a list. >> Is there any possible way to index with a cu

Re: Optparse and help formatting?

2007-09-30 Thread Steven Bethard
Tim Chase wrote: > I've been learning the ropes of the optparse module and have been > having some trouble getting the help to format the way I want. > > I want to specify parts of an option's help as multiline. > However, the optparse formatter seems to eat newlines despite my > inability to find

Re: global variables

2007-10-02 Thread Steven Bethard
TheFlyingDutchman wrote: > Does anyone know how the variables label and scale are recognized > without a global statement or parameter, in the function resize() in > this code: [snip] > def resize(ev=None): > label.config(font='Helvetica -%d bold' % \ > scale.get()) You're just cal

Re: unit testing

2007-10-04 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > On Oct 4, 1:02 pm, brad <[EMAIL PROTECTED]> wrote: >> Does anyone else feel that unittesting is too much work? Not in general, >> just the official unittest module for small to medium sized projects? [snip] > I actually do a lot of unit testing. I find it both annoying a

Re: unit testing

2007-10-05 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > On Oct 5, 5:38 am, Craig Howard <[EMAIL PROTECTED]> wrote: >> Brad: >> >> If the program is more than 100 lines or is a critical system, I >> write a unit test. I hate asking myself, "Did I break something?" >> every time I decide to refactor a small section of code. For

Re: weakrefs and bound methods

2007-10-07 Thread Steven Bethard
Mathias Panzenboeck wrote: > Marc 'BlackJack' Rintsch wrote: >> ``del b`` just deletes the name `b`. It does not delete the object. >> There's still the name `_` bound to it in the interactive interpreter. >> `_` stays bound to the last non-`None` result in the interpreter. > > Actually I have

Re: Problem of Readability of Python

2007-10-07 Thread Steven Bethard
Licheng Fang wrote: > Python is supposed to be readable, but after programming in Python for > a while I find my Python programs can be more obfuscated than their C/C > ++ counterparts sometimes. Part of the reason is that with > heterogeneous lists/tuples at hand, I tend to stuff many things into

Re: Problem of Readability of Python

2007-10-07 Thread Steven Bethard
George Sakkis wrote: > On Oct 7, 2:14 pm, Steven Bethard <[EMAIL PROTECTED]> wrote: >> Licheng Fang wrote: >>> Python is supposed to be readable, but after programming in Python for >>> a while I find my Python programs can be more obfuscated than their C/C >&

Re: Problem of Readability of Python

2007-10-07 Thread Steven Bethard
Alex Martelli wrote: > Steven D'Aprano <[EMAIL PROTECTED]> wrote: >> class Record(object): >> __slots__ = ["x", "y", "z"] >> >> has a couple of major advantages over: >> >> class Record(object): >> pass >> >> aside from the micro-optimization that classes using __slots__ are faster >> and s

Re: Don't use __slots__ (was Re: Problem of Readability of Python)

2007-10-08 Thread Steven Bethard
Aahz wrote: > In article <[EMAIL PROTECTED]>, > Steven Bethard <[EMAIL PROTECTED]> wrote: >> You can use __slots__ [...] > > Aaaugh! Don't use __slots__! > > Seriously, __slots__ are for wizards writing applications with huuuge > numbers of object i

Re: ANN: generator_tools-0.1 released

2007-10-09 Thread Steven Bethard
Kay Schluehr wrote: > Originally I came up with the idea of a pure Python implementation for > copyable generators as an ActiveState Python Cookbook recipe. Too bad, > it was badly broken as Klaus Müller from the SimPy project pointed > out. Two weeks and lots of tests later I got finally a running

Re: Problem of Readability of Python

2007-10-10 Thread Steven Bethard
Kevin wrote: > Am I missing something, or am I the only one who explicitly declares > structs in python? > > For example: > FileObject = { > "filename" : None, > "path" : None, > } > > fobj = FileObject.copy() > fobj["filename"] = "passwd" > fobj["path"] = "/etc/" Yes, I think this i

Re: Problem with argument parsing

2007-10-10 Thread Steven Bethard
Diez B. Roggisch wrote: > lgwe wrote: > >> On 9 Okt, 17:18, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: >>> lgwe wrote: I have a python-script: myscript, used to start a program on another computer and I use OptionParser in optpars. I use it like this: myscript -H host arg1 -x -y

Re: Problem of Readability of Python

2007-10-10 Thread Steven Bethard
Bjoern Schliessmann wrote: > Kevin wrote: >> Am I missing something, or am I the only one who explicitly >> declares structs in python? > > Yes -- you missed my posting :) Actually, your posting just used dicts normally. Kevin is creating a prototype dict with a certain set of keys, and then co

Re: Parsing a commandline from within Python

2007-10-11 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > Is there any buildin function which mimics the behavior of the > standard commandline parser (generating a list of strings > "foo bar" and "some text" from the commandline > <"foo bar" "some text">)? Try the shlex module:: >>> import shlex >>> shlex.split('"fo

Re: vote for Python - PLEASE

2007-10-19 Thread Steven Bethard
Monty Taylor wrote: > MySQL has put up a poll on http://dev.mysql.com asking what your primary > programming language is. Even if you don't use MySQL - please go stick > in a vote for Python. I agree with others that voting here if you don't use MySQL is *not* a good idea. That said, I still ap

Re: Python-URL! - weekly Python news and links (Oct 22)

2007-10-22 Thread Steven Bethard
Gabriel Genellina wrote: > "I actually do a lot of unit testing. I find it both annoying and highly > necessary and useful." - Steven Bethard > http://groups.google.com/group/comp.lang.python/msg/4df60bdff72540cb That quote is actually due to Dan McLeran. A very good q

Re: Automatic Generation of Python Class Files

2007-10-22 Thread Steven Bethard
Sunburned Surveyor wrote: > Contents of input text file: > > [Name] > Fire Breathing Dragon > > [Properties] > Strength > Scariness > Endurance > > [Methods] > eatMaiden argMaiden > fightKnight argKnight > > Generated Python Class File: > > def class FireBreathingDragon: > >def getStrengt

Re: Automatic Generation of Python Class Files

2007-10-22 Thread Steven Bethard
Sunburned Surveyor wrote: > I also intended to add statements creating properties from the getter > and setter methods. I understand that getters and setters aren't > really necessary if you aren't making a property. I just forgot to add > the property statements to my example. You still don't wan

Re: Iteration for Factorials

2007-10-22 Thread Steven Bethard
Michael J. Fromberger wrote: > # Not legal Python code. > def fact3(n, acc = 1): > TOP: > if n > 0 > n = n - 1 > acc = acc * n > goto TOP > else: > return acc Yes, to write this in legal Python code, you have to write:: from goto import goto

Re: Automatic Generation of Python Class Files

2007-10-22 Thread Steven Bethard
Bruno Desthuilliers wrote: > Steven Bethard a écrit : > (snip) >> In Python, you can use property() to make method calls look like >> attribute access. This could be necessary if you have an existing API >> that used public attributes, but changes to your code require th

Re: Automatic Generation of Python Class Files

2007-10-23 Thread Steven Bethard
Marc 'BlackJack' Rintsch wrote: > On Mon, 22 Oct 2007 17:31:51 -0600, Steven Bethard wrote: > >> Bruno Desthuilliers wrote: >>> Computed attributes are IMHO not only a life-saver when it comes to >>> refactoring. There are cases where you *really* have -

Re: Automatic Generation of Python Class Files

2007-10-23 Thread Steven Bethard
Bruno Desthuilliers wrote: > Steven Bethard a écrit : >> Bruno Desthuilliers wrote: >>> Steven Bethard a écrit : >>> (snip) >>>> In Python, you can use property() to make method calls look like >>>> attribute access. This could be necessary

Re: Automatic Generation of Python Class Files

2007-10-23 Thread Steven Bethard
Bruno Desthuilliers wrote: >> I guess as long as your documentation is clear about which attributes >> require computation and which don't... > > Why should it ? FWIW, I mentionned that I would obviously not use > properties for values requiring heavy, non cachable computation. This > set aside

Re: Automatic Generation of Python Class Files

2007-10-23 Thread Steven Bethard
Bruno Desthuilliers wrote: > Steven Bethard a écrit : >> Bruno Desthuilliers wrote: >>>> I guess as long as your documentation is clear about which >>>> attributes require computation and which don't... >>> >>> Why should it ? [snip] > I

Re: Automatic Generation of Python Class Files

2007-10-23 Thread Steven Bethard
Bruno Desthuilliers wrote: > Now how does your desire for documentation imply that "if you're > creating a class for the first time, it should *never* use property()" ? Of course, there's *never* any such thing as "never" in Python. ;-) STeVe P.S. If you really don't understand what I was gett

Re: optparse help output

2007-10-24 Thread Steven Bethard
Dan wrote: > On Oct 24, 12:06 pm, Tim Chase <[EMAIL PROTECTED]> wrote: >>> I've been using optparse for a while, and I have an option with a >>> number of sub-actions I want to describe in the help section: >>> parser.add_option("-a", "--action", >>> help=\ >> [snipped for

Re: Bypassing __getattribute__ for attribute access

2007-10-25 Thread Steven Bethard
Adam Donahue wrote: class X( object ): > ... def c( self ): pass > ... X.c > x = X() x.c > > > > If my interpretation is correct, the X.c's __getattribute__ call knows > the attribute reference is via a class, and thus returns an unbound > method (though it does convert th

Re: Iteration for Factorials

2007-10-26 Thread Steven Bethard
Nicko wrote: > If you don't like the rounding errors you could try: > > def fact(n): > d = {"p":1L} > def f(i): d["p"] *= i > map(f, range(1,n+1)) > return d["p"] > > It is left as an exercise to the reader as to why this code will not > work on Py3K Serves yo

Re: PEP 299 and unit testing

2007-10-28 Thread Steven Bethard
Ben Finney wrote: > What it doesn't allow is for the testing of the 'if __name__ == > "__main__":' clause itself. No matter how simple we make that, it's > still functional code that can contain errors, be they obvious or > subtle; yet it's code that *can't* be touched by the unit test (by > design

Re: PEP 299 and unit testing

2007-10-28 Thread Steven Bethard
Ben Finney wrote: > Steven Bethard <[EMAIL PROTECTED]> writes: > >> Ben Finney wrote: >>> What it doesn't allow is for the testing of the 'if __name__ == >>> "__main__":' clause itself. No matter how simple we make that, >>> i

Re: setting variables in outer functions

2007-10-29 Thread Steven Bethard
Hrvoje Niksic wrote: > Tommy Nordgren <[EMAIL PROTECTED]> writes: > >> Given the following: >> def outer(arg) >> avar = '' >> def inner1(arg2) >> # How can I set 'avar' here ? > > I don't think you can, until Python 3: > http://www.python.org/dev/peps/pep-3104/ But it definit

Re: Automatic Generation of Python Class Files

2007-10-29 Thread Steven Bethard
Fuzzyman wrote: > On Oct 22, 6:43 pm, Steven Bethard <[EMAIL PROTECTED]> wrote: >> # Inherit from object. There's no reason to create old-style classes. > > We recently had to change an object pipeline from new style classes to > old style. A lot of these objects were

Re: setting variables in outer functions

2007-10-30 Thread Steven Bethard
Neil Cerutti wrote: > On 2007-10-29, Steven Bethard <[EMAIL PROTECTED]> wrote: >> Hrvoje Niksic wrote: >>> Tommy Nordgren <[EMAIL PROTECTED]> writes: >>> >>>> Given the following: >>>> def outer(arg) >>>> avar = '

Re: Python Interview Questions

2007-10-31 Thread Steven Bethard
konryd wrote: >> - string building...do they use "+=" or do they build a list >>and use .join() to recombine them efficiently > > > I'm not dead sure about that, but I heard recently that python's been > optimized for that behaviour. That means: using += is almost as fast > as joining list.

Re: An iterator with look-ahead

2007-01-10 Thread Steven Bethard
Neil Cerutti wrote: > For use in a hand-coded parser I wrote the following simple > iterator with look-ahead. There's a recipe for this: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/304373 Note that the recipe efficiently supports an arbitrary look-ahead, not just a single item.

Re: A note on heapq module

2007-01-16 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > some time ago I have written a bug > into small program that uses the functions of the heapq module, because > I have added an item to the head of the heap using a normal list > method, breaking the heap invariant. I know I've had similar bugs in my code before. > from

[ANN] argparse 0.5 - Command-line parsing library

2007-01-16 Thread Steven Bethard
Announcing argparse 0.5 --- 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 r

Re: A note on heapq module

2007-01-17 Thread Steven Bethard
Antoon Pardon wrote: > For me, your class has the same drawback as the heappush, heappop > procedurers: no way to specify a comparision function. Agreed. I'd love to see something like ``Heap(key=my_key_func)``. STeVe -- http://mail.python.org/mailman/listinfo/python-list

aligning ElementTrees to text

2007-01-17 Thread Steven Bethard
I'm trying to align an XML file with the original text file from which it was created. Unfortunately, the XML version of the file has added and removed some of the whitespace. For example:: >>> plain_text = ''' ... Pacific First Financial Corp. said shareholders approved its ... a

Re: A note on heapq module

2007-01-18 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > Steven Bethard: >> Antoon Pardon: >>> For me, your class has the same drawback as the heappush, heappop >>> procedurers: no way to specify a comparision function. >> Agreed. I'd love to see something like ``Heap(key=my_key_func

Re: A note on heapq module

2007-01-18 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > Steven Bethard wrote: >> The current code fails when using unbound methods however:: > > I don't like your solution, this class was already slow enough. Don't > use unbound methods with this class :-) > Maybe there's a (better) solu

pyparsing Combine without merging sub-expressions

2007-01-20 Thread Steven Bethard
Within a larger pyparsing grammar, I have something that looks like:: wsj/00/wsj_0003.mrg When parsing this, I'd like to keep around both the full string, and the AAA_ substring of it, so I'd like something like:: >>> foo.parseString('wsj/00/wsj_0003.mrg') (['wsj/00/wsj_0003.

Re: pyparsing Combine without merging sub-expressions

2007-01-21 Thread Steven Bethard
Dennis Lee Bieber wrote: > On Sat, 20 Jan 2007 13:49:52 -0700, Steven Bethard > <[EMAIL PROTECTED]> declaimed the following in comp.lang.python: > >> Within a larger pyparsing grammar, I have something that looks like:: >> >> wsj/00/wsj_0003.mrg >>

Re: pyparsing Combine without merging sub-expressions

2007-01-21 Thread Steven Bethard
Paul McGuire wrote: > Steven Bethard wrote: >> Within a larger pyparsing grammar, I have something that looks like:: >> >> wsj/00/wsj_0003.mrg >> >> When parsing this, I'd like to keep around both the full string, and the >> AAA_

distutils, sdist and tests

2007-01-27 Thread Steven Bethard
How do I get distutils to include my testing module in just the "sdist" distribution? My current call to setup() looks like:: distutils.core.setup( ... py_modules=['argparse'], ) If change this to:: distutils.core.setup( ... py_modules=['argpa

Re: distutils, sdist and tests

2007-01-27 Thread Steven Bethard
Robert Kern wrote: > Steven Bethard wrote: >> How do I get distutils to include my testing module in just the "sdist" >> distribution? > > Use a MANIFEST. > > http://docs.python.org/dist/source-dist.html > >> I want test_argparse.py to be availab

Re: distutils, sdist and tests

2007-01-27 Thread Steven Bethard
Robert Kern wrote: > Steven Bethard wrote: >> Robert Kern wrote: >>> Steven Bethard wrote: >>>> How do I get distutils to include my testing module in just the "sdist" >>>> distribution? >>> Use a MANIFEST. >>> >>> h

Re: distutils, sdist and tests

2007-01-27 Thread Steven Bethard
Robert Kern wrote: > Steven Bethard wrote: >> Robert Kern wrote: > >>> Are you sure that you don't have changes left over in your setup.py when you >>> tested that? >> Yep. (Though I still cleared everything out and tried it again.) >> Here&#x

Re: distutils, sdist and tests

2007-01-27 Thread Steven Bethard
Robert Kern wrote: > Steven Bethard wrote: >> How do I get distutils to include my testing module in just the "sdist" >> distribution? > > Use a MANIFEST. Thanks again to Robert Kern for all the help. For the record, in the end all I did was add a MANIFE

Re: Fixed length lists from .split()?

2007-01-30 Thread Steven Bethard
On Jan 26, 11:07 am, Bob Greschke <[EMAIL PROTECTED]> wrote: > I'm reading a file that has lines like > > bcsn; 100; 1223 > bcsn; 101; 1456 > bcsn; 103 > bcsn; 110; 4567 > > The problem is the line with only the one semi-colon. > Is there a fancy way to get Parts=Lin

Re: Conditional expressions - PEP 308

2007-01-31 Thread Steven Bethard
Colin J. Williams wrote: > It would be helpful if the rules of the game were spelled out more clearly. > > The conditional expression is defined as X if C else Y. > We don't know the precedence of the "if" operator. From the little test > below, it seem to have a lower precedence than "or". > >

Re: SyntaxError: 'return' outside function

2007-01-31 Thread Steven Bethard
Melih Onvural wrote: > Has anyone seen this error before and been able to solve it? I can't > seem to find anything that leads to a solution. I found this post > http://zope.org/Collectors/Zope/1809, but can't really understand it. > I've attached my code below to see if anything looks funny. It ha

Re: How to sort using hash's key?

2007-01-31 Thread Steven Bethard
JoJo wrote: > I want to sort a dict via its key,but I have no idea on how to do it. >>> d = dict(a=2, b=1) >>> for key in sorted(d): ... print key, d[key] ... a 2 b 1 STeVe -- http://mail.python.org/mailman/listinfo/python-list

Re: How to sort using hash's key?

2007-01-31 Thread Steven Bethard
Ben Finney wrote: > Steven Bethard <[EMAIL PROTECTED]> writes: > >> JoJo wrote: >>> I want to sort a dict via its key,but I have no idea on how to do >>> it. >>>>> d = dict(a=2, b=1) >>>>> for key in sorted(d): >> ... pr

Re: Sorting a list

2007-02-01 Thread Steven Bethard
Bruno Desthuilliers wrote: > If you want to prevent this from happening and don't mind creating a > copy of the list, you can use the sorted() function with the key and > reverse arguments and operator.itemgetter: > > >>> lines = [('1995', 'aaa'), ('1997', 'bbb'), ('1995', 'bbb'), > ('1997', '

Re: Checking default arguments

2007-02-02 Thread Steven Bethard
Igor V. Rafienko wrote: > I was wondering whether it was possible to find out which parameter > value is being used: the default argument or the user-supplied one. > That is: > > def foo(x, y="bar"): > # how to figure out whether the value of y is > # the default argument, or user-suppl

[OT] main

2007-02-03 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > def main(argv): > try: > optlist, args = getopt.getopt(argv[1:], 'hvo:D:', ['help', > 'verbose']) > except getopt.GetoptError, msg: > sys.stderr.write("preprocess: error: %s" % msg) > sys.stderr.write("See 'preprocess --help'.\n") >

Re: when will python 2.5 take in mainstream?

2007-02-04 Thread Steven Bethard
Eric CHAO wrote: > A lot of application based on python claim that python 2.3 or 2.4 is > needed not 2.5, ie. mysqldb. I've been using python for months. I > don't care about 2.4 or 2.5. But I like the default icons of python in > 2.5. So I just use that, but some scripts can't work on that. > > W

Python 3.0 (Was: when will python 2.5 take in mainstream?)

2007-02-05 Thread Steven Bethard
Laurent Pointal wrote: > For Python 3.0, AFAIK its a big rewrite and developers know that it will > be uncompatible in large parts with existing code. Wrong on both counts. ;-) Python 3.0 is not a rewrite. It's based on the same code base as the 2.X line, but with a lot of the old deprecated thi

huge amounts of pure Python code broken by Python 2.5?

2007-02-06 Thread Steven Bethard
Jean-Paul Calderone <[EMAIL PROTECTED]> wrote: > Huge amounts of my pure Python code was broken by Python 2.5. Interesting. Could you give a few illustrations of this? (I didn't run into the same problem at all, so I'm curious.) Steve -- http://mail.python.org/mailman/listinfo/python-list

Re: Array delete

2007-02-07 Thread Steven Bethard
Jerry Hill wrote: > On 1/28/07, Scripter47 <[EMAIL PROTECTED]> wrote: >> Can someone plz make a function for that takes a array, and then search >> in it for duplicates, if it finds 2 or more items thats the same string >> then delete all except 1. > > >>> myList = [1, 1, 2, 4, 8, 8, 8, 8, 8, 8,

Re: Retry:Question about optparse/OptionParser callback.

2007-02-10 Thread Steven Bethard
Steven W. Orr wrote: > I'm writing a program that needs to process options. Due to the nature > of the program with its large number of commandline options, I would > like to write a callback to be set inside add_option. > > Something like this: > > parser.add_option("-b", action="callback", ca

<    9   10   11   12   13   14   15   16   >