Re: Using StopIteration

2006-05-08 Thread Steve R. Hastings
for fn in filenames: for line in open(fn): if line[0] in digits: ProcessLine(line) break -- Steve R. Hastings"Vita est" [EMAIL PROTECTED]http://www.blarg.net/~steveha -- http://mail.python.org/mailman/listinfo/python-list

Re: A critic of Guido's blog on Python's lambda

2006-05-05 Thread Steve R. Hastings
I won't say more, since Alex Martelli already pointed out that Google is doing big things with Python and it seems to scale well for them. -- Steve R. Hastings"Vita est" [EMAIL PROTECTED]http://www.blarg.net/~steveha -- http://mail.python.org/mailman/listinfo/python-list

Re: scope of variables

2006-05-03 Thread Steve R. Hastings
43:58) [GCC 4.0.3 (Ubuntu 4.0.3-1ubuntu5)] on linux2 Type "help", "copyright", "credits" or "license" for more information. As you can see, I'm running Python 2.4.3. Make sure you aren't running an old version of Python, and that cod

Re: simultaneous assignment

2006-05-03 Thread Steve R. Hastings
On Wed, 03 May 2006 17:51:03 +, Edward Elliott wrote: > Steve R. Hastings wrote: >> You could also use a function that counts all different values in a list, >> reducing the list to a dictionary whose keys are the unique values from >> the list. > > Wouldn'

Re: NewB question on text manipulation

2006-05-03 Thread Steve R. Hastings
ip() xc = m.group(3).replace(s_space, s_empty) s = pat_sc.sub(s_empty, s, 1) m = pat_lt.search(s) if m: lt = m.group(1) lt = lt.strip() s = pat_lt_remove.sub(s_empty, s, 1) tup = (before, title, xc, lt) lst.append(tup) for before, title, xc, lt in lst:

Re: what is the 'host' for SMTP?

2006-05-03 Thread Steve R. Hastings
he server, part of what the conversation includes will be to whom you wish to send the email. Please Google for information on SMTP. You can also start here: http://en.wikipedia.org/wiki/SMTP -- Steve R. Hastings"Vita est" [EMAIL PROTECTED]http://www.blarg.net/~steveha -- htt

Re: request help with Pipe class in iterwrap.py

2006-05-03 Thread Steve R. Hastings
hain()". newlist = Chain(mylist, sort, uniq, list) I did kind of want a way to make a "reusable pipe". If you come up with a useful chain, it might be nice if you could use it again with convenient syntax. Maybe like so: sort_u = [sort, uniq, list] newlist = Chain(mylist, sort_u) Thank you very much for making a helpful suggestion! -- Steve R. Hastings"Vita est" [EMAIL PROTECTED]http://www.blarg.net/~steveha -- http://mail.python.org/mailman/listinfo/python-list

Re: NewB question on text manipulation

2006-05-02 Thread Steve R. Hastings
g left over is assumed to be the LT. Now, we have all the data; it's easy enough to rearrange it. We can convert the XC string into a list of page ranges just by calling .split(";"), which will split on semicolons. Loop over this list, printing each time, and there you go. I'

Re: simultaneous assignment

2006-05-02 Thread Steve R. Hastings
mp.lang.python; I called my version of it tally(). d = tally(bool(x) for x in seq) print d[True] # prints how many true values in seq print d[False] # prints how many false values in seq tally() is in my iterwrap.py module, which you can get here: http://home.blarg.net/~steveha/iterwrap.tar.gz

Re: what is the 'host' for SMTP?

2006-05-02 Thread Steve R. Hastings
love to find them. If you are using email, then as I said above, your email client should have an SMTP server filled in already, and you are already using it every time you send email. So I suggest you use that. -- Steve R. Hastings"Vita est" [EMAIL PROTECTED]http://www.blarg.net/~steveha -- http://mail.python.org/mailman/listinfo/python-list

Re: simultaneous assignment

2006-05-02 Thread Steve R. Hastings
On Tue, 02 May 2006 12:58:14 -0700, Roger Miller wrote: > Steve R. Hastings wrote: > >> a = 0 >> b = 0 >> a is b # always true > > Is this guaranteed by the Python specification, or is it an artifact of > the current implementation? I believe it's an

Re: simultaneous assignment

