[ANN] argparse 1.1 - Command-line parsing library

2010-03-01 Thread Steven Bethard
=== Announcing argparse 1.1 === The argparse module provides an easy, declarative interface for creating command line tools, which knows how to: * parse the arguments and flags from sys.argv * convert arg strings into objects for your program * format and

[ANN] argparse 1.0.1 - Command-line parsing library

2009-09-14 Thread Steven Bethard
= Announcing argparse 1.0.1 = The argparse module provides an easy, declarative interface for creating command line tools, which knows how to: * parse the arguments and flags from sys.argv * convert arg strings into objects for your program * forma

Re: Double underscore names

2008-02-12 Thread Steven Bethard
Steven D'Aprano wrote: > Double-underscore names and methods are special to Python. Developers are > prohibited from creating their own (although the language doesn't enforce > that prohibition). From PEP 0008, written by Guido himself: > > __double_leading_and_trailing_underscore__: "magi

Re: functools possibilities

2008-02-02 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > 1. functools.partialpre: partialpre( f, x, y )( z )-> f( z, x, y ) > 2. functools.pare: pare( f, 1 )( x, y )-> f( y ) > 3. functools.parepre: parepre( f, 1 )( x, y )-> f( x ) > 4. functools.calling_default: calling_default( f, a, DefaultA, b )-> > f( a, , b ) There are l

Re: dict comprehension

2008-02-02 Thread Steven Bethard
Wildemar Wildenburger wrote: > Arnaud Delobelle wrote: >>> I believe both set and dict comprehensions will be in 3.0. >> >> Python 3.0a1+ (py3k:59330, Dec 4 2007, 18:44:39) >> [GCC 4.0.1 (Apple Inc. build 5465)] on darwin >> Type "help", "copyright", "credits" or "license" for more information. >>

Re: breaking out of outer loops

2008-01-29 Thread Steven Bethard
Jeremy Sanders wrote: > [EMAIL PROTECTED] wrote: > >> Any elegant way of breaking out of the outer for loop than below, I >> seem to have come across something, but it escapes me >> >> for i in outerLoop: >>for j in innerLoop: >>if condition: >> break >>else: >>co

Re: py3k feature proposal: field auto-assignment in constructors

2008-01-28 Thread Steven Bethard
Arnaud Delobelle wrote: > Sligthly improved (not for performance! but signature-preserving and > looks for default values) > > from functools import wraps > from inspect import getargspec > from itertools import izip, chain > > def autoassign(*names): > def decorator(f): > fargnames,

Re: Using a dict as if it were a module namespace

2008-01-27 Thread Steven Bethard
Steven D'Aprano wrote: > I have a problem which I think could be solved by using a dict as a > namespace, in a similar way that exec and eval do. > > When using the timeit module, it is very inconvenient to have to define > functions as strings. A good alternative is to create the function as >

Re: is possible to get order of keyword parameters ?

2008-01-25 Thread Steven Bethard
Steven Bethard wrote: > rndblnch wrote: >> my goal is to implement a kind of named tuple. >> idealy, it should behave like this: >> p = Point(x=12, y=13) >> print p.x, p.y >> but what requires to keep track of the order is the unpacking: >> x, y = p >>

Re: is possible to get order of keyword parameters ?

2008-01-25 Thread Steven Bethard
rndblnch wrote: > my goal is to implement a kind of named tuple. > idealy, it should behave like this: > p = Point(x=12, y=13) > print p.x, p.y > but what requires to keep track of the order is the unpacking: > x, y = p > i can't figure out how to produce an iterable that returns the values > in th

Re: find minimum associated values

2008-01-25 Thread Steven Bethard
Alan Isaac wrote: > I have a small set of objects associated with a larger > set of values, and I want to map each object to its > minimum associated value. The solutions below work, > but I would like to see prettier solutions... > [snip] > > # arbitrary setup > keys = [Pass() for i in range(10)]

Re: Why not 'foo = not f' instead of 'foo = (not f or 1) and 0'?

