Re: beginner, idiomatic python

2007-08-27 Thread Neil Cerutti
On 2007-08-27, Neil Cerutti <[EMAIL PROTECTED]> wrote: > This sort of suggests a direct solution: > > for i in xrange(self.parent.GetPageCount()): > if i >= self.parent.GetPageCount(): > break > # do stuff > > At least that way you're spared the manual

Re: convert non-delimited to delimited

2007-08-27 Thread Neil Cerutti
Processing in Python_ for one solution. http://gnosis.cx/TPiP/chap2.txt -- Neil Cerutti Weight Watchers will meet at 7 p.m. Please use large double door at the side entrance. --Church Bulletin Blooper -- http://mail.python.org/mailman/listinfo/python-list

Re: int/long bug in locale?

2007-08-28 Thread Neil Cerutti
f it is a bug, it is not in the locale code. >>> '%d' % float('22440125.') Traceback (most recent call last): File "", line 1, in TypeError: int argument required The documentation for the string formating operation doesn't specify what happens when you convert a non-int with specifier '%d'. In defense of your code, there's also no explicit requirement to do that. http://docs.python.org/lib/typesseq-strings.html -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: general function for sorting a matrix

2007-08-29 Thread Neil Cerutti
orting code every time she encounters a list. The advantage of such a richly implemented language as Python, is that a programmer don't need to write a general sorting algorithm at all. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: Python doesn't see the directories I create

2007-08-30 Thread Neil Cerutti
ears. To me, Python's collection of special-purpose string literal notations is one of its little warts. Of course, I'm not smart enough to have delivered the ONE TRUE string literal notation either, but I do have a computer and an internet connection, so there you are. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: Python doesn't see the directories I create

2007-08-30 Thread Neil Cerutti
On 2007-08-30, Steve Holden <[EMAIL PROTECTED]> wrote: > Neil Cerutti wrote: >> To me, Python's collection of special-purpose string literal >> notations is one of its little warts. > > Well, it's a wart that's shared with many other languages - > incl

Re: list index()

2007-08-30 Thread Neil Cerutti
ommon in modern Python code. The hair shirts and thumb-screws necessary for using exceptions correctly in C++, aren't needed in Python. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: list index()

2007-08-30 Thread Neil Cerutti
really some reason "key" IN dict can be implemented > faster than dict.has_key("key")??? Yes. Looking up the has_key method by name is the slower part. -- Neil Cerutti We're not afraid of challenges. It's like we always say: If you want to go out in

Re: beginner, idomatic python 2

2007-08-30 Thread Neil Cerutti
s simply in order to get the code to compile. A common example is a set of classes that all behave like file streams. You don't need to do this in Python. Simply have the object provide the right methods and you are done. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: Python doesn't see the directories I create

2007-08-31 Thread Neil Cerutti
On 2007-08-31, Lawrence D'Oliveiro <[EMAIL PROTECTED]> wrote: > In message <[EMAIL PROTECTED]>, Neil > Cerutti wrote: >> Keeping in mind which came first, isn't it at least as >> accurate to attribute this problem to Python's choice of >> escape

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

2007-08-31 Thread Neil Cerutti
re composed by the programmers writing the code. Is it likely that the same person who wrote a buggy function will know the right contract? -- Neil Cerutti The third verse of Blessed Assurance will be sung without musical accomplishment. --Church Bulletin Blooper -- http://mail.python.org/mailman/listinfo/python-list

Re: Why is this loop heavy code so slow in Python? Possible Project Euler spoilers

2007-09-02 Thread Neil Cerutti
. In Java (at least in > HotSpot), the byte code is further compiled to machine code > before execution; in Python, the byte code is interpreted. > > Whether this makes Python an interpreter or a compiler, I don't > know. I'd call it an integrated compiler and virtual mac

Re: Why is this loop heavy code so slow in Python? Possible Project Euler spoilers

2007-09-02 Thread Neil Cerutti
7;d like to see Python run as fast as C or Lisp, and > you have a few tens of millions of dollars spare to invest in > development, I think the Python Software Foundation would love > to hear from you. Hmmm. I have four dollars... almost five... -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: OT: pronounciation [was: list index()]