2006-05-02 Thread Steve R. Hastings
On Tue, 02 May 2006 21:20:48 +0200, Boris Borcic wrote: > Steve R. Hastings wrote: >> So, don't test to see if something is equal to True or False: >> >> if 0 == False: >> pass # never executed; False and 0 do not directly compare > > of course they

Re: simultaneous assignment

2006-05-02 Thread Steve R. Hastings
mostly with generator expressions: any(v for v in seq if v) # true if any v evaluates true all(v for v in seq if v) # true if *all* v evalute true Or a better example: any(is_green(x) for x in lst) # true if any value in list is green -- Steve R. Hastings"Vita est" [EMAIL PROTECTED]http://www.blarg.net/~steveha -- http://mail.python.org/mailman/listinfo/python-list

Re: simultaneous assignment

2006-05-02 Thread Steve R. Hastings
d it: if bool(0) == False: pass # always executed Do this: if not 0: pass # always executed if 1: pass # always executed To convert a random value into a boolean value, you could use either "bool()" or you could use "not not": a = not not 0 b = bool(0) &

request help with Pipe class in iterwrap.py

2006-05-01 Thread Steve R. Hastings
e a special method __set__ called when an expression is being assigned somewhere; that would make this trivial. What is the friendliest and most Pythonic way to write a Pipe class for iterwrap? P.S. I have experimented with overloading the | operator to allow this syntax: newlist = Pipe(mylist)

Re: efficiency of range() and xrange() in for loops

2006-04-06 Thread Steve R. Hastings
Nope, out of the question for Python 2.x. Note that the the builtin > range could be rebound, or a global range could appear in the module, > at run time. Ah! Of course. Thank you very much for explaining this. -- Steve R. Hastings"Vita est" [EMAIL PROTECTED]http://www.blarg.net/~steveha -- http://mail.python.org/mailman/listinfo/python-list

Re: efficiency of range() and xrange() in for loops

2006-04-05 Thread Steve R. Hastings
On Thu, 06 Apr 2006 02:33:16 +0200, Azolex wrote: > Don't. It's quite funny, thanks. I guess I should laugh. :-/ When you read my original articles, did *you* think I was proposing that range() be changed to always return an iterator? I thought what I wrote was pretty clear..

Re: efficiency of range() and xrange() in for loops

