Re: one-time initialization of class members

2007-06-13 Thread Steven Bethard
James Turk wrote: > It actually occured to me that I could use a @classmethod to do the > loading and take that out of the BaseClass constructor. What I have > makes more sense and eliminates the unecessary constructors. > > ie. > > class BaseClass: > @classmethod > def loadData(params):

Re: SimplePrograms challenge

2007-06-13 Thread Steven Bethard
Rob Wolfe wrote: > # HTML page > dinner_recipe = ''' > Recipe > > amtunititem > 24slicesbaguette > 2+tbspolive_oil > 1cuptomatoes > 1-2tbspgarlic > 1/2cupParmesan > 1jarpesto > > ''' > > # program > import xml.etree.ElementTree as etree > tree = etree.fromstring(dinner_recipe) > > #import Eleme

Re: SimplePrograms challenge

2007-06-14 Thread Steven Bethard
rzed wrote: > Steven Bethard <[EMAIL PROTECTED]> wrote in >> def iter_primes(): >> # an iterator of all numbers between 2 and +infinity >> numbers = itertools.count(2) >> >> # generate primes forever >> while True >> >&g

Re: Reference current module?

2007-06-19 Thread Steven Bethard
Tobiah wrote: > Can I do: > > getattr(current_module, 'foo') > > where 'current_module' is a handle the the one > that the code is in? Just like > > getattr(self, 'foo') > > in a class, but for the current module instead? You can try __import__() with __name__:: >>> foo = 42 >>> mo

Re: caseless dictionary howto ?

2007-06-19 Thread Steven Bethard
Stef Mientki wrote: > Evan Klitzke wrote: >> On 6/19/07, Stef Mientki <[EMAIL PROTECTED]> wrote: >>> hello, >>> >>> I need to search a piece of text and make all words that are equal >>> (except their case) also equal in their case, based on the first >>> occurrence. >>> So I'm using a dictionary

Re: caseless dictionary howto ?

2007-06-20 Thread Steven Bethard
Gabriel Genellina wrote: > En Tue, 19 Jun 2007 19:40:10 -0300, Steven Bethard > <[EMAIL PROTECTED]> escribió: > >> Stef Mientki wrote: >>> Evan Klitzke wrote: >>>> On 6/19/07, Stef Mientki <[EMAIL PROTECTED]> wrote: >>>>> >>&

Re: bool behavior in Python 3000?

2007-07-10 Thread Steven Bethard
Alan G Isaac wrote: > > Do you care to explain what is broken? > > I suppose one either finds coercion of arithmetic operations to int > to be odd/broken or does not. But that's all I meant. > > My preference would be for the arithmetic operations *,+,- > to be given the standard interpretation

Re: bool behavior in Python 3000?

2007-07-10 Thread Steven Bethard
Steven D'Aprano wrote: > On Tue, 10 Jul 2007 13:13:38 -0600, Steven Bethard wrote: > >> It's much easier to explain to newcomers that *, + and - work on True >> and False as if they were 1 and 0 than it is to introduce them to a two >> element boolean alge

Re: bool behavior in Python 3000?

2007-07-11 Thread Steven Bethard
Steven D'Aprano wrote: > On Tue, 10 Jul 2007 17:47:47 -0600, Steven Bethard wrote: >> But I think all you're really saying is that newbies don't expect things >> like +, -, *, etc. to work with bools at all. Which I agree is probably >> true. > > No, wha

Re: Function parameter type safety?

2007-07-12 Thread Steven Bethard
Robert Dailey wrote: > Is there a way to force a specific parameter in a function to be a > specific type? For example, say the first parameter in a function of > mine is required to be a string. If the user passes in an integer, I > want to notify them that they should pass in a string, not an int

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

Re: Text Suffix to Prefix Conversion