2007-09-04 Thread Neil Cerutti
pronounce >> Python... well, the way they do, with the stress and something of a >> drawl on the second syllable. I'm sure it's just as amusing the other >> way round: we pronounce it with the stress on the first syllable and >> the characteristic short vowel soun

Re: list index()

2007-09-04 Thread Neil Cerutti
s will be faster for shortish lengths of subseq. It was certainly easier to get it working correctly. ;) def find(seq, subseq): for i, j in itertools.izip(xrange(len(seq)-len(subseq)), xrange(len(subseq), len(seq))): if subseq == seq[i:j]: return i return -1 --

Re: interesting puzzle......try this you will be rewarded...

2007-09-07 Thread Neil Cerutti
thing :) Y'all may be thinking of The Euler Project, which provides math puzzles for programmers. http://projecteuler.net/ -- Neil Cerutti I pulled away from the side of the road, glanced at my mother-in-law and headed over the embankment. --Insurance Claim Blooper -- http://mail.python.org/mailman/listinfo/python-list

Re: library to launch program in linux

2007-09-07 Thread Neil Cerutti
'm a new user. What library should I use so that I can launch >>>> program in linux using python? >>>> >>> >>> subprocess >>> >> Hmm, there are some others... > > subprocess subsumes them all. And someday soon, subprocess will RULE THE WORLD! BWA-HAHAHAHAH! -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: Checking if elements are empty

2007-09-10 Thread Neil Cerutti
if the first element of y is non-null. > > Such as? Seriously people, a little more verbosity wouldn't > hurt here. This isn't a mystery game. >>> if "": True ... >>> if 0: True ... >>> if []: True ... >>> if {}: True ... >>

Re: Checking if elements are empty

2007-09-10 Thread Neil Cerutti
On 2007-09-10, Chris Mellon <[EMAIL PROTECTED]> wrote: > On 9/10/07, Neil Cerutti <[EMAIL PROTECTED]> wrote: >> On 2007-09-08, Wildemar Wildenburger <[EMAIL PROTECTED]> wrote: >> > Lawrence D'Oliveiro wrote: >> >>>>> if y[0]: >>

Re: Checking if elements are empty

2007-09-10 Thread Neil Cerutti
On 2007-09-10, Chris Mellon <[EMAIL PROTECTED]> wrote: > On 9/10/07, Neil Cerutti <[EMAIL PROTECTED]> wrote: >> Agreed; but I prefer 'if y[0] == ""', absent more context and >> better names. > > Probably should use u"" if you

Re: Checking if elements are empty

2007-09-11 Thread Neil Cerutti
a quibble with a test that will raise an exception when > the anticipated condition is true. Your test is patently > absurd, as you would have discovered had you bothered to try > it: "if y[0] == "" expresses more, i.e., that I expect y[0] to contain a Python byte string.

Re: Why is this loop heavy code so slow in Python? Possible Project Euler spoilers

2007-09-11 Thread Neil Cerutti
On 2007-09-11, Robert Brown <[EMAIL PROTECTED]> wrote: > Neil Cerutti <[EMAIL PROTECTED]> writes: > >> On 2007-09-02, Steven D'Aprano >> <[EMAIL PROTECTED]> wrote: >>> A big question mark in my mind is Lisp, which according to >>&g

Re: Enum class with ToString functionality

2007-09-12 Thread Neil Cerutti
ld be "Enum > 2008", and the next major update could be called "Enum > Professional Capowie!!!". I like the (priviledged) code names adopted by the Linux community for special versions, e.g., Enum 2.7.1 (Flapjacks). This would really tie the Enum-using community together, and make mess

Re: newbie: self.member syntax seems /really/ annoying

2007-09-12 Thread Neil Cerutti
mber shortcut proposal. Most proposals don't even address that point. Does it become: class Foo: def __init__(): .bar = 40 or class Foo: def __init__(.): .bar = 40 or class Foo: def __init__(self): .bar = 40 I guess the middle one is the most consistent, but it seems

Re: An ordered dictionary for the Python library?

2007-09-12 Thread Neil Cerutti
er respondent asked about use cases. A mapping with sorted keys could theoretically be convenient when your keys are comparable but not hashable. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: recursion