2008-01-23 Thread Steven Bethard
Kristian Domke wrote: > I am trying to learn python at the moment studying an example program > (cftp.py from the twisted framework, if you want to know) > > There I found a line > > foo = (not f and 1) or 0 Equivalent to ``foo = int(not f)`` > In this case f may be None or a string. > > If I

Re: subprocess and & (ampersand)

2008-01-23 Thread Steven Bethard
Ross Ridge wrote: > Tim Golden <[EMAIL PROTECTED]> wrote: >> but this doesn't: >> >> >> "c:\Program Files\Mozilla Firefox\firefox.exe" "%*" >> >> >> >> import subprocess >> >> cmd = [ >> r"c:\temp\firefox.bat", >> "http://local.goodtoread.org/search?word=tim&cached=0"; >> ] >> subprocess.Popen

Re: subprocess and & (ampersand)

2008-01-22 Thread Steven Bethard
Steven D'Aprano wrote: > On Tue, 22 Jan 2008 22:53:20 -0700, Steven Bethard wrote: > >> I'm having trouble using the subprocess module on Windows when my >> command line includes special characters like "&" (ampersand):: >> >> >>>

subprocess and & (ampersand)

2008-01-22 Thread Steven Bethard
I'm having trouble using the subprocess module on Windows when my command line includes special characters like "&" (ampersand):: >>> command = 'lynx.bat', '-dump', 'http://www.example.com/?x=1&y=2' >>> kwargs = dict(stdin=subprocess.PIPE, ... stdout=subprocess.PIPE, ...

Re: isgenerator(...) - anywhere to be found?

2008-01-22 Thread Steven Bethard
Diez B. Roggisch wrote: > Jean-Paul Calderone wrote: > >> On Tue, 22 Jan 2008 15:15:43 +0100, "Diez B. Roggisch" >> <[EMAIL PROTECTED]> wrote: >>> Jean-Paul Calderone wrote: >>> On Tue, 22 Jan 2008 14:20:35 +0100, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > For a simple greenlet/

Re: SyntaxError: 'import *' not allowed with 'from .'

2008-01-15 Thread Steven Bethard
George Sakkis wrote: > Unless I missed it, PEP 328 doesn't mention anything about this. > What's the reason for not allowing "from .relative.module import *' ? Generally, there's a move away from all "import *" versions these days. For example, Python 3.0 removes the ability to use "import *" wit

Re: Modules and descriptors

2008-01-08 Thread Steven Bethard
Chris Leary wrote: > As I understand it, the appeal of properties (and descriptors in > general) in new-style classes is that they provide a way to > "intercept" direct attribute accesses. This lets us write more clear > and concise code that accesses members directly without fear of future > API c

Re: ElementTree should parse string and file in the same way

2008-01-01 Thread Steven Bethard
Steven D'Aprano wrote: > On Tue, 01 Jan 2008 13:36:57 +0100, Diez B. Roggisch wrote: > >> And codemonkeys know that in python >> >> doc = et.parse(StringIO(string)) >> >> is just one import away > > Yes, but to play devil's advocate for a moment, > > doc = et.parse(string_or_file) > > would be

Re: Modify arguments between __new__ and __init__

2007-12-22 Thread Steven Bethard
Steven D'Aprano wrote: > When you call a new-style class, the __new__ method is called with the > user-supplied arguments, followed by the __init__ method with the same > arguments. > > I would like to modify the arguments after the __new__ method is called > but before the __init__ method, som

Re: Newbie observations

2007-12-18 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > First, it is absolutely horrible being a newbie. I'd forgot how bad it > was. In addition to making a fool of yourself in public, you have to > look up everything. I wanted to find a substring in a string. OK, > Python's a serious computer language, so you know it's got a

Re: Should proxy objects lie about their class name?

2007-11-27 Thread Steven Bethard
Fuzzyman wrote: > On Nov 26, 11:56 pm, Carl Banks <[EMAIL PROTECTED]> wrote: >> On Nov 20, 3:50 pm, [EMAIL PROTECTED] (John J. Lee) wrote: >>> Not much to add to the subject line. I mean something like this: >>> ProxyClass.__name__ = ProxiedClass.__name__ >>> I've been told that this is common pra

Re: Python web frameworks

