On Apr 4, 1:54 pm, George Sakkis <[EMAIL PROTECTED]> wrote:
> On Apr 4, 11:27 am, Gerardo Herzig <[EMAIL PROTECTED]> wrote:
> > There is an approach in which i can 'sum' after *any* thread finish?
>
> > Could a Queue help me there?
>
> Yes, you can
e. Now I have to check
whether a comment ends in new line and if it does output an extra
tag.. it works but it's a kludge.
George
--
http://mail.python.org/mailman/listinfo/python-list
On Apr 4, 4:38 pm, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> George Sakkis wrote:
> >> If it was a bug it has to violate a functional requirement. I can't
> >> see which one.
>
> > Perhaps it's not a functional requirement but it came up as a real
&g
something entered by user. now i want to call FB. I don't
> want to do an if else because if have way too many methods like
> this...
>
> var = "F" + temp
> var(param1, param2)
Try this:
func = globals()["F" + temp]
func(param1, param2)
HTH,
George
--
http://mail.python.org/mailman/listinfo/python-list
hs of several hundreds nodes, but in case
performance matters, you can take a look at the Python bindings of the
Boost graph library [1].
George
[1] http://www.osl.iu.edu/~dgregor/bgl-python/
--
http://mail.python.org/mailman/listinfo/python-list
ion:
http://docs.python.org/lib/hotshot-example.html
HTH,
George
--
http://mail.python.org/mailman/listinfo/python-list
nce the set is not modified, there's no harm for being mutable; IOW
it's no different than using a frozenset instead. Similarly for dicts,
lists and other mutable containers, as long as they are treated as
read-only.
George
--
http://mail.python.org/mailman/listinfo/python-list
>
> Thank you for any help!
>
> Mario
The problem is that the way you define 'objects', it is an attribute
of the A *class*, not the instance you create. Change the A class to:
class A(object):
def __init__(self):
self.objects = []
and rerun it; it should now work as you intended.
HTH,
George
--
http://mail.python.org/mailman/listinfo/python-list
is the conditional expressions, and I could easily live
without them. 2.4 is still pretty decent, and a major upgrade from
2.3.
George
--
http://mail.python.org/mailman/listinfo/python-list
ing it.
> I wasn't planning on making this discovery today! :)
>
> Bob
If you are running this on a 32-bit architecture, get Psyco [1] and
add at the top of your module:
import psyco; psyco.full()
Using Psyco in this scenatio is up to 70% faster:
python -m timeit "for i in xrange(1000):from3Bytes_bob(s)" \
-s "from bin import *; s=pack('>i',1234567)[1:]"
1000 loops, best of 3: 624 usec per loop
python -m timeit "for i in xrange(1000):from3Bytes_grant(s)" \
-s "from bin import *; s=pack('>i',1234567)[1:]"
1000 loops, best of 3: 838 usec per loop
python -m timeit "for i in xrange(1000):from3Bytes_ross(s)" \
-s "from bin import *; s=pack('>i',1234567)[1:]"
1000 loops, best of 3: 834 usec per loop
George
[1] http://psyco.sourceforge.net/
--
http://mail.python.org/mailman/listinfo/python-list
"\0")[0] >> 8
else:
def from3Bytes(s):
Value = (ord(s[0])<<16) + (ord(s[1])<<8) + ord(s[2])
if Value >= 0x80:
Value -= 0x100
return Value
psyco.bind(from3Bytes)
HTH,
George
--
http://mail.python.org/mailman/listinfo/python-list
rception though.
Look into any of the dozen Python-based template engines that are
typically used for such tasks; they offer many more features than a
way to indent blocks.
George
--
http://mail.python.org/mailman/listinfo/python-list
On Apr 20, 12:34 pm, Eric Wertman <[EMAIL PROTECTED]> wrote:
> > Look into any of the dozen Python-based template engines that are
> > typically used for such tasks; they offer many more features than a
> > way to indent blocks.
>
> > George
>
> I def
On Apr 20, 6:50 pm, Jason Scheirer <[EMAIL PROTECTED]> wrote:
> On Apr 20, 3:25 pm, Zethex <[EMAIL PROTECTED]> wrote:
>
>
>
> > Im a bit new to python. Anyway working on a little project of mine and i
> > have nested lists
>
> > ie
>
> > Answer = [['computer', 'radeon', 'nvidia'], ['motherboard',
On Apr 20, 6:54 pm, Dan Bishop <[EMAIL PROTECTED]> wrote:
> On Apr 20, 11:42 am, Matthew Woodcraft
>
>
>
> <[EMAIL PROTECTED]> wrote:
> > Christian Heimes <[EMAIL PROTECTED]> wrote:
>
> > >> I feel that including some optional means to block code would be a big
> > >> step in getting wider adoptio
in__ import %s; buf=%r' % (func,buf)
).timeit(1))
if __name__ == '__main__':
s = ''.join(struct.pack('>i',v)[1:] for v in
[0,1,-2,500,-500,,-,-94496,98765,
-98765,8388607,-8388607,-8388608,1234567])
assert from3Bytes_ord(s) == from3Bytes_struct(s) ==
from3Bytes_array(s)
print '*** Without Psyco ***'
benchmark()
import psyco; psyco.full()
print '*** With Psyco ***'
benchmark()
George
--
http://mail.python.org/mailman/listinfo/python-list
bine(a,b,c))
>
> ['a', '1', 'a1', 'b', '2', 'b2', 'c', 'c3', 'd4', 'e5']
>
> It has the advantage that it uses the generator protocol, so you can
> pass in any type of sequence. It uses arbitrary arguments to make its
> use closer to that of zip. It is also a generator, so it takes
> advantage of lazy evaluation. Notice that there is never any checking
> of length.
>
> Matt
A similar solution using the itertools module:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/528936
George
--
http://mail.python.org/mailman/listinfo/python-list
On Apr 22, 12:04 am, Ivan Illarionov <[EMAIL PROTECTED]>
wrote:
> On Mon, 21 Apr 2008 16:10:05 -0700, George Sakkis wrote:
> > On Apr 21, 5:30 pm, Ivan Illarionov <[EMAIL PROTECTED]> wrote:
>
> >> On 22 ÁÐÒ, 01:01, Peter Otten <[EMAIL PROTECTED]>
On Apr 22, 6:34 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> azrael schrieb:
>
> > Hy guys,
> > A friend of mine i a proud PERL developer which always keeps making
> > jokes on python's cost.
>
> > Please give me any arguments to cut him down about his commnets
> > like :"keep programing i p
lity
and reduce redundancy than inheritance.
George
--
http://mail.python.org/mailman/listinfo/python-list
the string, so I don't feel comfortable using that.
Check out one of the safe restricted eval recipes, e.g.
http://preview.tinyurl.com/6h7ous.
HTH,
George
--
http://mail.python.org/mailman/listinfo/python-list
ions, like so:
>
> junk = ['[[','"[',']]']
>
> and just using re.sub to covert them into a single character that I
> could start to do split() actions on. There must be something else I
> can do..
Yes, find out the formal grammar of
gh pickle calls
__reduce_ex__ too:
from pickle import dumps,loads
t = Test(0, 0)
assert loads(dumps(t)) == t
Perhaps someone more knowledgeable can explain the subtle differences
between pickling and copying here.
George
[1] http://docs.python.org/lib/module-copy.html
[2] http://docs.python.org/lib/node320.html
--
http://mail.python.org/mailman/listinfo/python-list
On Apr 24, 12:21 am, Daniel <[EMAIL PROTECTED]> wrote:
> On Apr 23, 4:22 pm, George Sakkis <[EMAIL PROTECTED]> wrote:> On Apr 23, 6:24
> pm, Daniel <[EMAIL PROTECTED]> wrote:
>
> > > I have a list of strings, which I need to convert into tuples. If the
>
acter; probably
not what you intend. Of course we can check for "isinstance(obj,str)"
but then we're back at explicit type checking. There is no general way
to express something lke "atomic value that also happens to be
iterable (but pretend it's not)" because it'
honic design pattern/best practice that I can apply here?
>
> Thank you,
> Malcolm
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/502304
HTH,
George
--
http://mail.python.org/mailman/listinfo/python-list
On Apr 28, 10:10 pm, [EMAIL PROTECTED] wrote:
> George,
>
> > Is there an elegant way to unget a line when reading from a file/stream
> > iterator/generator?
>
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/502304
>
> That's exactly what I was lookin
getattr(self, attr, default),
fset = lambda self,value: setattr(self, attr, value),
doc = func.__doc__)
class Rectangle(object):
'''A beautiful Rectangle'''
@defaultproperty
def length(default=12.0):
'''This is the length property'''
George
--
http://mail.python.org/mailman/listinfo/python-list
s. It can be done with two expressions though:
def normquery(text, findterms=re.compile(r'"([^"]+)"|(\S+)').findall,
normspace=re.compile(r'\s{2,}').sub):
return [normspace(' ', (t[0] or t[1]).strip()) for t in
findterms(text)]
>>> normquery(' "some words" with and "withoutquotes " ')
>>> ['some words', 'with', 'and', 'without quotes']
HTH,
George
--
http://mail.python.org/mailman/listinfo/python-list
o much ? Is there a guesstimate of what
percentage of this test code tests for things that you would get for
free in a statically typed language ? I'm just curious whether this
argument against dynamic typing - that you end up doing the job of a
static compiler in test code - holds in pra
On Apr 29, 11:13 pm, Jürgen Exner <[EMAIL PROTECTED]> wrote:
> "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>
> Is this self-promoting maniac still going at it?
>
> >Although i disliked Perl very much [...]
>
> Then why on earth do you bother polluting this NG?
>
> Back into the killfile you g
for x in iterable)
I can't count the times I've been bitten by TypeErrors raised on
','.join(s) if s contains non-string objects; having to do
','.join(map(str,s)) or ','.join(str(x) for x in s) gets old fast.
"Explicit is better than implicit" unless there is an obvious default.
George
--
http://mail.python.org/mailman/listinfo/python-list
On Apr 30, 3:53 pm, Mel <[EMAIL PROTECTED]> wrote:
> George Sakkis wrote:
> > def join(iterable, sep=' ', encode=str):
> > return sep.join(encode(x) for x in iterable)
>
> Actually
>
> return encode(sep).join(encode(x) for x in iterable)
On May 1, 3:36 am, Duncan Booth <[EMAIL PROTECTED]> wrote:
> George Sakkis <[EMAIL PROTECTED]> wrote:
> > On Apr 30, 5:06 am, Torsten Bronger <[EMAIL PROTECTED]>
> > wrote:
> >> Hallöchen!
>
> >> SL writes:
> >> > "Gabr
/2006/09/27/introducing-wsgi-pythons-secret-web-weapon.html.
Here's the standard "Hello world!" example:
from wsgiref.simple_server import make_server
def application(environ, start_response):
start_response('200 OK',[('Content-type','text/html')])
return ['Hello World!']
httpd = make_server('', 8000, application)
print "Serving HTTP on port 8000..."
httpd.serve_forever()
and point your browser to http://localhost:8000/
HTH,
George
--
http://mail.python.org/mailman/listinfo/python-list
it's a
context-free language [1], not a regular one [2]. Either do it
manually or use a parser generator [3].
George
[1] http://en.wikipedia.org/wiki/Context-free_language
[2] http://en.wikipedia.org/wiki/Regular_language
[3] http://wiki.python.org/moin/LanguageParsing
--
http://mail.python.
]
>
> m3 doesn't work because you're building a list of 10 color/number pairs
> that you're trying to unpack that into just two names. The working
> "derivative" of m3 is m1, which is the most natural, fastest and
> clearest solution to your problem.
Another alternative is:
from operator import itemgetter
def m3():
colours, nums = zip(*map(itemgetter('colour','num'), l))
It's slower than m1() but faster than m2(); it's also the most
concise, especially if you extract more than two keys.
George
--
http://mail.python.org/mailman/listinfo/python-list
On May 2, 2:17 am, Matimus <[EMAIL PROTECTED]> wrote:
> On May 1, 10:50 pm, George Sakkis <[EMAIL PROTECTED]> wrote:
>
>
>
> > On May 1, 11:46 pm, Carsten Haese <[EMAIL PROTECTED]> wrote:
>
> > > Yves Dorfsman wrote:
>
> > > > In
On Wed, 30 Apr 2008 12:35:10 +0200, "John Thingstad"
<[EMAIL PROTECTED]> wrote:
>PÃ¥ Wed, 30 Apr 2008 06:26:31 +0200, skrev George Sakkis
><[EMAIL PROTECTED]>:
>
>>
>>\|||/
>> (o o)
>> ,ooO--(_)---.
>> |
re trying to achieve here, but I bet there is a
> simpler way to do it than by generating a script. You might want to look into
> functions.
>
> http://docs.python.org/tut/node6.html#SECTION00660
Seriously, this looks like a DailyWTF entry.
George
--
http://mail.python.org/mailman/listinfo/python-list
ce (raw view) and particularly check in the
> > headers for things to filter by.
>
> Why don't you just block all messages from Gmail?
Look up the term "false positive" before you make such brilliant
suggestions in the future.
Posting-from-google-groups-ly yrs,
George
--
http://mail.python.org/mailman/listinfo/python-list
going to work but in ideality the index function
> should return a -1 and no way in hell crash.
Please refrain from making such inane comments after an hour or two of
toying with a new language. Read a good tutorial first (e.g.
http://diveintopython.org/toc/index.html) and come back if you have a
real question.
George
--
http://mail.python.org/mailman/listinfo/python-list
On May 2, 4:49 pm, Mensanator <[EMAIL PROTECTED]> wrote:
> On May 2, 2:57 pm, George Sakkis <[EMAIL PROTECTED]> wrote:
>
>
>
> > On May 2, 1:18 pm, Mensanator <[EMAIL PROTECTED]> wrote:
>
> > > On May 2, 9:53 am, Michael Torrie <[EMAI
ps, best of 3: 5.14 usec per loop
python -mtimeit --setup="from operator import add; x=[1.0]*100"
"reduce(add,x)"
10 loops, best of 3: 10.1 usec per loop
# Adding tuples
python -mtimeit --setup="x=[(1,)]*100" "sum(x,())"
1 loops, best of 3: 61.6 usec
ictionaries:
>
> > def invert(d):
> > inv = {}
> > for key, val in d.iteritems():
> > inv.setdefault(val, []).append(key)
> > return inv
>
>
In Python 2.5 and later you may use the defaultdict class which is
faster and slightly more elegant in such cases:
from collections import defaultdict
def invert(d):
inv = defaultdict(list)
for key, val in d.iteritems():
inv[val].append(key)
return inv
George
--
http://mail.python.org/mailman/listinfo/python-list
On May 4, 2:04 am, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote:
> En Sun, 04 May 2008 02:17:07 -0300, dave <[EMAIL PROTECTED]> escribió:
>
>
>
> > Hello,
>
> > I made a function that takes a word list (one word per line, text file)
> > and searches for all the words in the list that are 'shifts'
with "from ... import ...".
- Any existing instances of classes defined in the module still refer
to the original class, not the reloaded one (assuming it is still
present).
- The module's dictionary (containing the module's global variables)
is retained and updated in place, so names that are deleted in the
module are still available.
- It is not recursive.
- And more...
George
--
http://mail.python.org/mailman/listinfo/python-list
rnaud was
referring to the case where you do it in a loop, like in your snippet.
A direct translation to use ''.join would be:
ans = ''.join(chr((ord(letter) - ord('a') + amt) % 26 + ord('a'))
for letter in word)
Of course it is simpler and more efficient if you factor out of the
loop the subexpressions that don't need to be recomputed:
ord_a = ord('a')
shift = ord_a - amt
ans = ''.join(chr((ord(letter) - shift) % 26 + ord_a)
for letter in word)
George
--
http://mail.python.org/mailman/listinfo/python-list
gt; Now, cherrypy is something that is not properly "include a file and get
> >> going!"
> >>>http://www.kid-templating.org/
> >> kid seems to have a non-linear approach, but i may give it a try
>
> >>>http://www.cheetahtemplate.org/
> >> cheetah was something that i already considered using. have i to
> >> "install" it or can i just import it?
>
> > You will need to install any of these. It is part of how python is designed.
> > Extendability comes with a price-tag.
>
> well, the problema is exacly that i'm looking for a python module, not
> for a python library.
What does it matter if it's a single file or a dozen under a package ?
"Installation" for pure Python packages can be as simple as copying
the package under any directory in your PYTHONPATH.
Check out Mako (http://www.makotemplates.org/), it's pretty powerful
and fast.
George
--
http://mail.python.org/mailman/listinfo/python-list
tp://xahlee.org/UnixResource_dir/writ/jargons.html
>
>Â The Jargon ÂLisp1Â vs ÂLisp2Â
> http://xahlee.org/emacs/lisp1_vs_lisp2.html
>
>Â The Term Curring In Computer Science
> http://xahlee.org/UnixResource_dir/writ/currying.html
>
>Â What Is Closure In A Programing Language
> http://xahlee.org/UnixResource_dir/writ/closure.html
>
>Â What are OOP's Jargons and Complexities
> http://xahlee.org/Periodic_dosage_dir/t2/oop.html
>
>Â Sun Microsystem's abuse of term ÂAPIÂ and ÂInterfaceÂ
> http://xahlee.org/java-a-day/interface.html
>
>Â Math Terminology and Naming of Things
> http://xahlee.org/cmaci/notation/math_namings.html
>
> Xah
> [EMAIL PROTECTED]
>? http://xahlee.org/
>
>?
George
--
for email reply remove "/" from address
--
http://mail.python.org/mailman/listinfo/python-list
it sure does make sense from a theoretical standpoint.
Whether it's a worthy addition is debatable though; I don't think
there are many common use cases to convince the core developers to
work on it. OTOH if you (or someone else) comes up with a working
patch, it might improve its chances o
difying self.__dict__
are good enough.
I understand that no more proposals are accepted for Python 3 but it
looks like a missed opportunity to make the language a bit simpler and
more consistent. Anyone else have an opinion on this?
George
--
http://mail.python.org/mailman/listinfo/python-list
On May 8, 2:58 am, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
> George Sakkis wrote:
> > One of the few Python constructs that feels less elegant than
> > necessary to me is the del statement. For one thing, it is overloaded
> > to mean three different things:
>
d only be meaningful if the survey population
already possessed some knowledge of programming, but were not already
aware of the particular terminology being surveyed.
George
--
for email reply remove "/" from address
--
http://mail.python.org/mailman/listinfo/python-list
functions have been wrapped in (unbound) methods:
A.__init__ = w(A.__init__)
- (Risky Hack): Guess whether a function is intended to be wrapped in
a method by checking whether its first argument is named "self".
Obviously this is not foolproof and it doesn't work for static/
>This is what I don't understand - everyone seems to assume that by cross
>posting, one intends on start a "flamefest", when in fact most such
>"flamefests" are started by those who cannot bring themselves to
>skipping over the topic that they so dislike.
Th
apq.nlargest)
Help on function nlargest in module heapq:
nlargest(n, iterable, key=None)
Find the n largest elements in a dataset.
Equivalent to: sorted(iterable, key=key, reverse=True)[:n]
HTH,
George
--
http://mail.python.org/mailman/listinfo/python-list
emented in derived classes?
Using the overridable property recipe [1], it can be written as:
class AbstractFoo(object):
def _getFoo(self):
raise NotImplementedError('Abstract method')
def _setFoo(self, signals):
raise NotImplementedError('Abstract method'
y
I'm trying to install on the latest Ubuntu (8.04) and the following
extension modules fail:
_bsddb, _curses, _curse_panel, _hashlib, _sqlite3, _ssl, _tkinter,
bz2, dbm, gdbm, readline, zlib
All of them except for _tkinter are included in the preinstalled
Python 2.5.2, so I guess the dependencies mus
On May 9, 11:19 pm, dave <[EMAIL PROTECTED]> wrote:
> On 2008-05-09 18:53:19 -0600, George Sakkis <[EMAIL PROTECTED]> said:
>
>
>
> > On May 9, 5:19 pm, [EMAIL PROTECTED] wrote:
> >>>> What would be the best method to print the top results, the
On Fri, 09 May 2008 22:45:26 -0500, [EMAIL PROTECTED] (Rob Warnock) wrote:
>George Neuner wrote:
>
>>On Wed, 7 May 2008 16:13:36 -0700 (PDT), "[EMAIL PROTECTED]"
>><[EMAIL PROTECTED]> wrote:
>
>>>Â Functions [in Mathematica] that takes elements
l6 PEG is in a usable state?
>
>Thanks.
>
> Xah
> [EMAIL PROTECTED]
>? http://xahlee.org/
George
--
for email reply remove "/" from address
--
http://mail.python.org/mailman/listinfo/python-list
icdef('plus5', 5)
>
> print plus5(7)
Unsurprisingly, there is indeed a better way, a closure:
def adder(amt):
def closure(x):
return x + amt
return closure
>>> plus5 = adder(5)
>>> plus5(7)
12
HTH,
George
--
http://mail.python.org/mailman/listinfo/python-list
, guess what, it uses exec!
I might be wrong, but the reason namedtuple uses exec is performance.
IIRC earlier versions of the recipe used a metaclass instead, so it's
not that it *has* to use exec, it's just an optimization, totally
justified in this case since namedtuples should be
in [3] == True
False
How/why does the last one evaluate to False ?
George
--
http://mail.python.org/mailman/listinfo/python-list
On Aug 18, 12:04 pm, Peter Otten <[EMAIL PROTECTED]> wrote:
> George Sakkis wrote:
> > I'm probably missing something obvious but I can't put my finger on
> > it:
>
> >>>> (3 in [3]) == True
> > True
>
> >>>> 3 in ([3]
Parser:
# XXX: monkeypatch SGMLParser to fix bug introduced in 2.5
# http://bugs.python.org/issue1651995
if sys.version_info[:2] == (2,5):
from sgmllib import SGMLParser
SGMLParser.convert_codepoint = lambda self,codepoint:
unichr(codepoint)
HTH,
George
[1] http://en.wikipedia.org/wiki/Monkey_patch
--
http://mail.python.org/mailman/listinfo/python-list
elem in iterparse(StringIO(s)):
... print elem.text
...
Traceback (most recent call last):
File "", line 1, in
File "", line 64, in __iter__
UnicodeEncodeError: 'ascii' codec can't encode characters in position
6-15: ordinal not in range(128)
Am I using
ml.etree the returned text's type is not fixed, even within the same
file. Although it's not a bug, having a mixed collection of byte and
unicode strings from the same source makes me somewhat uneasy.
George
--
http://mail.python.org/mailman/listinfo/python-list
On Aug 21, 1:48 am, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> George Sakkis wrote:
> > It's interesting that the element text attributes after a successful
> > parse do not necessarily have the same type, i.e. all be str or all
> > unicode. I ported some text ext
call last):
...
csv.writer(f).writerow([s])
UnicodeEncodeError: 'ascii' codec can't encode character u'\u0391' in
position 0: ordinal not in range(128)
Is this the expected behavior or are these bugs ?
George
--
http://mail.python.org/mailman/listinfo/python-list
t;There is nobody here, who ever visited/replied with any thought relavence that
>can
>be brought foward to any degree, meaning anything, nobody
What are you looking for? An emulator you can play with?
Machine coding is not relevant anymore - it's completely infeasible to
input all but the smallest program. My friend had a BASIC interpreter
for his 8080 - about 2KB which took hours to input by hand and heaven
help you if you screwed up or the computer crashed.
>sln
George
--
http://mail.python.org/mailman/listinfo/python-list
n a couple more attributes some fairly
> complex over-ride logic?
A small improvement as far as overriding goes is the OProperty recipe:
http://infinitesque.net/articles/2005/enhancing%20Python's%20property.xhtml
George
--
http://mail.python.org/mailman/listinfo/python-list
rted() returns a list, but reversed() returns an iterator.
>
> urllib2.urlopen() will automatically detect the proxy in your environment
> and use that. That's usually a feature, but sometimes it can be a gotcha.
>
> urllib2 doesn't work well with some HTTPS proxies.
to take a look at implementation.
George
--
http://mail.python.org/mailman/listinfo/python-list
On Aug 24, 1:12 am, Stefan Behnel <[EMAIL PROTECTED]> wrote:
> George Sakkis wrote:
> > On Aug 21, 1:48 am, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
>
> >> George Sakkis wrote:
> >>> It's interesting that the element text attributes after a succe
On Aug 25, 4:45 pm, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> George Sakkis wrote:
> > It depends on what you mean by "compatible"; e.g. you can't safely do
> > [s.decode('utf8') for s in strings] if you have byte strings mixed
> > with unicod
On Aug 27, 5:42 am, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> George Sakkis wrote:
> >> if you meant to write "encode", you can indeed safely do
> >> [s.encode('utf8') for s in strings] as long as all strings are returned
> >> by a
ke up to `good_ones` non-zeros
good = list(islice(takewhile(bool,iterator), good_ones))
if not good: # iterator exhausted
return iterator
if len(good) == good_ones:
# found `good_ones` consecutive non-zeros;
# chain them to the rest items and return them
return chain(good, iterator)
HTH,
George
--
http://mail.python.org/mailman/listinfo/python-list
4]; from
itergood import itergood" "list(itergood(x))"
100 loops, best of 3: 3.09 msec per loop
And with Psyco enabled:
$ python -m timeit -s "x = 1000*[0, 0, 0, 1, 2, 3] + [1,2,3,4]; from
itergood import itergood" "list(itergood(x))"
1000 loops, best of 3: 466 usec per loop
George
--
http://mail.python.org/mailman/listinfo/python-list
On Aug 27, 5:34 pm, [EMAIL PROTECTED] wrote:
> George Sakkis:
>
> > This seems the most efficient so far for arbitrary iterables.
>
> This one probably scores well with Psyco ;-)
I think if you update this so that it returns the "good" iterable
instead of the startin
On Aug 27, 5:48 pm, castironpi <[EMAIL PROTECTED]> wrote:
> On Aug 27, 4:34 pm, [EMAIL PROTECTED] wrote:
>
>
>
> > George Sakkis:
>
> > > This seems the most efficient so far for arbitrary iterables.
>
> > This one probably scores well with Psy
On Aug 29, 1:29 am, "W. eWatson" <[EMAIL PROTECTED]> wrote:
> It looks like I have a few new features to learn about in Python. In
> particular,
> dictionaries.
In Python it's hard to think of many non-trivial problems that you
*don't* have to know
# even if it's not a list, it will raise an exception later anyway
if you call a list-specific method
HTH,
George
--
http://mail.python.org/mailman/listinfo/python-list
e exception propagate to the top
level with a full traceback.
HTH,
George
--
http://mail.python.org/mailman/listinfo/python-list
t you want can be expressed much easier and efficiently with a
generator expression as:
def av_grade(self):
# XXX: missing 0 reviews handling
return sum(review.grade for review in self.reviews) /
len(self.reviews)
HTH,
George
--
http://mail.python.org/mailman/listinfo/python-list
On Mon, 1 Sep 2008 21:03:44 + (UTC), Martin Gregorie
<[EMAIL PROTECTED]> wrote:
>On Mon, 01 Sep 2008 12:04:05 -0700, Robert Maas, http://tinyurl.com/uh3t
>wrote:
>
>>> From: George Neuner <[EMAIL PROTECTED]> A friend of mine had an
>>> early 8080 micro
7;m tired, when I have to put my
> hands on the code of someone else, and so on.
So what happens in Java (or any language for that matter) if there are
indeed two attributes x and y with the same type and you mistype the
one for the other ? Or if you meant to write x-y instead of y-x ?
Wh
uld be (x, y) since both
(d,a) and (a,b) would match for (d,a,b).
With respect to complexity, I am mainly interested in len(S); len(I)
is small for my application, typically no more than 10. Of course, an
algorithm that scales decently in both len(S) and len(I) would be even
better. Any ideas or re
o an
"equivalent" hashable object. A common choice that works for any list
[*] is to convert it to a tuple. An alternative that works for strings
only is to join() them into a single string:
>>> values = '00341 01741 03254 34100 14300 05321'.split()
>>> set
quot;require") readers to
share their interest or enthusiasm by replying to the ANN. Given your
past semi-coherent and incoherent posts, expecting people to jump on
such a thread is a rather tall order.
George
--
http://mail.python.org/mailman/listinfo/python-list
s messy.
>
> Another idea was to store the weightings as a dictionary
> on each instance, but I could not see how to update that
> from a decorator.
>
> I like the idea of having the weights in a dictionary, so I
> am looking for a better API, or a way to re-weight the
> meth
any sub-
version is greater than 9. Here's a standard idiom (in 2.5+ at least):
from collection import defaultdict
versions = [ "1.1.1.1", "1.2.2.2", "1.2.2.3", "1.3.1.2", "1.3.4.5"]
major2count = defaultdict(int)
for v in versions:
major2count['.'.join(v.split('.',2)[:2])] += 1
print major2count
HTH,
George
--
http://mail.python.org/mailman/listinfo/python-list
uot;2",
> >"1.3" : "2" }
>
> [...]
> data = [ "1.1.1.1", "1.2.2.2", "1.2.2.3", "1.3.1.2", "1.3.4.5"]
>
> from itertools import groupby
>
> datadict = \
>dict((k, len(list(g))) for k,g in groupby(data, lambda s: s[:3]))
> print datadict
Note that this works correctly only if the versions are already sorted
by major version.
George
--
http://mail.python.org/mailman/listinfo/python-list
(len(data_set)):
> ds = data_set[:]
> data = ds[i]
> if i == 1: data['param'] = "y"
> if i == 2: data['param'] = "x"
>
> print data_set
>
> This script print out:
> ({'param': 'a'}, {'param'
On Sep 23, 9:57 am, Grant Edwards <[EMAIL PROTECTED]> wrote:
> On 2008-09-23, sturlamolden <[EMAIL PROTECTED]> wrote:
>
> [...]
>
> > After having a working Python prototype, I resorted to rewrite the
> > program in C++. The Python prototype took an hour to make, debug and
> > verify. The same thi
Here's one approach, using metaclasses and descriptors; it sort of
works, but it's less than ideal, both in usage and implementation.
George
#== usage
class MyConstants:
__metaclass__ = ConstantsMeta
FOO = const(1,
On Sep 23, 3:55 pm, Gerard flanagan <[EMAIL PROTECTED]> wrote:
> George Sakkis wrote:
> > On Sep 23, 1:23 am, "Tom Harris" <[EMAIL PROTECTED]> wrote:
>
> >> Greetings,
>
> >> I want to have a class as a container for a bunch of symbo
lass Proxy(object):
__metaclass__ = _ProxyMeta
def __init__(self, *delegates):
self._cls2delegate = {}
for delegate in delegates:
cls = type(delegate)
if cls in self._cls2delegate:
raise ValueError('More than one %s delegates were
given
> because you could set a flag to see the words in comment yes or no )
If you're on *nix platform, you can use:
$ find -name "*py" | xargs egrep "\bword\b"
HTH,
George
--
http://mail.python.org/mailman/listinfo/python-list
1301 - 1400 of 1560 matches
Mail list logo