2007-09-13 Thread Neil Cerutti
the length of seq, my_sum(seq) terminates with the value of the sum of all the items in seq for any length of seq. But really I prefer the first first plain English version. ;) -- Neil Cerutti For those of you who have children and don't know it, we have a nursery downstairs. --Church Bulletin Blooper -- http://mail.python.org/mailman/listinfo/python-list

Re: recursion

2007-09-13 Thread Neil Cerutti
On 2007-09-13, Ian Clark <[EMAIL PROTECTED]> wrote: > Neil Cerutti wrote: >> On 2007-09-13, Gigs_ <[EMAIL PROTECTED]> wrote: >>> Can someone explain me this >>> >>>>>> def f(l): >>> if l == []: >>> return

Re: recursion

2007-09-14 Thread Neil Cerutti
er. A little intuitive leap, perhaps, will allow you to note that the case of a two-element list can actually be handled without a special case: def f(l): if len(l) < 2: return l else: return f(l[1:]) + l[:1] Final note: for reasons of tradition, base cases are almost always set up as it was in the original function, checking for a zero-length list, and returning a new empty list, the truly simplest base case. Another intuitive leap is possibly required to note that a one-element list is not a special case after all: it's a reverse of a zero-element list with that one element appended. def f(l): if len(l) == 0: return [] else: return f(l[1:]) + l[:1] Clear as mud? -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: where is help file?

2007-09-14 Thread Neil Cerutti
; necessary in the interactive helper you start by calling > help(). The interactive help function is cool. You need to download and install the HTML version of the standard docs to take the utmost advantage of it. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: Parsing problems: A journey from a text file to a directory tree

2007-09-16 Thread Neil Cerutti
OK for the directories to be unordered, which doesn't appear to be the case. > But this doesn't do the trick, as I also have to save the > hierarchy level of the current folder as well... The above does store the hierarchy, as the number of nesting levels. ditreedb['New Client']['Offers']['Denied'] -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: can Python be useful as functional?