2007-11-21 Thread Steven Bethard
Jeff wrote: > On Nov 21, 6:25 am, Bruno Desthuilliers [EMAIL PROTECTED]> wrote: >> joe jacob a écrit : >> (snip) >> >>> Thanks everyone for the response. From the posts I understand that >>> Django and pylons are the best. By searching the net earlier I got the >>> same information that Django is

Re: Efficient (HUGE) prime modulus

2007-11-19 Thread Steven Bethard
blaine wrote: > Hey guys, > For my Network Security class we are designing a project that will, > among other things, implement a Diffie Hellman secret key exchange. > The rest of the class is doing Java, while myself and a classmate are > using Python (as proof of concept). I am having problems

Re: Finding lowest value in dictionary of objects, how?

2007-11-19 Thread Steven Bethard
Boris Borcic wrote: > davenet wrote: >> Hi, >> >> I'm new to Python and working on a school assignment. >> >> I have setup a dictionary where the keys point to an object. Each >> object has two member variables. I need to find the smallest value >> contained in this group of objects. >> >> The obje

Re: Equivalent of TCL's "subst" ?

2007-11-13 Thread Steven Bethard
gamename wrote: > In TCL, you can do things like: > set foobar "HI!" > set x foo > set y bar > subst $$x$y > HI! > > Is there a way to do this type of evaluation in python? If this is at the outer-most scope, you can use globals():: >>> foobar = 'HI!' >>> x = 'foo' >>> y = 'bar'

Re: optional arguments with compact reporting in optparse

2007-11-12 Thread Steven Bethard
braver wrote: > Steve -- thanks for your pointer to argparse, awesome progress -- > optional arguments. > > However, I still wonder how I do reporting. The idea is that there > should be a list with tuples of the form: > > (short, long, value, help) > > -- for all options, regardless of whether

Re: operator overloading on built-ins

2007-11-08 Thread Steven Bethard
[EMAIL PROTECTED] wrote: (1).__cmp__(10) > -1 Integer object "(1)" followed by method call ".__cmp__(10)" 1.__cmp__(10) > File "", line 1 > 1.__cmp__(10) > ^ > SyntaxError: invalid syntax Floating point number "1." followed by "__cmp__(10)". STeVe -- http://mail.pyt

Re: How to output newline or carriage return with optparse

2007-11-08 Thread Steven Bethard
Tim Chase wrote: >>> ASIDE: I've started refactoring this bit out in my local >>> source...how would I go about contributing it back to the >>> Python code-base? I didn't get any feedback from posting to >>> the Optik site. >> >> You can post a patch to bugs.python.org, but it will probably >> ju

Re: How to output newline or carriage return with optparse

2007-11-08 Thread Steven Bethard
Tim Chase wrote: > ASIDE: I've started refactoring this bit out in my local source...how > would I go about contributing it back to the Python code-base? I didn't > get any feedback from posting to the Optik site. You can post a patch to bugs.python.org, but it will probably just get forwarde

Re: optional arguments with compact reporting in optparse

2007-11-08 Thread Steven Bethard
braver wrote: > Posted to the Optik list, but it seems defunct. Optik is now Python's > optparse. > > I wonder how do you implement optional arguments to Optik. You may want to check out argparse: http://argparse.python-hosting.com/ It supports optional arguments like this:: parser

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: 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: 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-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: 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: 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: 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: 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: 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: 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: 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: >> 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: >>> 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
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-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: 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
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: 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: 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: 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: 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: 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: 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
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: 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: 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: 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: 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
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: 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: 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: 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: 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: 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: 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: 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: 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
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: 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: 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: 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: 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: 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: 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: pwdmodule.c

2007-09-12 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > I am trying to compile Python with cmake, but perhaps there are a few > dependencies that have not been corrected for Windows compilation. I don't know the specific answers to your questions, but I wanted to point out, in case you didn't already know, that Alexander Neu

Re: Is a Borg rebellion possible? (a metaclass question)

2007-09-07 Thread Steven Bethard
Carsten Haese wrote: > Indeed, if you have an __init__ method that shouldn't see the "group" > argument, you need a metaclass after all so you can yank the "group" > argument between __new__ and __init__. The following code seems to work, > but it's making my brain hurt: > > class SplinterBorgMeta

