Re: How about adding slice notation to iterators/generators?

2009-10-18 Thread Eloff
On Oct 16, 7:38 pm, Carl Banks wrote: > You would burden everyone who writes a custom iterator to provide a > __getitem__ method just because you're too lazy to type out the word > islice? No, of course not. That would be stupid. Custom iterators are iterators, so they would also get the default

Re: How about adding slice notation to iterators/generators?

2009-10-16 Thread Eloff
On Oct 16, 3:54 am, Terry Reedy wrote: > There is already an obvious standard way to do this. > > it = > next(it) #toss first item > for item in it: >   > That fails if there is no first item. You're taking one corner case and saying there's an easy way to do it, which is more or less true,

How about adding slice notation to iterators/generators?

2009-10-15 Thread Eloff
I was just working with a generator for a tree that I wanted to skip the first result (root node.) And it occurs to me, why do we need to do: import sys from itertools import islice my_iter = islice(my_iter, 1, sys.maxint) When we could simply add slice operations to generators? for x in my_it

Find first matching substring

2009-07-17 Thread Eloff
Almost every time I've had to do parsing of text over the last 5 years I've needed this function: def find_first(s, subs, start=None, end=None): results = [s.find(sub, start, end) for sub in subs] results = [r for r in results if r != -1] if results: return min(results) re

Re: What do _ast Load | Store | Del | AugLoad | AugStore | Param mean?

2008-10-11 Thread Eloff
On Oct 11, 9:22 pm, Benjamin <[EMAIL PROTECTED]> wrote: > Load: > a = 2 > Module(body=[Assign(targets=[Name(id='a', ctx=Store())], > value=Num(n=2))]) > > Store: > print a > Module(body=[Print(dest=None, values=[Name(id='a', ctx=Load())], > nl=True)]) > > Del: > del a > Module(body=[Delete(targets=

What do _ast Load | Store | Del | AugLoad | AugStore | Param mean?

2008-10-11 Thread Eloff
In the _ast module Attribute, Subscript, Name, List, Tuple all have an expr_context associated with them which is defined as: expr_context = Load | Store | Del | AugLoad | AugStore | Param I have no idea what they mean, and what's the difference between them. I'm porting _ast to IronPython and th

Re: Python v PHP for web, and restarting Apache?

2006-11-17 Thread sandra . eloff
On Nov 17, 12:07 pm, "walterbyrd" <[EMAIL PROTECTED]> wrote: > I think I have read somewhere that using Python to develop > web-applications requires some restarting of the Apache server, whereas > PHP does not. It depends what you do. CGI's operate much like PHP. mod_python has auto-reloading (an

Re: Avoiding deadlocks in concurrent programming

2005-06-22 Thread Eloff
Thanks for all of the replies, I'm glad I posted here, you guys have been very helpful. >Obviously, I only know what you've told us about your data, but 20-100 >queries? That doesn't sound right ... RDBMSes are well- >studied and well-understood; they are also extremely powerful when used >to the

Re: Avoiding deadlocks in concurrent programming

2005-06-22 Thread Eloff
Hi Steve, The backup thread only holds the lock long enough to create an in-memory representation of the data. It writes to disk on it's own time after it has released the lock, so this is not an issue. If you're saying what I think you are, then a single lock is actually better for performance t

Re: MySQLdb reconnect

2005-06-22 Thread Eloff
I don't beleive that it does. You can however call ping() on the connection which should attempt an automatic reconnection. See the docs for mysql_ping: http://dev.mysql.com/doc/mysql/en/mysql-ping.html I've never tested that, but I have a need for it also so let me know if it works or not. -Da

Re: Avoiding deadlocks in concurrent programming

2005-06-22 Thread Eloff
Hi Paul, >Do you mean a few records of 20+ MB each, or millions of records of a >few dozen bytes, or what? Well they're objects with lists and dictionaries and data members and other objects inside of them. Some are very large, maybe bigger than 20MB, while others are very numerous and small (a h

Avoiding deadlocks in concurrent programming

2005-06-22 Thread Eloff
This is not really Python specific, but I know Python programmers are among the best in the world. I have a fair understanding of the concepts involved, enough to realize that I would benefit from the experience of others :) I have a shared series of objects in memory that may be > 100MB. Often to

Re: "also" to balance "else" ?

2005-06-13 Thread Eloff
My first reaction was that this is terrible, else clauses on loops are confusing enough. But if I think about it more, I'm warming up to the idea. Also/Else for loops is clear, symmetrical, and would be useful. Reversing the meanign of else will break code, but it's not used that frequently, and i

How to test if an object IS another object?

2005-06-12 Thread dan . eloff
If two objects are of equal value you can compare them with ==. What I want to do is find out if two objects are actually just references to the same object, how can I do this in Python? Thanks -- http://mail.python.org/mailman/listinfo/python-list

Re: How Do I get Know What Attributes/Functions In A Class?

2005-02-23 Thread Dan Eloff
Use the dir() function dir(myClass) returns a list of strings -Dan -- http://mail.python.org/mailman/listinfo/python-list

Re: Dynamically pass a function arguments from a dict

2005-02-23 Thread Dan Eloff
Awesome, wrapping that into a function: def getargs(func): numArgs = func.func_code.co_argcount names = func.func_code.co_varnames return names[:numArgs] short, concise, and it works :) variables declared inside the function body are also in co_varnames but after the arguments only it s

Dynamically pass a function arguments from a dict

2005-02-23 Thread Dan Eloff
You can take a dictionary of key/value pairs and pass it to a function as keyword arguments: def func(foo,bar): print foo, bar args = {'foo':1, 'bar':2} func(**args) will print "1 2" But what if you try passing those arguments to a function def func2(bar,zoo=''): print bar, zoo H