2007-09-18 Thread Neil Cerutti
mming is *functions*. > > Functional lists are not quite the same. They are actually > recursive datastructes. In Python you would model them as > nested tuples: > > t = (a, (b, (c, ...(d, None) Tuples won't work for cyclic data, though. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: super() doesn't get superclass

2007-09-19 Thread Neil Cerutti
ot the same as > superclass of type(self). Super iterates over the latter, > where you expect the former. I can't blame a person for thinking that the call super(A, self) is taking the superclass of A. A is perhaps too prominently placed. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: super() doesn't get superclass

2007-09-19 Thread Neil Cerutti
s happening. super.foo() to me, is even more confusing. self.super.foo() or super(self).foo() seem like improvements. Unfortunately, neither is one of the current alternate proposals. The closest competing proposal in PEP3135 is: self.__super__.foo() That syntax seems justified given the

Re: Sets in Python

2007-09-20 Thread Neil Cerutti
to Python's basic assignment semantics and clever type hierarchy that it's hard to even sensibly promote anything other than the current implementation without completely redesigning Python. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: An Editor that Skips to the End of a Def

2007-09-24 Thread Neil Cerutti
ther text > editor still surviving uses such an antiquated concept. The existence of command mode allows plain old keystrokes to be commands--it potentially makes commands easier to type. Emacs users don't find it to be a compelling advantage. ;) -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: An Editor that Skips to the End of a Def

2007-09-26 Thread Neil Cerutti
s the very cool elisp scripting language. I'm not so keen on Vim's built-in scripting language. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: What is a good way of having several versions of a python module installed in parallell?

2007-09-27 Thread Neil Cerutti
t integrates with Python's unit testing modules, so if you need to "graduate", it is simple to do so. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: Using fractions instead of floats

2007-10-01 Thread Neil Cerutti
On 2007-10-01, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > Finally, arithmetic would become very confusing if there were > three distinct numeric types; it already causes enough > confusion with two! Scheme says: It's not that bad. -- Neil Cerutti I am free of all prejudi

Re: Using fractions instead of floats

2007-10-02 Thread Neil Cerutti
On 2007-10-01, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > On Oct 1, 6:26 pm, Neil Cerutti <[EMAIL PROTECTED]> wrote: >> On 2007-10-01, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: >> >> > Finally, arithmetic would become very confusing if there were >

Re: Using fractions instead of floats

2007-10-02 Thread Neil Cerutti
On 2007-10-02, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > On Oct 2, 12:42 pm, Neil Cerutti <[EMAIL PROTECTED]> wrote: >> On 2007-10-01, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: >> > Scheme has prefix numeric operators, so that 1/2 is >> > unamb

Re: module confusion

2007-10-04 Thread Neil Cerutti
do people react to the word "pointer" as though > computers have to wear underwear to conceal something shameful > going on in their nether regions? Refraining from thinking about pointers (unless I have to) saves wear and tear on the old bean. I also like to think of 5 as an integer most of the time. -- Neil Cerutti Will the last person to leave please see that the perpetual light is extinguished --sign at New England church -- http://mail.python.org/mailman/listinfo/python-list

Re: What does the syntax [::-1] really mean?

2007-10-04 Thread Neil Cerutti
:0:-1] => "cb", not "cba". Changing the "end" value to > x[n:-1:-1] results in an empty string. Your proposed sequence, x[n:0:-1] is half-open on the wrong end. When k is -1 then j must also be negative. This is because there's no way to refer to the element one before the first element without using a negative index value for j. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: module confusion

2007-10-05 Thread Neil Cerutti
On 2007-10-05, Lawrence D'Oliveiro <[EMAIL PROTECTED]> wrote: > In message <[EMAIL PROTECTED]>, Neil Cerutti wrote: > >> On 2007-10-03, Lawrence D'Oliveiro <[EMAIL PROTECTED]> >> wrote: >>> In Python, all names _are_ variables. They are not &q

Re: Newbi Q: What is a rational for strings not being lists in Python?

2007-10-15 Thread Neil Cerutti
On 2007-10-15, Simon Brunning <[EMAIL PROTECTED]> wrote: > On 10/15/07, Dmitri O.Kondratiev <[EMAIL PROTECTED]> wrote: >> To clarify my point: >> reverse() is a lucky one - Python has variants of *this particular* >> function both for lists and strings. Yet what about other list functions? >> Ho

Re: Newbi Q: What is a rational for strings not being lists in Python?

2007-10-16 Thread Neil Cerutti
mmutable. > ><http://c2.com/cgi/wiki?ValueObjectsShouldBeImmutable> And strings are considered value objects because... -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: Noob questions about Python

2007-10-17 Thread Neil Cerutti
yway. You can obtain a practical workaround using the int built-in function. >>> int('110', 2) 6 -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: Better writing in python

2007-10-24 Thread Neil Cerutti
operator import truth from collections import defaultdict result = defaultdict(list) for k, g in groupby(sorted(cls.dArguments, key=truth), truth): result[k].extend(g) I like your initial attempt better. P.S. I didn't realize until working out this example that extend could consume an ite

Re: about functions question

2007-10-25 Thread Neil Cerutti
t. > if __name__ == '__main__': >print SOME_CONST >if not do_something(): > try_somethin_else() That idiom is useful in modules for launching tests or examples that should not be run when the module is imported. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: about functions question

2007-10-26 Thread Neil Cerutti
On 2007-10-26, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > Neil Cerutti a écrit : >> On 2007-10-25, Bruno Desthuilliers >> <[EMAIL PROTECTED]> wrote: >>> The canonical case for small scripts is to have first all >>> functions and globals defined

Re: Proposal: Decimal literals in Python.

2007-10-27 Thread Neil Cerutti
ent to os.chmod. >> >> You mean instead of >> >> import this >> os.chmod(filename, os.R_OK | os.W_OK | os.X_OK) >> >> which explicitly (rather than implicitly) spells it out? > > And the equivalent of ``os.chmod(filename, 0777)`` looks like

Re: A Python 3000 Question

2007-10-30 Thread Neil Cerutti
1:08) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import timeit >>> timeit.Timer('len(seq)', 'seq = range(100)').timeit() 0.20332271187463391 >>&g

Re: setting variables in outer functions

2007-10-30 Thread Neil Cerutti
x return balance, post_transaction fred_balance, fred_post = account(1500) joe_balance, joe_post = account(12) fred_post(20) joe_post(-10) fred_balance() 1520 joe_balance() 2 Python classes will of course nearly always win, though the idiom looks like it might be faster (I don't have Python 3000 to try it out). -- Neil Cerutti It isn't pollution that is hurting the environment; it's the impurities in our air and water that are doing it. --Dan Quayle -- http://mail.python.org/mailman/listinfo/python-list

Re: A Python 3000 Question

2007-10-31 Thread Neil Cerutti
On 2007-10-30, Jean-Paul Calderone <[EMAIL PROTECTED]> wrote: > On Tue, 30 Oct 2007 15:25:54 GMT, Neil Cerutti <[EMAIL PROTECTED]> wrote: >>On 2007-10-30, Eduardo O. Padoan <[EMAIL PROTECTED]> wrote: >>> This is a FAQ: >>> http://effbot.org/pyfaq/why-d

Re: A Python 3000 Question

2007-10-31 Thread Neil Cerutti
On 2007-10-30, George Sakkis <[EMAIL PROTECTED]> wrote: > On Oct 30, 11:25 am, Neil Cerutti <[EMAIL PROTECTED]> wrote: >> On 2007-10-30, Eduardo O. Padoan <[EMAIL PROTECTED]> wrote: >> >> > This is a FAQ: >> >http://effbot.org/pyfaq/why-does-pyth

Re: A Python 3000 Question

2007-10-31 Thread Neil Cerutti
On 2007-10-31, George Sakkis <[EMAIL PROTECTED]> wrote: > On Oct 31, 8:44 am, Neil Cerutti <[EMAIL PROTECTED]> wrote: >> On 2007-10-30, George Sakkis <[EMAIL PROTECTED]> wrote: >> >> >> >> > On Oct 30, 11:25 am, Neil Cerutti <[EMAIL PROTECTE

Re: A Python 3000 Question

2007-10-31 Thread Neil Cerutti
hink tuples didn't used to have any > methods at all). Thanks for the interesting note. I didn't know that tuples originally had no methods. That made len mandatory, I suppose. -- Neil Cerutti The Pastor would appreciate it if the ladies of the congregation would lend him their electr

Re: setting variables in outer functions

2007-11-01 Thread Neil Cerutti
here? > > I was simply responding to a subthread that only evaluated > closures as a SICP-style OOP implementation mechanism. That is > missing the point of closures. It really depends on how wide your definition of primitive object system is. Can you come up with a use-case for nonloc

Re: How can I have one element list or tuple?

2007-11-01 Thread Neil Cerutti
On 2007-11-01, nico <[EMAIL PROTECTED]> wrote: > The following example returns a string type, but I need a tuple... >>>> var = ("Hello") >>>> print type(var) > > > I need that for a method parameter. var = "hello", -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: Syntax coloring in Python interpreter

2007-11-01 Thread Neil Cerutti
x on the fly. Is there >> anything similar for Python? >> > > I believe IPython can do this: > > http://ipython.scipy.org/moin/ IPython's syntax coloring doesn't work with Windows 2000 and up, since (last I checked) it relies on a readline.py file, which relies

Re: Syntax coloring in Python interpreter

2007-11-01 Thread Neil Cerutti
On 2007-11-01, Chris Mellon <[EMAIL PROTECTED]> wrote: > On Nov 1, 2007 3:01 PM, Neil Cerutti <[EMAIL PROTECTED]> wrote: >> On 2007-11-01, Lee Capps <[EMAIL PROTECTED]> wrote: >> > >> > On Nov 1, 2007, at 1:45 PM, braver wrote: >> >>

Re: python newbie

2007-11-02 Thread Neil Cerutti
odule is an object, would > not every function be a method of that module and every variable be a > field of that module? You are almost correct. Every identifier/name in Python is conceptually an attribute of an object. But identifiers in Python are not typed. It is the objects that t

Re: Syntax coloring in Python interpreter

2007-11-02 Thread Neil Cerutti
On 2007-11-02, Tim Golden <[EMAIL PROTECTED]> wrote: > Neil Cerutti wrote: >> On 2007-11-01, Chris Mellon <[EMAIL PROTECTED]> wrote: >>> On Nov 1, 2007 3:01 PM, Neil Cerutti <[EMAIL PROTECTED]> wrote: >>>> On 2007-11-01, Lee Capps <[EMAIL PROTECTE

An iterator with look-ahead

2007-01-10 Thread Neil Cerutti
return self.look def next(self): item = self.look try: self.look = self.iter.next() except StopIteration: if self.exhausted: raise else: self.exhausted = True return item -- Neil Cerutti We'v

Working with named groups in re module

2007-01-10 Thread Neil Cerutti
re.compile('(?Px+)|(?Pa+)') m = r.match('aaxaxx') if m: for k in r.groupindex: if m.group(k): # Find the token type. token = (k, m.group()) I wish I could do something obvious instead, like m.name(). -- Neil Cerutti After finding no qualified

Re: An iterator with look-ahead

2007-01-10 Thread Neil Cerutti
ple-parser-1 Thank you. Much better. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: Working with named groups in re module

2007-01-10 Thread Neil Cerutti
On 2007-01-10, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Neil Cerutti wrote: >> A found some clues on lexing using the re module in Python in >> an article by Martin L÷wis. > >> Here, each alternative in the regular expression defines a >> named group. Scan

Re: Need startup suggestions for writing a MSA viewer GUI in python

2007-01-10 Thread Neil Cerutti
with an impressive plethora of demos. -- Neil Cerutti The concert held in Fellowship Hall was a great success. Special thanks are due to the minister's daughter, who labored the whole evening at the piano, which as usual fell upon her. --Church Bulletin Blooper -- http://mail.python.org/mailman/listinfo/python-list

Re: An iterator with look-ahead

2007-01-10 Thread Neil Cerutti
On 2007-01-10, Steven Bethard <[EMAIL PROTECTED]> wrote: > 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/

Re: Print message with Colors

2007-01-11 Thread Neil Cerutti
Python on those platforms, even if you use the crummy old COMMAND.COM. I believe it's because Python on those platforms in a console application, which on NT, 2000 and XP doesn't support ANSI escape sequences. It makes IPython's appearance less cool. :-( Try http://effbot.org/download

Re: Type casting a base class to a derived one?

2007-01-11 Thread Neil Cerutti
t;def __init__ (self, base_object): > # ( copy all attributes ) > ... > > This looks expensive. Moreover __init__ () may not be available > if it needs to to something else. > > Thanks for suggestions How does it make sense to cast a base to a derived in your ap

Re: __init__ vs __new__

2007-01-11 Thread Neil Cerutti
e): if alist is None: alist = [] for objekt in alist: _validateParameter(objekt) list.__init__(self, alist) You will no longer need to call append. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: What happened to SPE?

2007-01-11 Thread Neil Cerutti
it here: http://sourceforge.net/projects/spe/ -- Neil Cerutti We don't necessarily discriminate. We simply exclude certain types of people. --Colonel Gerald Wellman -- http://mail.python.org/mailman/listinfo/python-list

Re: Fixed keys() mapping

2007-01-11 Thread Neil Cerutti
tance). Is this a valid use > case for type-changing behavior or is there a better, more > "mainstream" OO design pattern for this ? I can post the > relevant code if necessary. Since the type gets changed before __init__ finishes, I don't see any problem with it. It sounds cool. -- Neil Cerutti It isn't pollution that is hurting the environment; it's the impurities in our air and water that are doing it. --Dan Quayle -- http://mail.python.org/mailman/listinfo/python-list

Re: passing a variable to an external program

2007-01-11 Thread Neil Cerutti
> os.system('cscript /nologo ' + pathname + '\test.vbs') Use / instead of \, or \\ instead of \. -- Neil Cerutti Ushers will eat latecomers. --Church Bulletin Blooper -- http://mail.python.org/mailman/listinfo/python-list

Re: Matching Directory Names and Grouping Them

2007-01-12 Thread Neil Cerutti
orted(g)) print if __name__ == "__main__": import doctest doctest.testmod() I really wanted nested join calls for the output, to suppress that trailing blank line, but I kept getting confused and couldn't sort it out. It would better to use the os.path module, but I couldn't find the function in there lets me pull out path tails. I didn't filter out stuff that didn't match the date path convention you used. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: Boilerplate in rich comparison methods

2007-01-13 Thread Neil Cerutti
thIdentity(1) >>>> timeit.Timer("x = x", "from __main__ import x,y").repeat() > [0.20761799812316895, 0.16907095909118652, 0.16420602798461914] >>>> timeit.Timer("x = y", "from __main__ import x,y").repeat() > [0.2090909481048584, 0.1968839168548584, 0.16479206085205078] > > Anyone want to argue that this is a worthwhile optimization? :) Perhaps. But first test it with "==". -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: Anyone has a nice "view_var" procedure ?