Re: reload(sys)

2007-09-06 Thread Steven Bethard
Sönmez Kartal wrote: > I was using the XMLBuilder(xmlbuilder.py). I'm writing XML files as > "f.write(str(xml))". At execution of that line, it gives error with > description, configure your default encoding... > [and later] > > http://rafb.net/p/RfaF8215.html > > products in the code is a list of

Re: reload(sys)

2007-09-02 Thread Steven Bethard
Sönmez Kartal wrote: > I was using the XMLBuilder(xmlbuilder.py). I'm writing XML files as > "f.write(str(xml))". At execution of that line, it gives error with > description, configure your default encoding... > [and later] > > I get this when it happens: "Decoding Error: You must configure > defa

Re: reload(sys)

2007-08-31 Thread Steven Bethard
Sönmez Kartal wrote: > On 31 A ustos, 04:24, Steven Bethard <[EMAIL PROTECTED]> wrote: >> Sönmez Kartal wrote: >>> I've had an encoding issue and solved it by >>> "sys.setdefaultencoding('utf-8')"... >>> My first try wasn't

Re: reload(sys)

2007-08-30 Thread Steven Bethard
Sönmez Kartal wrote: > I've had an encoding issue and solved it by > "sys.setdefaultencoding('utf-8')"... > > My first try wasn't successful since setdefaultencoding is not named > when I imported sys module. After, I import sys module, I needed to > write "reload(sys)" also. > > I wonder why we

Re: status of Programming by Contract (PEP 316)?