2007-04-18 Thread Steven Bethard
EMC ROY wrote: > Original Sentence: An apple for you. > Present: An apple for you .<.> > Desire:An apple for you <.>. >>> text = 'An apple for you .<.>' >>> import re >>> re.sub(r'(\S+)(<[^>]+>)(\s*)', r'\2\1\3', text) 'An apple for you <.>.' -- http://mail.python.org/mailma

Re: Python un-plugging the Interpreter

2007-04-19 Thread Steven Bethard
S.Mohideen wrote: > I was thinking about the feasbility of adjusting Python as a > compiled language. Python is a compiled language. It's compiled from source code to byte code. That's what the .pyc files are. STeVe -- http://mail.python.org/mailman/listinfo/python-list

Re: Fast and capable XML parser?

2007-04-20 Thread Steven Bethard
Magnus Lycka wrote: > I'm looking for some library to parse XML code > much faster than the libs built into Python 2.4 > (I'm stuck with 2.4 for quite a while) and I > also need XML Schema validation, and would > appreciate support for e.g. XPath and XInclude. > I also want an API which is more Pyt

Re: Python "robots.txt" parser broken since 2003

2007-04-22 Thread Steven Bethard
John Nagle wrote: > Terry Reedy wrote: >> "John Nagle" <[EMAIL PROTECTED]> wrote in message >> news:[EMAIL PROTECTED] >> | This was reported in 2003, and a patch was uploaded in 2005, but the >> patch >> | never made it into Python 2.4 or 2.5. >> >> If the patch is still open, perhaps you could r

Re: recursion depth problem

2007-04-22 Thread Steven Bethard
proctor wrote: > On Apr 22, 1:24 pm, Michael Bentley <[EMAIL PROTECTED]> wrote: >> On Apr 22, 2007, at 1:49 PM, proctor wrote: >> >> >> >>> i have a small function which mimics binary counting. it runs fine as >>> long as the input is not too long, but if i give it input longer than >>> 8 characte

Re: recursion depth problem

2007-04-22 Thread Steven Bethard
proctor wrote: > On Apr 22, 2:06 pm, Steven Bethard <[EMAIL PROTECTED]> wrote: >> proctor wrote: >>> On Apr 22, 1:24 pm, Michael Bentley <[EMAIL PROTECTED]> wrote: >>>> On Apr 22, 2007, at 1:49 PM, proctor wrote: >>>>> i have a smal

Re: recursion depth problem

2007-04-22 Thread Steven Bethard
Alex Martelli wrote: > Steven Bethard <[EMAIL PROTECTED]> wrote: >... >>>>>>> import sys >>>>>>> def ch4(item, n=0): >>>>>>>if n < len(item): >>>>>>>if ite

Re: If Dict Contains a particular key

2007-04-24 Thread Steven Bethard
Steven Howe wrote: > Carsten Haese wrote: >> On Tue, 2007-04-24 at 18:28 +0100, Robert Rawlins - Think Blue wrote: >> >>> Hello Guys, >>> >>> >>> >>> I’m Looking to build a quick if/else statement that checks a >>> dictionary for a key like follows. >>> >>> >>> >>> If myDict contains ThisKey:

Re: Where's the source code for __builtin__?

2007-04-24 Thread Steven Bethard
Ben Finney wrote: > John Machin <[EMAIL PROTECTED]> writes: >> On 25/04/2007 9:32 AM, Dustan wrote: >>> I've been paging through the source code for various C modules in >>> python, and wanted to find the source of some of the builtin >>> functions. >> What's the 2nd file (in alphabetical order) in

Re: regexp match string with word1 and not word2

2007-04-30 Thread Steven Bethard
Flyzone wrote: > Hello, > i have again problem with regexp :-P > I need to match all lines that contain one word but not contain > another. > Like to do "grep one | grep -v two:" You don't need a regexp:; if 'one' in line and 'two:' not in line: ... do something... STeVe -- http:/

Re: regexp match string with word1 and not word2