2007-01-16 Thread Neil Cerutti
the names of its class's attributes, and recursively of the attributes of its class's base classes. The resulting list is sorted alphabetically. [...] It's unclear to me what attributes an object could have that aren't included in the above list. Note: Because dir()

Re: whats wrong with my reg expression ?

2007-01-16 Thread Neil Cerutti
; v=v.replace('""','"') > return(l) > > v=rex.match(v).group('value') > AttributeError: 'NoneType' object has no attribute 'group' When the regex doesn't match, match returns None. -- Neil Cerutt

Re: assert versus print [was Re: The curious behavior of integer objects]

2007-01-16 Thread Neil Cerutti
. How copacetic! It is the null module. ;-) -- Neil Cerutti Facts are stupid things. --Ronald Reagan -- http://mail.python.org/mailman/listinfo/python-list

Re: Regular expressions question

2007-01-16 Thread Neil Cerutti
3 * 4 ok 30 100% 100% Outgoing" >>> import re >>> r = re.search('\*\s+(\d+)', g) >>> r.group() '* 4' >>> r.group(1) '4' -- Neil Cerutti We're not afraid of challenges. It's like we always say: If you want to go out

Re: Regular expressions question

2007-01-16 Thread Neil Cerutti
On 2007-01-16, Victor Polukcht <[EMAIL PROTECTED]> wrote: > On Jan 16, 5:40 pm, Neil Cerutti <[EMAIL PROTECTED]> wrote: >> On 2007-01-16, Victor Polukcht <[EMAIL PROTECTED]> wrote: >> >> > Actually, i'm trying to get the values of first field (Globa

