took", secondsToStr(t2-t1),"seconds"
>
> and get nicely-formatted 0:00:12.345 style output.
>
> (I also posted this to the Python Cookbook.)
>
> -- Paul
Cute... for obfuscated python contests :-) Whenever I needed this, a
simple
"Completed in %d minutes and %.1f seconds" % divmod(end-start, 60)
was more than enough.
George
--
http://mail.python.org/mailman/listinfo/python-list
e classobjs defined in there? Or finding any constant strings in the
> caller's module would also be just fine. Or is there a completely
> different way to do such a thing?
Yes, there is: use an ORM to do the SQL generation for you. Check out
SQLAlchemy, it will buy you much more than what you asked for.
George
--
http://mail.python.org/mailman/listinfo/python-list
decisions you want.
archtool_path= os.getenv('ARCHTOOL_PATH')
archtool_cfg = os.getenv('ARCHTOOL_CFG')
sys.path.insert(0,archtool_path)
import archtool
exec "import archtool.%s as cfg" % archtool_cfg
--
Harry George
PLM Engineering Architecture
--
http://mail.python.org/mailman/listinfo/python-list
bc are the
main players.
http://www.unixodbc.org/
http://www.iodbc.org/
3. For *NIX you need python bindings. This is where mxODBC has
operated (e.g., with iodbc). But there is an OSS effort at:
https://sourceforge.net/projects/pyodb
--
Harry George
PLM Engineering Architecture
--
http://mail.python.org/mailman/listinfo/python-list
PE, stdout=PIPE)
else: # this captures only stdout
pipe = Popen(cmd, shell=False, stderr=PIPE, stdout=PIPE)
# this prints the empty string if not run through the shell
print "stderr:", pipe.stderr.read()
# this prints correctly in both cases
print "stdout:", pipe.stdout.re
On May 15, 5:30 am, Nick Craig-Wood <[EMAIL PROTECTED]> wrote:
> George Sakkis <[EMAIL PROTECTED]> wrote:
> > I'm trying to figure out why Popen captures the stderr of a specific
> > command when it runs through the shell but not without it. IOW:
>
> &
to it. Accepting this PEP would upset lots of people
as it seems, and it's interesting that quite a few are not even native
english speakers.
George
--
http://mail.python.org/mailman/listinfo/python-list
es?
No, and I would refuse to maintain code that did use them*.
George
* Unless I start teaching programming to preschoolers or something.
--
http://mail.python.org/mailman/listinfo/python-list
ew datasets with the same or similar structure but it
soon gets tiring.
I had a similar task recently so I wrote a general and efficient (at
least as far as pure python goes) row transformer that does the
repetitive work. Below are some examples from an Ipython session; let
me know if this might be
s does, lookup for "list
comprehensions". By the way, I hope these were shortened examples and
you're not actually using names such as 'Class' or 'ClassXYZ' in
your actual code...
George
--
http://mail.python.org/mailman/listinfo/python-list
able to do something along the following lines:
def iterprimes(start=1, end=None):
# ...
yield prime
# rpc-related initialization
...
rpc_proxy = some_rpc_lib(iterprimes, start=1e6, end=1e12)
for prime in proxy:
print prime
Is there any module out there that does anything close to this
On May 23, 2:11 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> George Sakkis wrote:
> > I'm looking for any existing packages or ideas on how to implement the
> > equivalent of a generator (in the Python sense, i.e.
> >http://www.python.org/dev
On May 23, 2:11 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> George Sakkis wrote:
> > I'm looking for any existing packages or ideas on how to implement the
> > equivalent of a generator (in the Python sense, i.e.
> >http://www.python.org/dev
On May 23, 3:35 pm, [EMAIL PROTECTED] wrote:
> On May 23, 11:00 am, George Sakkis <[EMAIL PROTECTED]> wrote:
>
>
>
> > I'm looking for any existing packages or ideas on how to implement the
> > equivalent of a generator (in the Python sense,
> > i.e.http:
On May 23, 3:35 pm, [EMAIL PROTECTED] wrote:
> On May 23, 11:00 am, George Sakkis <[EMAIL PROTECTED]> wrote:
>
>
>
> > I'm looking for any existing packages or ideas on how to implement the
> > equivalent of a generator (in the Python sense,
> > i.e.http:
On May 23, 3:35 pm, [EMAIL PROTECTED] wrote:
> On May 23, 11:00 am, George Sakkis <[EMAIL PROTECTED]> wrote:
>
>
>
> > I'm looking for any existing packages or ideas on how to implement the
> > equivalent of a generator (in the Python sense,
> > i.e.http:
On May 23, 3:35 pm, [EMAIL PROTECTED] wrote:
> On May 23, 11:00 am, George Sakkis <[EMAIL PROTECTED]> wrote:
>
>
>
> > I'm looking for any existing packages or ideas on how to implement the
> > equivalent of a generator (in the Python sense,
> > i.e.http:
On May 23, 4:22 pm, Paul McGuire <[EMAIL PROTECTED]> wrote:
> On May 23, 2:58 pm, [EMAIL PROTECTED] wrote:
>
>
>
> > On May 23, 11:00 am, George Sakkis <[EMAIL PROTECTED]> wrote:
>
> > > I'm looking for any existing packages or ideas on how to implem
other way?
>
> W
Yes; check out the following:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/502243
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/205183
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/410698
George
--
http://mail.python.org/mailman/listinfo/python-list
eld next()
except StopIteration:
num_left[0] -= 1
nextfuncs[i] = next = repeat(default).next
yield next()
while True:
t = tuple(iter_next_tuple_values())
if not num_left[0]:
break
yield t
# example
lista = [
ssedRequestError()
class UnprocessedRequestError(RuntimeError):
pass
So far it seems it works as expected but I'd like to know if this is
error-prone and why.
George
--
http://mail.python.org/mailman/listinfo/python-list
On May 29, 9:46 am, [EMAIL PROTECTED] wrote:
> On May 28, 10:46 pm, George Sakkis <[EMAIL PROTECTED]> wrote:
>
>
>
> > I'm reading the docs on sys.exc_info() but I can't tell for sure
> > whether I'm using it safely to get a snapshot of an exceptio
On May 29, 1:21 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Tue, 29 May 2007 13:51:09 -0300, George Sakkis
> <[EMAIL PROTECTED]> escribió:
>
> > The traceback module is handy if you want a text representation of the
> > traceback, not the a
xists...
George
--
http://mail.python.org/mailman/listinfo/python-list
roupby(x, key=lambda div: div%n),
[[] for _ in xrange(n)])
George
--
http://mail.python.org/mailman/listinfo/python-list
t suggested,
> it isn't likely to be implemented. The first step would be to write a
> PEP though.
The time machine did it again: http://www.python.org/dev/peps/pep-3132/.
George
--
http://mail.python.org/mailman/listinfo/python-list
at least planned for Python 3.0?
>
> Thanks for any suggestions,
> Boris Dušek
>
> P.S.: The code should finally look in esence something like this:
>
> if isinstance(f, file):
>pass
> elif isinstance(f, string):
>f = urllib.urlopen(f)
> else:
>raise "...&q
or n in iter(lambda:random.randrange(10), 0):
print n
More generally, iter(callable, sentinel) is just a convenience
function for the following generator:
def iter(callable, sentinel):
while True:
c = callable()
if c == sentinel: break
yield c
George
--
http://mai
flatten_nostr([1, [[[2, 'hello']], (4, u'world')]]))
By the way, it's bad design to couple two distinct tasks: flattening a
(possibly nested) iterable and applying a function to its elements.
Once you have a flatten() function, deeply_mapped is reduced down to
itertools.imap.
HTH,
George
--
http://mail.python.org/mailman/listinfo/python-list
> I know the * operator. However, a 'partial unpack' does not seem to
> > work.
>
> > def g():
> > return (1,2)
>
> > def f(a,b,c):
> > return a+b+c
>
> > f(*g(),10) will return an error.
>
> > Do you know how to get that to work?
>
> > Thanks,
> > cg
>
> As I mentioned, you can access the elements individually using square
> brackets. The following works:
>
> f(g()[0], g()[1], 10)
>
> But it's not clear. Unfortunately, I'm not seeing much else for tuple
> unpacking except the obvious:
>
> a,b=g()
> f(a,b,10)
>
> Mike
Or if you'd rather write it in one line:
f(*(g() + (10,)))
George
--
http://mail.python.org/mailman/listinfo/python-list
table.
>
> Is there a simpler way?
If all you need is sequential access, you can use the next() method of
the file object:
nextline = open(textfile).next
print 'First line is: %r' % nextline()
print 'Second line is: %r' % nextline()
...
For random access, the easiest
- Original Message -
From: "Oleg Broytmann" <[EMAIL PROTECTED]>
To: "Python Announce Mailing List" <[EMAIL PROTECTED]>;
"Python Mailing List"
Sent: Thursday, July 26, 2007 7:23 AM
Subject: SQLObject 0.7.8
> Hello!
>
> I'm pleased to announce the 0.7.8 release of SQLObject.
>
> What is
On Sep 1, 7:13 am, "E.D.G." <[EMAIL PROTECTED]> wrote:
> "E.D.G." <[EMAIL PROTECTED]> wrote in message
>
> news:[EMAIL PROTECTED]
>
> > Important Research Project (Related to computer programming)
>
> > Posted by E.D.G. on August 30, 2007 [EMAIL PROTECTED]
>
> This effort was not successful.
he graph, it seems more accurate to say that Perl is undertaking
> >Python.
>
> Jean-Paul
And to make it even more accurate, "Perl is undertaking Python in
India", since that's where the difference in favor of Python comes
from.
George
--
http://mail.python.org/mailman/listinfo/python-list
with verification of both client and server certificates. If that is
where you are going, let me know what works.
--
Harry George
PLM Engineering Architecture
--
http://mail.python.org/mailman/listinfo/python-list
p-4.7/siplib'
gcc -c -pipe -fPIC -O2 -w -I. -I/usr/local/include/python2.5 -o siplib.o
siplib.c
gcc -c -pipe -fPIC -O2 -w -I. -I/usr/local/include/python2.5 -o qtlib.o qtlib.c
gcc -c -pipe -fPIC -O2 -w -I. -I/usr/local/include/python2.5 -o threads.o
threads.c
gcc -c -pipe -fPIC -O2 -w -I. -I/usr/local/include/python2.5 -o objmap.o
objmap.c
g++ -c -pipe -fPIC -O2 -w -I. -I/usr/local/include/python2.5 -o bool.o bool.cpp
g++ -shared -Wl,--version-script=sip.exp -o sip.so siplib.o qtlib.o threads.o
objmap.o bool.o
gmake[1]: Leaving directory `/usr2/src/qt/sip-4.7/siplib'
--
Harry George
PLM Engineering Architecture
--
http://mail.python.org/mailman/listinfo/python-list
tion. The number
> of elements in the tuple will not always be the same.
>
> T = A,B,C,D,...
>
> Is there a way that I can pass the contents of the tuple to the function
> without explicitly indexing the elements?
Yes:
myfunc(*T)
More details at
http://docs.python.org/tut/
in g)
or a bit less cryptically:
import itertools as it
for chunk,enum_lines in it.groupby(enumerate(open('input.txt')),
lambda (i,line): i//5):
open("output.%d.txt" % chunk, 'w').writelines(line for _,line
in enum_lines)
George
--
http://mail.python.org/mailman/listinfo/python-list
g(m+2)
z3=log(m+3)
z4=log(m+4)
z5=log(m+5)
z6=log(m+6)
z7=log(m+7)
z8=log(m+8)
z9=log(m+9)
return z9
HTH,
George
--
http://mail.python.org/mailman/listinfo/python-list
is in fact undefined.
1. If I onfigure with unicode=ucs2, does all this go away and I get a
working system (efficient or not) on my 64-bit machine?
2. Can you point to a configure (and maybe patch) process which leads
to a clean "make altinstall".
--
Harry George
PLM Engi
emy (I'm back and forth on that. Mostly stay with
straight SQL).
Of course, as long as you write DBI2 compliant code, your app doesn't
much care which DBMS you use. The postgresql payoff is in admin
functionality and scaling and full ACID.
--
Harry George
PLM Engineering Architecture
--
http://mail.python.org/mailman/listinfo/python-list
self.m()
>
> m = B()
> m.am() # prints 'A.m'
> m.bm() # prints 'B.m'
>
> -
>
> P.S. Here's a link to the descriptor how-to:
>http://users.rcn.com/python/download/Descriptor.htm
What would the semantics be if m is decorated as local only in A or
only in B ?
George
--
http://mail.python.org/mailman/listinfo/python-list
I have a pure python program (no C extensions) that occasionally core
dumps in a non-reproducible way. The program is started by a (non-
python) cgi script when a form is submitted. It involves running a
bunch of other programs through subprocess in multiple threads and
writing its output in severa
table values from defaults. The fact that an object is
mutable doesn't mean that the function will try to mutate it:
def paintWall(ind, colormap={1:'red', 2:'blue', 5:'green'}):
print "Let's paint the wall %s" % colormap[ind]
George
--
http://mail.python.org/mailman/listinfo/python-list
be the worst of both worlds. The main alternative to the
> present behavior is re-computing the default value every time the
> function is entered.
One can do this is today's Python if he's so inclined, albeit with a
more verbose syntax:
http://aspn.activestate.com/ASP
ial problem in general, but in my case every thread is
exclusively responsible for the subprocesses it forks; no subprocess
is inherited from the main thread or is shared in among the worker
threads.
George
--
http://mail.python.org/mailman/listinfo/python-list
;modified_by", and every
write operation on it would automatically record the time and the id
of the user who did the addition or change (I'm not sure how to deal
with deletions let's leave this for now). Has anyone done something
like that or knows where to start from ?
George
--
http://mail.python.org/mailman/listinfo/python-list
This information
is part of the context (e.g. an http request), not stored persistently
somewhere. It should be doable at the framework/orm level but I'm
rather green on Turbogears/SQLAlchemy.
George
--
http://mail.python.org/mailman/listinfo/python-list
ne reverse:
>
> first_word = line.split(' ', 1)[0]
> last_word = line.rsplit(' ', 1][-1]
> db[first_word] = last_word
I'd guess the following is in theory faster, though it might not make
a measurable difference:
first_word = line[:line.i
RAM boxes and
setting a big buffer (1GB or more) reduces the wall time by 30 to 50%
compared to the default value. BerkeleyDB should have a buffering
option too, make sure you use it and don't synchronize on every line.
Best,
George
--
http://mail.python.org/mailman/listinfo/python-list
o python script share a common object?
>
For the CPU to use the object, it needs to be in RAM. But it is
possible to save the RAM image onto disk, and then bring it back
later. The common approach is called "pickling", though there are
several variants on this:
http://docs.pyth
and numarray.
> scipy
> > provides a bunch of computational routines (linear algebra, optimization,
> > statistics, signal processing, etc.) built on top of numpy.
>
> Thank you.
>
>
Also see gsl and its python binding.
http://www.gnu.org/software/gsl/
http://
ably impossible.
>
>Perhaps somebody could ask the chinese government to put him in jail
>for "hurting international society" :)
That's going to be tough because, according to his web page, he's
living in a Honda Civic somewhere in Illinois, USA.
http://xahlee.org/PageTw
SomeFunction(self, someParameter):
>self.someParameter = someParameter
If one *really* wants this, it is doable in python too:
http://www.voidspace.org.uk/python/weblog/arch_d7_2006_12_16.shtml#e583
George
--
http://mail.python.org/mailman/listinfo/python-list
act "a list of strings from a text", you want to extract specific
elements from an XML data source. There are several standard and non
standard python packages for XML processing, look for them online.
Here's how to do it using the (3rd party) BeautyfulSoup module:
>>> from BeautifulSoup import BeautifulStoneSoup
>>> BeautifulStoneSoup(s).findAll('organisatie')
[
28996
,
28997
]
HTH,
George
--
http://mail.python.org/mailman/listinfo/python-list
ained module in a single file.
"Installing" it can be as simple as having it in the same directory of
your module that imports it. Given that you can do in 2 lines what
took you around 15 with lxml, I wouldn't think it twice.
George
--
http://mail.python.org/mailman/listinfo/python-list
e(count))
I am puzzled by the parentheses in the last line. Somehow they make
frange to be a generator:
>> print type(frange(1.0, increment=0.5))
But I always thought that generators need a keyword "yield". What is
going on here?
George
--
http://mail.python.org/mailman/listinfo/python-list
table.__getitem__, line))
def scramble_dict_imap(line):
return ''.join(imap(scramble_table.__getitem__, line))
if __name__=='__main__':
funcs = [scramble, scramble_listcomp, scramble_gencomp,
scramble_map, scramble_imap,
scramble_dict, scramble_dict_map, scramble_dict_imap]
s = 'abcdefghijklmnopqrstuvwxyz' * 100
assert len(set(f(s) for f in funcs)) == 1
from timeit import Timer
setup = "import __main__; line = %r" % s
for name in (f.__name__ for f in funcs):
timer = Timer("__main__.%s(line)" % name, setup)
print '%s:\t%.3f' % (name, min(timer.repeat(3,1000)))
George
--
http://mail.python.org/mailman/listinfo/python-list
for learning purposes, perhaps you should
be thinking it the other way around: how fast is fast enough ?
Optimizing just for the sake of optimization, without a specific
performance goal in mind, is not the most productive way to do things
(again, leaving learning motivations aside).
George
--
h
of "ok, apparently bit fiddling is important for some classes of
problems but so are regular expressions. Are bit operations so
frequent and/or important to grant them around a dozen of operators
while there are none for regexps ?"
George
--
http://mail.python.org/mailman/listinfo/python-list
the only difference the flag
makes is the keyword argument, you can either factor the common part
out in another function called by foo or (if performance is crucial)
create foo dynamically through exec:
def factory(flag):
kw = flag and 'spam' or 'ham'
exec '''def foo(obj, arg):
return obj.method(%s=arg)''' % kw
return foo
George
--
http://mail.python.org/mailman/listinfo/python-list
how many elements
there are actually present:
print string.split(line, "\t")
By the way, most functions of the string module are deprecated in
favor of string methods; the above is better written as
print line.split("\t")
HTH,
George
--
http://mail.python.org/mailman/listinfo/python-list
RTFM! and the like.
Which shows once again that you're trying to break the world record of
being wrong in as many sentences as possible:
http://mail.python.org/mailman/listinfo/tutor
You would do yourself (and others) a favor by migrating there for a
few weeks or months.
George
--
can be "adopted" by someone else.
>
> Python doesn't have any of this. And that's far more of a problem
> than Python 3.x.
Does Perl support extension modules, and if so, are they so prevalent
as in Python ? Either case, bringing up CPAN is moot in this case;
nothing can force an external open source contributor to maintain or
provide binaries for his packages. How is this a problem of the
*language* ?
George
--
http://mail.python.org/mailman/listinfo/python-list
t can generate
tuples *lazily*.
> Sometime it maybe a waste to generate all possible combinations of i,j first.
It doesn't; read about generator expressions at
http://www.python.org/dev/peps/pep-0289/
George
--
http://mail.python.org/mailman/listinfo/python-list
n soup.findAll('a'):
for attr in 'href','name':
val = a.get(attr)
if val:
a[attr] = val.replace(' ','_')
print soup
George
--
http://mail.python.org/mailman/listinfo/python-list
to Python" has been translated in Chinese:
http://www.woodpecker.org.cn/diveintopython/
Hope it helps,
George
--
http://mail.python.org/mailman/listinfo/python-list
On Sep 30, 2:54 pm, Ricardo Aráoz <[EMAIL PROTECTED]> wrote:
>
> Errhhh. guys.. I think .kr means Korea so he would speak
> Korean, not Chinese
In this case, http://kr.diveintopython.org/html/index.htm might be
more useful ;-)
George
--
http://mail.python.org/m
was it rejected? and for what?
Is internet down today ?
http://pypi.python.org/pypi/clnum/1.2
http://www.python.org/dev/peps/pep-0239/
George
--
http://mail.python.org/mailman/listinfo/python-list
beer" nearly always come with a catch or implied
>obligation?
It means you have to bring the chips.
George
--
for email reply remove "/" from address
--
http://mail.python.org/mailman/listinfo/python-list
ked. Redo from start.
Our [US] legal system is fucked ... more so with respect to patents,
but copyrights aren't far behind. The US Congress just revisited
patent law to make it less of a land grab - we'll have to wait and see
how the USPTO interprets the new rules - but copyright law has
sum:
dsum[key] = value
else:
dsum[key] += value
return dsum
Surprisingly (?), this turns out to be faster than using dict.get(key,
0) instead of the explicit if/else.
George
--
http://mail.python.org/mailman/listinfo/python-list
for this man to retire so they could write and speak the
way they wanted rather than having to be "correct".
Dictionaries used to be the arbiters of the language - any word or
meaning of a word not found in the dictionary was considered a
colloquial (slang) use. Since the 1980's, an entry in the dictionary
has become little more than evidence of popularity as the major
dictionaries (OED, Webster, Cambridge, etc.) will now consider any
word they can find used in print.
George
--
for email reply remove "/" from address
--
http://mail.python.org/mailman/listinfo/python-list
On Oct 3, 12:59 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> hii
> ý think you know spam page is the most pest for net user.
...closely followed in the second position by incoherent misspelled
posts in silly IM-speak.
--
http://mail.python.org/mailman/listinfo/python-list
oo(object):
# XXX this is a class instance, shared by all Foo instances;
# XXX probably not what you intended
params = [ ]
def __init__(self, *args):
# uncomment the following line for instance-specific params
# self.params = []
for arg in args:
if not isinstance(arg, Bar):
# let the Bar constructor to do typechecking or whatnot
arg = Bar(arg)
self.params.add(arg)
HTH,
George
--
http://mail.python.org/mailman/listinfo/python-list
On Oct 3, 2:27 pm, George Sakkis <[EMAIL PROTECTED]> wrote:
> On Oct 3, 1:04 pm, Adam Lanier <[EMAIL PROTECTED]> wrote:
>
>
>
> > Relatively new to python development and I have a general question
> > regarding good class design.
>
> > Say I have
On Wed, 3 Oct 2007 18:20:38 + (UTC), [EMAIL PROTECTED] (Bent C
Dalager) wrote:
>In article <[EMAIL PROTECTED]>,
>George Neuner wrote:
>>On Wed, 3 Oct 2007 09:36:40 + (UTC), [EMAIL PROTECTED] (Bent C
>>Dalager) wrote:
>>
>>>
>>>Only if yo
I read this somewhere, don't remember where.. it goes like:
"He's not really mean... he is just a little prejudiced against
anything that breathes." :-)
George
--
http://mail.python.org/mailman/listinfo/python-list
On Wed, 03 Oct 2007 23:07:32 +0100, [EMAIL PROTECTED] wrote:
>George Neuner wrote:
>> Symbolism over substance has become the mantra
>> of the young.
>
>"Symbolism: The practice of representing things by means of symbols or
>of attributing symbolic meanings or signif
lasses
> so that the above is pretty much all you need to write:
>
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/502237
>
> STeVe
For immutable records, you may also want to check out the named tuples
recipe: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/500261
George
--
http://mail.python.org/mailman/listinfo/python-list
could be very
> complicated. Thanks a lot.
>
> Manu
I haven't needed to use it myself so far, but PyCells (http://
pycells.pdxcb.net/) seems it might fit the bill.
George
--
http://mail.python.org/mailman/listinfo/python-list
I don't have this author's name, nor can
Google find it at the moment. I have a copy though (~2MB) - if you
are interested, contact me by email and I'll send it to you.
Also Google for free CS books. Many older books (including some
classics) that have gone out of print have been released
electronically for free download.
George
--
for email reply remove "/" from address
--
http://mail.python.org/mailman/listinfo/python-list
On Oct 10, 11:08 am, [EMAIL PROTECTED] wrote:
> Why apologize? If someone doesn't like the name given to a piece of
> software by its author(s), screw them. If I find the software useful,
> I'll use it. Even if its called 'bouncingBetty'.
Or 'Beautifu
gt; >>>
>
> -tkc
Or generalized for arbitrary iterables, number of items at a time,
combination function and stopping criterion:
from itertools import islice, takewhile, repeat
def taking(iterable, n, combine=tuple, pred=bool):
iterable = iter(iterable)
return takewhile(pred,
D(C1,C2): pass
items = [A(),B1(),B2(),C1(),C1(),D(),A(),B2()]
print ' * Instances per class'
for c in iter_descendant_classes(A):
print c, list(iter_instances(c))
print ' * Instances per class (after delete)'
del items
for c in iter_descendant_classes(A):
print c, list(iter_instances(c))
HTH,
George
--
http://mail.python.org/mailman/listinfo/python-list
one-shot continuations (exceptions or non-local returns) are the next
most common form used, even in Scheme.
Upward continuations can be stack implemented. On many CPU's, using
the hardware stack (where possible) is faster than using heap
allocated structures. For performance, some Scheme compil
ormat % name)
return type(cls,bases,attrdict)
return meta
class Person(object):
__metaclass__ = PropertyMaker('name', format='__%s__')
def __init__(self, name):
self.name = name
print self.__name__
George
--
http://mail.python.org/mailman/listinfo/python-list
On Oct 11, 7:04 pm, George Sakkis <[EMAIL PROTECTED]> wrote:
> You could take it even further by removing the need to repeat the
> attribute's name twice. Currently this can done only through
> metaclasses but in the future a class decorator would be even
> better:
Reply
lol :) another one on baseball : 90% of the game is physical, the
other half is mental.
GS
[EMAIL PROTECTED]
On Oct 11, 7:32 pm, willshak <[EMAIL PROTECTED]> wrote:
> on 10/11/2007 10:14 PM Audio expert said the following:
>
> > Now I know where NOT to go.
> > TOO crowded for me.
>
> No one goes
tuation.
>
> Thanks
> Tim
Unfortunately __getattr__ is not called for special attributes; I'm
not sure if this is by design or a technical limitation. You have to
manually delegate all special methods (or perhaps write a metaclass
that does this for you).
George
--
http://mail.python.org/mailman/listinfo/python-list
similar to
> improve performance.
"best way you know how from a Software Engineering" != "best way to do
it in less flexible languages that will go unnamed, such as Java"
You seem to conflate these two.
George
--
http://mail.python.org/mailman/listinfo/python-list
ll the server and restart it but obviously
this is not ideal. Is there a way to either prevent or at least
recover automatically the server when it hangs ?
George
--
http://mail.python.org/mailman/listinfo/python-list
On Oct 12, 4:59 pm, brad <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > On Oct 12, 2:55 pm, Florian Lindner <[EMAIL PROTECTED]> wrote:
> >> Hello,
> >> is there a function in the Python stdlib to test if a string is a valid
> >> email address?
>
> here's a Perl re example... I don't know
re I am guessing...
I don't create explicitly any thread in my server code but Pyro itself
is multithreaded. Unfortunately I don't have the resources to start
digging in Pyro's internals..
George
--
http://mail.python.org/mailman/listinfo/python-list
ry with them their execution context.
This allows them to used directly for things like user-space
threading.
George
--
for email reply remove "/" from address
--
http://mail.python.org/mailman/listinfo/python-list
ke 'abc', the remaining portion will be 'bc', then 'c',
> than '', but never [] so you 'll never stop.
>
> Try:
>
> if xs == []:
> return []
> elif xs == '':
> return ''
> else:
> ...
The '
mport timeit
>
> t = timeit.Timer("test3()", "from __main__ import test3, key, data")
> print t.timeit()
> t = timeit.Timer("test1()", "from __main__ import test1, data")
> print t.timeit()
>
> --output:---
> 42.791079998
> 19.012
On Oct 16, 7:35 am, Laurent Pointal <[EMAIL PROTECTED]> >
> How does it compare to the scalar module ?
> (seehttp://russp.us/scalar.htm)
or the Unum module (http://home.scarlet.be/be052320/Unum.html) ?
--
http://mail.python.org/mailman/listinfo/python-list
e
> > time when holding up the invariant when inserting key/values into the
> > dictionary.
>
> Actually, I somehow read the FOR and ITERATOR above as something like this:
>
> entries = sorted(a.items(), key=lambda v: v[1])[:100]
>
> The gist of my statement above is nontheless the same: if you want sorted
> results, you need to sort...
>
> Diez
If you want the top 100 out of 100K, heapq.nlargest is more than an
order of magnitude faster.
George
--
http://mail.python.org/mailman/listinfo/python-list
quot;'
for func in bin2dec, bin2dec_2, bin2dec_3:
name = func.__name__
timer = timeit.Timer('__main__.%s(bin)' % name, setup)
print '%s: %s' % (name, timer.timeit())
### Without Psyco
bin2dec: 17.6126108206
bin2dec_2: 7.57195732977
bin2dec_3: 5.46163297291
### With Psyco
bin2dec: 17.6995679618
bin2dec_2: 8.60846224869
bin2dec_3: 0.16031255369
George
--
http://mail.python.org/mailman/listinfo/python-list
701 - 800 of 1560 matches
Mail list logo