2006-04-05 Thread Steve R. Hastings
the Holy Grail_. I was trying to be funny, not sarcastic, bitter, etc. Thank you for your patience and I am done with this thread, unless I have written something unclear in *this* post and I have to post another post to clarify it as well. :-( -- Steve R. Hastings"Vita est" [EMAIL

Re: efficiency of range() and xrange() in for loops

2006-04-05 Thread Steve R. Hastings
d not mean to suggest that for would simply call iter() when you use "for i in range". I apologize if my writing was unclear. -- Steve R. Hastings"Vita est" [EMAIL PROTECTED]http://www.blarg.net/~steveha -- http://mail.python.org/mailman/listinfo/python-list

Re: efficiency of range() and xrange() in for loops

2006-04-05 Thread Steve R. Hastings
#x27;m mistaken here, but I don't see how this optimization could possibly break anything. range() makes a list, and for consumes it, and the list isn't seen anywhere else. If the Python compiler took this: for i in range(10**6): pass and produced code equivalent to this:

efficiency of range() and xrange() in for loops

2006-04-05 Thread Steve R. Hastings
like this one. I want to be cool too. Where can I find information about how to get a bytecodes listing for my compiled Python? -- Steve R. Hastings"Vita est" [EMAIL PROTECTED]http://www.blarg.net/~steveha -- http://mail.python.org/mailman/listinfo/python-list

Re: any() and all() on empty list?

2006-04-01 Thread Steve R. Hastings
one" instead of "== None". Actually, I do like your version. And I try to always use "is None" instead of "== None"; today I made a mistake about it. Thank you for your comments. Ideally there should be an official tally() function in some module in Pyt

Re: any() and all() on empty list?

2006-04-01 Thread Steve R. Hastings
On Sat, 01 Apr 2006 00:38:08 -0800, Steve R. Hastings wrote: > my proposed truecount() returns a tuple, with the length and > the count of true values. I never liked the name truecount(), and the more I think about it, the less I like the function. It should either solve a very importan

Re: any() and all() on empty list?

2006-04-01 Thread Steve R. Hastings
a tuple with two values, one pass is enough. -- Steve R. Hastings"Vita est" [EMAIL PROTECTED]http://www.blarg.net/~steveha -- http://mail.python.org/mailman/listinfo/python-list

Should any() and all() take a key= argument?

2006-03-31 Thread Steve R. Hastings
e the key= option. The need isn't as strong as with .sort(), min(), and max(), but consistency can be a good thing. I'd personally like to see key= anywhere it makes sense. -- Steve R. Hastings"Vita est" [EMAIL PROTECTED]http://www.blarg.net/~steveha -- http://mail.python.org/mailman/listinfo/python-list

Re: any() and all() on empty list?

2006-03-31 Thread Steve R. Hastings
ly write your own truecount() but it would be nice to have something like that as standard. I don't much like the name "truecount" though; I'm open to suggestions for a better name. -- Steve R. Hastings"Vita est" [EMAIL PROTECTED]http://www.blarg.net/~steveha -- http://mail.python.org/mailman/listinfo/python-list

Re: any() and all() on empty list?

2006-03-29 Thread Steve R. Hastings
I'm happy any() and all() will be built in, but I don't know that there is sufficient need for truecount() or anything similar. If you need it, just write it. -- Steve R. Hastings"Vita est" [EMAIL PROTECTED]http://www.blarg.net/~steveha -- http://mail.python.org/mailman/listinfo/python-list

Re: any() and all() on empty list?

2006-03-28 Thread Steve R. Hastings
Thank you very much for explaining this. And so thoroughly! Of course I withdraw all objections. :-) -- Steve R. Hastings"Vita est" [EMAIL PROTECTED]http://www.blarg.net/~steveha -- http://mail.python.org/mailman/listinfo/python-list

any() and all() on empty list?

2006-03-28 Thread Steve R. Hastings
False for x in S: ret_val = True if not x: return False return ret_val Comments? P.S. I searched with Google, and with Google Groups, trying to find anyplace this might have been discussed before. Apologies if this has already been discussed and I missed it somehow.

Re: maximum() efficency

2006-03-27 Thread Steve R. Hastings
if cmp(maxval, v) <= 0: maxval = v return maxval raise TypeError, "seq must be a list or an iterator" -- Steve R. Hastings"Vita est" [EMAIL PROTECTED]http://www.blarg.net/~steveha -- http://mail.python.org/mailman/listinfo/python-list

Re: maximum() efficency

2006-03-26 Thread Steve R. Hastings
t;lst" it is. I would have put the "cmp" argument second, and made it default to the built-in Python "cmp" function if not specified. Oh, well. -- Steve R. Hastings"Vita est" [EMAIL PROTECTED]http://www.blarg.net/~steveha -- http://mail.python.org/mailman/listinfo/python-list

Re: maximum() efficency

2006-03-26 Thread Steve R. Hastings
ur version. P.S. I benchmarked your version; it ran in 22.0 seconds, just a gnat's whisker faster than the iter() version. -- Steve R. Hastings"Vita est" [EMAIL PROTECTED]http://www.blarg.net/~steveha -- http://mail.python.org/mailman/listinfo/python-list

Re: maximum() efficency

2006-03-26 Thread Steve R. Hastings
l This is from Google's "goopy" package. http://goog-goopy.sourceforge.net/ -- Steve R. Hastings"Vita est" [EMAIL PROTECTED]http://www.blarg.net/~steveha -- http://mail.python.org/mailman/listinfo/python-list

Re: maximum() efficency

2006-03-26 Thread Steve R. Hastings
ecause I just wanted a streamlined simple example. I had a nagging feeling that I was missing something simple, and you have put your finger on it. That's perfect! It's simple, it's clear, and it will work on any version of Python. Thanks! -- Steve R. Hastings"Vita est&q

maximum() efficency

2006-03-26 Thread Steve R. Hastings
ter than complex, so I don't think I'd ever actually use it. The clear winner was the iterator version. It was much faster than the others, and in my opinion it is simpler and easier to understand than any of the others. -- Steve R. Hastings"Vita est" [EMAIL PROTECTED]http://www.blarg.net/~steveha -- http://mail.python.org/mailman/listinfo/python-list

Announcing xe and PyFeed, for XML and syndication feeds

2006-03-23 Thread Steve R. Hastings
.py", line 1148, in direct raise ValueError, "value must be a valid timestamp string" ValueError: value must be a valid timestamp string >>> item.pub_date = "01 Jan 2006 08:01:23 GMT" >>> print item.pub_date.text Sun, 01 Jan 2006 00:01:23 -0800 >>> pr

Announcing atomfeed.py, xmlelements.py, and feedutils.py

2006-03-07 Thread Steve R. Hastings
tp://example.org/2003/12/13/atom03";) entry.links.append(link) s = str(xmldoc) if s_example != s: failed_tests += 1 print "test case failed:" print "The generated XML doesn't match the example. diff follows:" print diff(s_example

Re: list assignment using concatenation "*"

2006-02-24 Thread Steve R. Hastings
I suggest you should build your list using a list comprehension: >>>a = [[0]*3 for i in range(3)] >>>a [[0, 0, 0], [0, 0, 0], [0, 0, 0]] >>>a[0][1] = 1 [[0, 1, 0], [0, 0, 0], [0, 0, 0]] -- Steve R. Hastings"Vita est" [EMAIL PROTECTED]ht

Re: list assignment using concatenation "*"

2006-02-24 Thread Steve R. Hastings
s a safe way to create a list of three 0 values. When you have a list that contains three references to the same mutable, and you change the mutable, you get the results you discovered. -- Steve R. Hastings"Vita est" [EMAIL PROTECTED]http://www.blarg.net/~steveha -- http://mail.python.org/mailman/listinfo/python-list

Re: PyAtom, a Python module for creating Atom syndication feeds

2006-02-23 Thread Steve R. Hastings
I have edited PyAtom, and now it should be in better conformance with the PEP 8 guidelines. It is available from the same place as before: http://www.blarg.net/~steveha/pyatom.tar.gz -- Steve R. Hastings"Vita est" [EMAIL PROTECTED]http://www.blarg.net/~steveha

Re: PyAtom, a Python module for creating Atom syndication feeds

2006-02-23 Thread Steve R. Hastings
. Now that it's done I want to share it, but I didn't study PEP 8 very much before I started it. Thank you for the feedback. -- Steve R. Hastings"Vita est" [EMAIL PROTECTED]http://www.blarg.net/~steveha -- http://mail.python.org/mailman/listinfo/python-list

Re: PyAtom, a Python module for creating Atom syndication feeds

2006-02-23 Thread Steve R. Hastings
in the Python core. I said I intend to donate it to PSF. I didn't say they would do anything with it... :-) That's up to them, of course. > Good job :) Thank you. -- Steve R. Hastings"Vita est" [EMAIL PROTECTED]http://www.blarg.net/~steveha -- http://mail.python.org/mailman/listinfo/python-list