Re: A note on heapq module

2007-01-17 Thread Neil Cerutti
nt Python's deque is, but it's possible a deque would provide a faster heap than a contiguous array. C++'s std::deque is the default implementation of C++'s std::priority_queue for that reason (unless I'm confused again). -- Neil Cerutti We will sell gasoline to anyone in a glass container. --sign at Santa Fe gas station -- http://mail.python.org/mailman/listinfo/python-list

Re: generate tuples from sequence

2007-01-17 Thread Neil Cerutti
on library contains a recipe for this in the itertools recipes in the documentation (5.16.3). def grouper(n, iterable, padvalue=None): "grouper(3, 'abcdefg', 'x') --> ('a','b','c'), ('d','e','f'), ('g&#

Re: A note on heapq module

2007-01-18 Thread Neil Cerutti
On 2007-01-18, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Neil Cerutti: >> One more idea, cribbed from the linked list thread elsewhere: >> it might be nice if your Heap could optionally use an >> underlying collections.deque instead of a list. I don't know &g

Re: One more regular expressions question

2007-01-18 Thread Neil Cerutti
ncorrect, but can't understand where > exactly. Break it up using verbose notation to help yourself. Also, use more helpful names. With names like var1 and var2 you might as well not used named groups. r = re.compile(r"""(?x) (?P [^(]+ ) (?P \d+ ) \) \s+ (

Re: A note on heapq module

2007-01-18 Thread Neil Cerutti
On 2007-01-18, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Neil Cerutti: >> One more idea, cribbed from the linked list thread elsewhere: >> it might be nice if your Heap could optionally use an >> underlying collections.deque instead of a list. I don't know &g

Re: Traversing the properties of a Class

2007-01-18 Thread Neil Cerutti
print attr -- Neil Cerutti -- Posted via a free Usenet account from http://www.teranews.com -- http://mail.python.org/mailman/listinfo/python-list

Re: How can I create a linked list in Python?

2007-01-18 Thread Neil Cerutti
) print cons(5, cons(3, nil)) print cons(cons(5, (cons(7, nil))), cons(cons(5, cons(3, nil)), nil)) print nil print llist([1, ['a', 'b', 'c'], 2, 3]) There's lots more more stuff to add, but the fun wore out. I'd like if it the cdr of nil could actually be nil,