2007-08-28 Thread Steven Bethard
Russ wrote: > I just stumbled onto PEP 316: Programming by Contract for Python > (http://www.python.org/dev/peps/pep-0316/). This would be a great > addition to Python, but I see that it was submitted way back in 2003, > and its status is "deferred." I did a quick search on > comp.lang.python, > bu

Re: Parser Generator?

2007-08-27 Thread Steven Bethard
Paul McGuire wrote: > On Aug 26, 10:48 pm, Steven Bethard <[EMAIL PROTECTED]> wrote: >> In Japanese and Chinese tokenization, word boundaries are not marked by >> different classes of characters. They only exist in the mind of the >> reader who knows which sequences o

Re: Parser Generator?

2007-08-26 Thread Steven Bethard
Paul McGuire wrote: > On Aug 26, 8:05 pm, "Ryan Ginstrom" <[EMAIL PROTECTED]> wrote: >> The only caveat being that since Chinese and Japanese scripts don't >> typically delimit "words" with spaces, I think you'd have to pass the text >> through a tokenizer (like ChaSen for Japanese) before using Py

Re: optparse - required options

2007-08-23 Thread Steven Bethard
Omari Norman wrote: > On Mon, Aug 20, 2007 at 05:31:00PM -0400, Jay Loden wrote: >> Robert Dailey wrote: >>> Well, I don't know what is wrong with people then. I don't see how >>> required arguments are of bad design. > >> I tend to agree...while "required option" may be an oxymoron in >> English,

Re: Module level descriptors or properties

2007-08-21 Thread Steven Bethard
Floris Bruynooghe wrote: > When in a new-style class you can easily transform attributes into > descriptors using the property() builtin. However there seems to be > no way to achieve something similar on the module level, i.e. if > there's a "version" attribute on the module, the only way to chan

Re: unexpected optparse set_default/set_defaults behavior

2007-08-17 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > Some rather unexpected behavior in the set_default/set_defaults > methods for OptionParser that I noticed recently: > import optparse parser = optparse.OptionParser() parser.add_option("-r", "--restart", dest="restart", action="store_true") > parser.

Re: to property or function in class object

2007-08-17 Thread Steven Bethard
james_027 wrote: > i am very new to python, not knowing much about good design. I have an > object here for example a Customer object, where I need to retrieve a > info which has a number of lines of code to get it. > > my question is weather what approach should I use? to use the property > which

Re: advice about `correct' use of decorator

2007-08-16 Thread Steven Bethard
Gerardo Herzig wrote: > Hi all. I guess i have a conceptual question: > Im planing using a quite simple decorator to be used as a conditional > for the execution of the function. I mean something like that: > > @is_logued_in > def change_pass(): >bla >bla > > And so on for all the other

Re: A dumb question about a class

2007-08-14 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > Also, does anyone know if there is some magic that makes > i in some_set > loads faster than > i in some_list It's not magic, per se. It's really part of the definition of the data type. Lists are ordered, and are slow when checking containment. Sets are unordered and

Re: is there anybody using __del__ correctly??

2007-08-13 Thread Steven Bethard
Michele Simionato wrote: > SPECIALMETHODS = ['__%s__' % name for name in > ''' > abs add and call concat contains delitem delslice div eq floordiv ge > getitem > getslice gt iadd iand iconcat idiv ifloordiv ilshift imod imul index > inv invert > ior ipow irepeat irshift isub iter itruediv ixor le l

Re: A dumb question about a class

2007-08-12 Thread Steven Bethard
Steven Bethard wrote: > Dustan wrote: >> On Aug 12, 7:35 pm, Dustan <[EMAIL PROTECTED]> wrote: >>> On Aug 12, 5:09 pm, Steven Bethard <[EMAIL PROTECTED]> wrote: >>> >>>> def iter_primes(): >>>> # an iterat

Re: A dumb question about a class

2007-08-12 Thread Steven Bethard
Dick Moores wrote: > At 03:35 PM 8/12/2007, Steven Bethard wrote: >> Note that if you just want to iterate over all the primes, there's no >> need for the class at all. Simply write:: >> >> for prime in iter_primes(): > > Even if I want to test only 1

Re: A dumb question about a class

2007-08-12 Thread Steven Bethard
Dustan wrote: > On Aug 12, 7:35 pm, Dustan <[EMAIL PROTECTED]> wrote: >> On Aug 12, 5:09 pm, Steven Bethard <[EMAIL PROTECTED]> wrote: >> >>> def iter_primes(): >>> # an iterator of all numbers between 2 and +infinity >>>

Re: A dumb question about a class

2007-08-12 Thread Steven Bethard
Dick Moores wrote: > At 03:09 PM 8/12/2007, Steven Bethard wrote: > >> Here's how I'd write the recipe:: >> >> import itertools >> >> def iter_primes(): >> # an iterator of all numbers between 2 and +infinity >>

Re: A dumb question about a class

2007-08-12 Thread Steven Bethard
Dick Moores wrote: > I'm still trying to understand classes. I've made some progress, I > think, but I don't understand how to use this one. How do I call it, or > any of its functions? It's from the Cookbook, at > . The short answ

Re: is there anybody using __del__ correctly??

2007-08-12 Thread Steven Bethard
Michele Simionato wrote: > On Aug 10, 7:09 pm, Steven Bethard <[EMAIL PROTECTED]> wrote: >> There were also a few recipes posted during this discussion that wrap >> weakrefs up a bit nicer so it's easier to use them in place of __del__: >> >> http://aspn.activ

Re: is there anybody using __del__ correctly??

2007-08-10 Thread Steven Bethard
Raymond Hettinger wrote: > [Michele Simionato] >> Here and there I hear rumors about deprecating __del__ and >> nothing >> happens, are there any news about that? Expecially concerning Py3k? > > I was writing a Py3K PEP advocating the elimination of __del__ > because: > > * 'with closing()' and

Re: Adding a list of descriptors to a class

2007-08-07 Thread Steven Bethard
Bob B. wrote: > I've been playing with descriptors lately. I'm having one problem I > can't seem to find the answer to. I want to assign a descriptor to a > list of attributes. I know I should be able to add these somewhere in > the class's __dict__, but I can't figure out where. Here's some co

Re: how to implementation latent semantic indexing in python..

2007-07-18 Thread Steven Bethard
78ncp wrote: > how to implementation algorithm latent semantic indexing in python > programming...?? malkarouri wrote: > IIRC, there was some explanation of Latent Semantic Analysis (with > Python code) in an IEEE ReadyNotes document called "Introduction to > Python for Artificial Intelligence". I

  1   2   3   4   5   6   7   8   9   10   >