2007-04-30 Thread Steven Bethard
Flyzone wrote: > On 30 Apr, 17:11, Steven Bethard <[EMAIL PROTECTED]> wrote: > >> You don't need a regexp:; > > I need a regexp.i'm parsing a file with a rule-file that contains > also regexp and strings too Well then it seems like you might wan

Re: __dict__s and types and maybe metaclasses...

2007-05-02 Thread Steven Bethard
Adam Atlas wrote: > Suppose I want to create a type (i.e. a new-style class via the usual > `class blah(...)` mechanism) but, during the process of creating the > type, I want to replace its __dict__ If I understand you right, what you want is something like:: class MyDict(object):

Re: Getting some element from sets.Set

2007-05-09 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > I've also previously run into the same need as the original poster. I > no longer recall the details, but I think maybe I was implementing a > union/find type algorithm. This basically involves partitioning a > universe set into partitions, where any element of a partit

Re: which is more pythonic/faster append or +=[]

2007-05-10 Thread Steven Bethard
7stud wrote: >> Is there any documentation for the syntax you used with timeit? > > This is the syntax the docs describe: [snip > python timeit.py [-n N] [-r N] [-s S] [-t] [-c] [-h] [statement ...] [snip] > Then in the examples in section 10.10.2 [snip] > timeit.py 'try:' ' str.__nonzero__' 'exc

Re: Dynamic subclassing ?

2007-05-12 Thread Steven Bethard
manatlan wrote: > I've got an instance of a class, ex : > > b=gtk.Button() > > I'd like to add methods and attributes to my instance "b". > I know it's possible by hacking "b" with setattr() methods. But i'd > like to do it with inheritance, a kind of "dynamic subclassing", > without subclassing

Re: package rating system for the Cheese Shop

2007-05-12 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > Is there a package rating system for the Cheese Shop, like how Perl > has cpanratings (http://cpanratings.perl.org/)? I don't know CPAN, but maybe this is what you're looking for: http://www.cheeserater.com/ ? STeVe -- http://mail.python.org/mailman/listinfo/pyt

Re: package rating system for the Cheese Shop

2007-05-13 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > On May 12, 2:49 pm, Steven Bethard <[EMAIL PROTECTED]> wrote: >> [EMAIL PROTECTED] wrote: >>> Is there a package rating system for the Cheese Shop, like how Perl >>> has cpanratings (http://cpanratings.perl.org/)? >> I don

Re: Using "subprocess" without lists. . .?

2007-05-13 Thread Steven Bethard
Michael Williams wrote: > Hi All, > > I've recently seen the "subprocess" module and am rather confused by > it's requirements. Is it not possible to execute an entire string > without having to break them up into a list of arguments? For instance, > I'd much rather do the following: > > >

Re: How do I tell the difference between the end of a text file, and an empty line in a text file?

2007-05-16 Thread Steven Bethard
walterbyrd wrote: > Python's lack of an EOF character is giving me a hard time. > > I've tried: > > - > s = f.readline() > while s: > . > . > s = f.readline() > > > and > > --- > s = f.readline() > while s != '' > . > . > s = f.readline() > --- > > > In both cases, the lo

Re: how do I count spaces at the beginning of a string?

2007-05-16 Thread Steven Bethard
walterbyrd wrote: > The strings start with whitespace, and have a '*' or an alphanumeric > character. I need to know how many whitespace characters exist at the > beginning of the string. You really need to stop posting the same message multiple times. A possible answer using regular expressions:

Re: docs patch: dicts and sets

2007-05-19 Thread Steven Bethard
Alan Isaac wrote: > I submitted the language based on Bill and Carsten's proposals: > > https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1721372&group_id=5470 > > That language has been rejected. > You many want to read the discussion and see if > acceptible language still seems disco

Re: docs patch: dicts and sets

2007-05-19 Thread Steven Bethard
7stud wrote: > On May 19, 9:06 am, Steven Bethard <[EMAIL PROTECTED]> wrote: >> Alan Isaac wrote: >>> I submitted the language based on Bill and Carsten's proposals: >>> https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1721372&;... >

pyparsing actinos (WAS: Inverse of id()?)

2007-05-21 Thread Steven Bethard
Paul McGuire wrote: > For instance, Seo Sanghyeon (I believe the same one now working on > IronPython) uses the following technique in the EBNF parser/"compiler" > that he contributed to the pyparsing examples directory: > > # list of all the grammar variable names > all_names = ''' > integer > me

converting text and spans to an ElementTree

2007-05-21 Thread Steven Bethard
I have some text and a list of Element objects and their offsets, e.g.:: >>> text = 'aaa aaa aaabbb bbbaaa' >>> spans = [ ... (etree.Element('a'), 0, 21), ... (etree.Element('b'), 11, 18), ... (etree.Element('c'), 18, 18), ... ] I'd like to produce the co

Re: converting text and spans to an ElementTree

2007-05-22 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > On May 21, 11:02 pm, Steven Bethard <[EMAIL PROTECTED]> wrote: >> I have some text and a list of Element objects and their offsets, e.g.:: >> >> >>> text = 'aaa aaa aaabbb bbbaaa' >> >

Re: converting text and spans to an ElementTree

2007-05-22 Thread Steven Bethard
Gabriel Genellina wrote: > the idea would be as follows: > > - For each span generate two tuples: (start_offset, 1, end_offset, > element) and (end_offset, 0, -start_offset, element). If start==end use > (start_offset, -1, start_offset, element). > - Collect all tuples in a list, and sort them.

Re: xml.parsers.expat loading xml into a dict and whitespace

2007-05-22 Thread Steven Bethard
kaens wrote: > Let's say I write a simple xml parser, for an xml file that just loads > the content of each tag into a dict (the xml file doesn't have > multiple hierarchies in it, it's flat other than the parent node) [snip] > > hey > bee > eff > > > it prints out: > " : > > three : eff > two

Re: xml.parsers.expat loading xml into a dict and whitespace

2007-05-23 Thread Steven Bethard
kaens wrote: > Now the code looks like this: > [snip ElementTree code] > > freaking easy. Compare with making a generic xml parser class, and > inheriting from it for doing different things with different xml > files. This does exactly the right thing. I'm sure it's not perfect > for all cases, and

Re: converting text and spans to an ElementTree

2007-05-23 Thread Steven Bethard
Neil Cerutti wrote: > On 2007-05-22, Steven Bethard <[EMAIL PROTECTED]> wrote: >> Thanks a lot! This put me on the right track (though the >> devil's definitely in the details). It's working now:: >> >> >>>>> tree

Re: optparse: list out entered values

2007-05-25 Thread Steven Bethard
Nirnimesh wrote: > On May 25, 3:07 am, Nirnimesh <[EMAIL PROTECTED]> wrote: >> I'm using optparse.OptionParser for parsing command line arguments. >> >> parser = optparse.OptionParser() >> parser.add_option("-x", "--xample", help="example", >> default="nothing", >> dest="ex") >> options

Re: ten small Python programs

2007-05-26 Thread Steven Bethard
Steve Howell wrote: > I've always thought that the best way to introduce new > programmers to Python is to show them small code > examples. > > When you go to the tutorial, though, you have to wade > through quite a bit of English before seeing any > Python examples. > > Below is my attempt at

PyPI bdist_wininst upload failing

2007-05-26 Thread Steven Bethard
I just tried to upload new versions of the argparse module to PyPI, but it seems like I can no longer upload Windows installers: $ setup.py sdist bdist_wininst upload ... running upload Submitting dist\argparse-0.8.0.zip to http://www.python.org/pypi Server response (200): OK Su

Re: ten small Python programs

2007-05-26 Thread Steven Bethard
Paul McGuire wrote: > I ***love*** this "10 Little Programs" idea! As soon as I get a > breathing space, I'm going to add a "10 Little Parsers" page to the > pyparsing wiki! > > On May 26, 2:38 pm, Steven Bethard <[EMAIL PROTECTED]> wrote: >&

Re: PyPI bdist_wininst upload failing

2007-05-26 Thread Steven Bethard
Steven Bethard wrote: > I just tried to upload new versions of the argparse module to PyPI, but > it seems like I can no longer upload Windows installers: > > $ setup.py sdist bdist_wininst upload > ... > running upload > Submitting dist\argparse-0.8.0.zip to http:

Re: Is PEP-8 a Code or More of a Guideline?

2007-05-26 Thread Steven Bethard
Stefan Sonnenberg-Carstens wrote: > Paul McGuire schrieb: >> I'm starting a new thread for this topic, so as not to hijack the one >> started by Steve Howell's excellent post titled "ten small Python >> programs". >> >> In that thread, there was a suggestion that these examples should >> conform to

Re: PyPI bdist_wininst upload failing

2007-05-27 Thread Steven Bethard
John Machin wrote: > On May 27, 4:20 pm, Steven Bethard <[EMAIL PROTECTED]> wrote: >> Steven Bethard wrote: >>> I just tried to upload new versions of the argparse module to PyPI, but >>> it seems like I can no longer upload Windows installers: > [snip] >>

Re: PyPI bdist_wininst upload failing

2007-05-27 Thread Steven Bethard
Gabriel Genellina wrote: > En Sun, 27 May 2007 12:19:03 -0300, Steven Bethard > <[EMAIL PROTECTED]> escribió: > >> Also, I couldn't get the StringIO code from there to work: >> >> >>> import StringIO >> >>> content = open(&#x

Re: PyPI bdist_wininst upload failing

2007-05-27 Thread Steven Bethard
Steven Bethard wrote: > Gabriel Genellina wrote: >> En Sun, 27 May 2007 12:19:03 -0300, Steven Bethard >> <[EMAIL PROTECTED]> escribió: >> >>> Also, I couldn't get the StringIO code from there to work: >>> >>> >>> impo

[ANN] argparse 0.8 - Command-line parsing library

2007-05-27 Thread Steven Bethard
=== Announcing argparse 0.8 === The argparse module is an optparse-inspired command line parser that improves on optparse by supporting: * positional arguments * sub-commands * required options * options with a variable number of args * better usage message

Re: ten small Python programs

2007-05-27 Thread Steven Bethard
Steve Howell wrote: > --- Steven Bethard <[EMAIL PROTECTED]> wrote: >> Very cool! Do you mind putting this up on the Wiki >> somewhere so that we >> can link to it more easily? Maybe something like: >> >> http://wiki.python.org/moin/SimplePrograms >

Re: ten small Python programs

2007-05-27 Thread Steven Bethard
Steve Howell wrote: > --- Steven Bethard <[EMAIL PROTECTED]> wrote: >> I think I would rewrite the current unit-testing >> example to use the >> standard library unittest module:: >> >> # Let's write reusable code, and unit test it. >> d

Re: ten small Python programs

2007-05-27 Thread Steven Bethard
Steve Howell wrote: > --- Steven Bethard <[EMAIL PROTECTED]> wrote: > >> I think I would rewrite the current unit-testing >> example to use the >> standard library unittest module:: >> >> # Let's write reusable code, and unit test it. &

Re: ten small Python programs

2007-05-27 Thread Steven Bethard
Steve Howell wrote: > --- Steven Bethard <[EMAIL PROTECTED]> wrote: > >> Steve Howell wrote: >>> --- Steven Bethard <[EMAIL PROTECTED]> >> wrote: >>>> I think I would rewrite the current unit-testing >>>> example to use the >&

Re: Error in optparse documentation

2007-05-27 Thread Steven Bethard
Shatadal wrote: > In the python documentation section 14.3.2.6 (http://docs.python.org/ > lib/optparse-generating-help.html) in the last line it is written > > "options that have a default value can include %default in the help > string--optparse will replace it with str() of the option's default

Re: unit testing

2007-05-27 Thread Steven Bethard
Steve Howell wrote: > --- Steven Bethard <[EMAIL PROTECTED]> wrote: >> Have you tried py.test? >> >> http://codespeak.net/py/dist/test.html >> >> I've heard good things about it, but haven't gotten >> around to trying it >

Re: Is PEP-8 a Code or More of a Guideline?

2007-05-28 Thread Steven Bethard
John J. Lee wrote: > Paul McGuire <[EMAIL PROTECTED]> writes: > [...] >> http://mail.python.org/pipermail/python-dev/2005-December/058750.html >> >> At first, Guido seemed ambivalent, and commented on the >> contentiousness of the issue, but it seems that the "non-English >> speakers can more easil

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: 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: 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: 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: 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
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: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
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: 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-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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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-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-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: 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: 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: Setting Up SOAPpy for Python v2.5 on Windows?

2007-03-13 Thread Steven Bethard
Steve wrote: > What are the required version of the SOAPpy, PyXML, fpconst that are > needed to run under the Python 2.5 environment on Windows? If you're not married to SOAPpy, you can use elementsoap which has just a single download and works with ElementTree from the 2.5 stdlib: http://e

Re: Multiline code - trailing slash usage

2007-03-15 Thread Steven Bethard
abcd wrote: > When do I need to use a trailing slash to separate code over multiple > lines. > > For example: > > x = "hello world, this is my multiline " + \ > "string" Yes. > > x = {'name' : \ > 'bob'} No. You don't need trailing slashes whenever there's a pair of {}, [] or

Re: To count number of quadruplets with sum = 0

2007-03-15 Thread Steven Bethard
n00m wrote: > http://www.spoj.pl/problems/SUMFOUR/ > > 3 > 0 0 0 0 > 0 0 0 0 > -1 -1 1 1 > Answer for this input data is 33. > > My solution for the problem is > == > > import time > t = time.clock() > > q,w,e,r,sch,h = [],[],[

Re: To count number of quadruplets with sum = 0

2007-03-16 Thread Steven Bethard
Marc 'BlackJack' Rintsch wrote: > In <[EMAIL PROTECTED]>, Paul Rubin wrote: > >> "n00m" <[EMAIL PROTECTED]> writes: >>> h = collections.defaultdict(itertools.repeat(0).next) >> Something wrong with >>h = collections.defaultdict(int) >> ? > > According to a post by Raymond Hettinger it's

Re: getopt or optparse options/arguments wrapping?

2007-03-16 Thread Steven Bethard
Rocky Zhou wrote: > I wonder is there any way to make the wrapper program can wrap options > && arguments for the the subprocess/command the wrapper will > execute? by getopt or optparse module? [snip] > I need this because I now have finished a fs_backup script written in > python, it will execu

Re: getopt or optparse options/arguments wrapping?

2007-03-18 Thread Steven Bethard
Rocky Zhou wrote: > .dirs .files is just a snapshot of the current directories, which can > be used to delete-outdated files when restoring. Here I used absolute > path by using tar's -P parameter. When fs_rstore, it will do this: > command = "tar -xpz -P -f %s.tgz -T %s" % (archive, self.t_files)

Re: where function

2007-03-18 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > Is there a function in Python analogous to the "where" function in > IDL? > > x=[0,1,2,3,4,2,8,9] > print where(x=2) > > output: > [2,5] If you're doing a lot of this kind of thing, you probably want to use numpy:: >>> import numpy >>> x = numpy.array([0, 1

Re: Passing arguments to a command line from a python script

2007-03-19 Thread Steven Bethard
Luis M. González wrote: > On Mar 19, 10:49 pm, "zacherates" <[EMAIL PROTECTED]> wrote: >> This implies that `os.system("setuppy py2exe")` should do what you >> want. > > It works! > Thank you, this is just what I wanted. You'll get better error checking if instead you do:: >>> import subpro

Re: an enumerate question

2007-03-19 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > for n,l in enumerate(open("file")): >print n,l # this prints current line >print next line in this current iteration of the loop. Depends what you want to happen when you request "next". If you want to renumber the lines, you can call .next() on the iterator::

Re: why brackets & commas in func calls can't be ommited? (maybe it could be PEP?)

2007-03-21 Thread Steven Bethard
dmitrey wrote: > I looked to the PEPs & didn't find a proposition to remove brackets & > commas for to make Python func call syntax caml- or tcl- like: instead > of > result = myfun(param1, myfun2(param5, param8), param3) > just make possible using > result = myfun param1 (myfun2 param5 param8) pa

Re: Multi-line strings with formatting

2007-03-23 Thread Steven Bethard
On Fri, 2007-03-23 at 09:54 -0700, [EMAIL PROTECTED] wrote: > When constructing a particularly long and complicated command to be > sent to the shell, I usually do something like this, to make the > command as easy as possible to follow: > commands.getoutput( > 'mycommand -S %d -T %d ' % (

Re: functions, classes, bound, unbound?

2007-03-24 Thread Steven Bethard
7stud wrote: > Here is some example code that produces an error: > > class Test(object): > def greet(): > print "Hello" > > t = Test() > t.greet() > TypeError: greet() takes no arguments (1 given) [snip] > Test.greet() > > TypeError: unbound method greet() must be called

Re: Pattern for foo tool <-> API <-> shell|GUI

2007-03-25 Thread Steven Bethard
Anastasios Hatzis wrote: > I'm working on a tool which is totally command-line based and consisting of > multiple scripts. The user can execute a Python script in the shell, this > script does some basic verification before delegating a call into my tool's > package and depending on some argumen

[ANN] argparse 0.7 - Command-line parsing library

2007-03-25 Thread Steven Bethard
Announcing argparse 0.7 --- The argparse module is an optparse-inspired command line parser that improves on optparse by supporting: * positional arguments * sub-commands * required options * options with a variable number of args * better usage messages * a much simpler exten

Re: functions, classes, bound, unbound?

2007-03-25 Thread Steven Bethard
On Mar 25, 9:13 am, "7stud" <[EMAIL PROTECTED]> wrote: > Is there some other way to retrieve a user-defined function object > from a class other than using the class name or an instance? On Mar 25, 3:00 am, [EMAIL PROTECTED] wrote: > What Steven B. already said, MyClass.__dict__['someFunc'], is

Re: Modules & positive surprises

2007-03-30 Thread Steven Bethard
Jan Danielsson wrote: >But then there are a few modules that I just love to use, because > they are so "clean" from interface to function. Among them I can't help > mentioning optparse. If you like optparse, you should try argparse: http://argparse.python-hosting.com/ It has an optpars

Re: Sorting a multidimensional array by multiple keys

2007-03-31 Thread Steven Bethard
Rehceb Rotkiv wrote: >> If you want a good answer you have to give me/us more details, and an >> example too. > > OK, here is some example data: > > reaction is BUT by the > sodium , BUT it is > sea , BUT it is > this manner BUT the dissolved > pattern , BUT it is > rapid , BUT it is > > As each

Re: I18n issue with optik

2007-03-31 Thread Steven Bethard
Thorsten Kampe wrote: > I've written a script which uses Optik/Optparse to display the > options (which works fine). The text for the help message is localised > (with german umlauts) and when I execute the script with the localised > environment variable set, I get this traceback[1]. The intere

Re: I18n issue with optik

2007-04-01 Thread Steven Bethard
Thorsten Kampe wrote: > * Steven Bethard (Sat, 31 Mar 2007 20:08:45 -0600) >> Thorsten Kampe wrote: >>> I've written a script which uses Optik/Optparse to display the >>> options (which works fine). The text for the help message is localised >>> (wi

<    8   9   10   11   12   13   14   15   16   >