Re: OT Annoying Habits (Was: when format strings attack)

2007-01-20 Thread Neil Cerutti
k with stupid top-posting, too. It's been an interesting journey, from some unix-based terminal email, to Lotus Notes (ARRGH!), then a happy time using IMAP, and now back to (ARRGH!). -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: Are there sprintf in Python???

2007-01-23 Thread Neil Cerutti
easily. def sprintf(format, *objects): return format % tuple(objects) Since strings are immutable it's not convenient to provide a pass-out parameter as in C. If you want to check for errors you'll have to catch the exceptions, rather than inspect the return value as you can in C. --

Re: Best way to document Python code...

2007-01-23 Thread Neil Cerutti
e docs installed, it functions somewhat like perldoc. Type help() at the interactive prompt to get started. -- Neil Cerutti Will the last person to leave please see that the perpetual light is extinguished --sign at New England church -- Posted via a free Usenet account from http://www.teranews.com -- http://mail.python.org/mailman/listinfo/python-list

Re: match nested parenthesis

2007-01-23 Thread Neil Cerutti
xcellent support on this group at the moment. Or just compose your own little function by hand. A stack-based solution (implemented using a list as a stack) should be easy enough. -- Neil Cerutti And now the sequence of events in no particular order. --Dan Rather -- Posted via a free Usenet acc