PyAtom, a Python module for creating Atom syndication feeds

2006-02-23 Thread Steve R. Hastings
Atom questions and comments: [EMAIL PROTECTED] P.S. Should I publish this to the Cheese Shop? http://cheeseshop.python.org/ -- Steve R. Hastings"Vita est" [EMAIL PROTECTED]http://www.blarg.net/~steveha -- http://mail.python.org/mailman/listinfo/python-list

Re: user-defined operators: a very modest proposal

2005-11-22 Thread Steve R. Hastings
orted to ASCII for porting code to platforms that don't allow Unicode Python files? Yes: just replace the Unicode character with a symbol like __op__, where op is the operator. Actually, that's a better syntax than the one I proposed, too: __+__ # __add__ # this one's alread

Re: user-defined operators: a very modest proposal

2005-11-22 Thread Steve R. Hastings
w.python.org/peps/pep-0225.html Alas, the links to the discussion about this don't work. But it is possible to use the Google Groups archive of comp.lang.python to read some of the discussion. -- Steve R. Hastings"Vita est" [EMAIL PROTECTED]http://www.blarg.net/~steveha -- http://mail.python.org/mailman/listinfo/python-list

user-defined operators: a very modest proposal

2005-11-22 Thread Steve R. Hastings
I actually have made a sensible suggestion, or else people will now explain why this idea isn't good (and I'll learn something). Either way, I look forward to your comments. References: Elementwise/Objectwise Operators http://www.python.org/peps/pep-0225.html Adding A New Outer Product