Re: Thoughts on using isinstance

2007-01-24 Thread Neil Cerutti
ngs that contains every name you'd like to accept. Names probably aren't worth validating, although you might reasonably reject a few things, like the empty string. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: Re-thinking my if-thens - a software engineering question

2007-01-24 Thread Neil Cerutti
write it better. In other words, writing the code organizes my thoughts. I usually have to fully understand something, even to get a kludgey solution to work. The Kludgey solution informs the design of something better. 2. a) Got to 1. a) In the case above, I've tried to

Re: Static variables

2007-01-24 Thread Neil Cerutti
er will also work. >>> def foo(x, s=[0]): ... print s[0], x ... s[0] += 1 ... >>> for i in range(5): ... foo("!") ... 0 ! 1 ! 2 ! 3 ! 4 ! The latter is not as nice, since your "static" variable is easy to clobber by passing something into the function. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: Please have a look at this class

2007-01-25 Thread Neil Cerutti
ce become actual attributes per se. A nice use for this class might be to pass large mutable objects to a functions as if it were immutable without needing to copy them. Unfortunately it only works for one level of call. I think. -- Neil Cerutti -- Posted via a free Usenet account from http://www.teranews.com -- http://mail.python.org/mailman/listinfo/python-list

Re: python+ncurses: I can't display accents

2007-01-26 Thread Neil Cerutti
y terminal (rxvt-unicode) is able to > display those chars. What have you tried? -- Neil Cerutti -- Posted via a free Usenet account from http://www.teranews.com -- http://mail.python.org/mailman/listinfo/python-list

Re: python+ncurses: I can't display accents

2007-01-26 Thread Neil Cerutti
)) I don't really expect it to work, but if anything will, that is it. Curses supports only ASCII and a some special symbol codes defined by curses. > I have > > #!/usr/local/bin/python > #coding: iso8859-15 Be sure to write your non-ASCII strings as unicode literals, and then encod

Re: Convert String to list of chars

2007-01-26 Thread Neil Cerutti
On 2007-01-27, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > How can I convert a string to a char list? > for example > > "hello" --> ['h','e','l','l','o'] > > I have been searching but I can't find my answers list("hello") -- http://mail.python.org/mailman/listinfo/python-list

Re: python+ncurses: I can't display accents

2007-01-26 Thread Neil Cerutti
On 2007-01-27, Thomas Dickey <[EMAIL PROTECTED]> wrote: > Neil Cerutti <[EMAIL PROTECTED]> wrote: >> I don't really expect it to work, but if anything will, that >> is it. Curses supports only ASCII and a some special symbol >> codes defined by curses. >

<    4   5   6   7   8   9   10   11   12   >