Re: Class Methods Vs Any Other Callable

2008-05-14 Thread George Sakkis
od was the only (elegant) solution; neither a class method nor a plain function would do. I'll post it if I find it unless someone beats me to it. George -- http://mail.python.org/mailman/listinfo/python-list

Nasty gotcha/bug in heapq.nlargest/nsmallest

2008-05-14 Thread George Sakkis
r nsmallest. So that must be at least a documentation bug, if not an implementation one. George -- http://mail.python.org/mailman/listinfo/python-list

Re: Class Methods Vs Any Other Callable

2008-05-15 Thread George Sakkis
On May 14, 4:38 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > On 14 mai, 16:30, George Sakkis <[EMAIL PROTECTED]> wrote: > > > On May 14, 10:19 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > > > > > An instance me

Re: Nasty gotcha/bug in heapq.nlargest/nsmallest

2008-05-15 Thread George Sakkis
On May 15, 3:06 am, Peter Otten <[EMAIL PROTECTED]> wrote: > George Sakkis wrote: > > I spent several hours debugging some bogus data results that turned > > out to be caused by the fact that heapq.nlargest doesn't respect rich > > comparisons: > > &g

Re: datamining .txt-files, library?

2008-05-15 Thread George Sakkis
s and what kind of information you hope to extract (shallow or deep). NLTK might be a good starting point: http://nltk.sourceforge.net/ George -- http://mail.python.org/mailman/listinfo/python-list

Re: morning in Python

2008-05-16 Thread George Sakkis
On May 16, 11:58 am, "inhahe" <[EMAIL PROTECTED]> wrote: > I'm not an expert in this but what does it mean to emphasize state?  It > seems the opposite of that would be a) functional programming, and b) > passing parameters instead of using global or relatively local variables. > And maybe c) corou

Re: can't delete from a dictionary in a loop

2008-05-17 Thread George Sakkis
h them to the other if still alive, something like this: from collections import deque processes = deque() # start processes and put them in the queue while processes: for i in xrange(len(processes)): p = processes.pop() if p.poll() is None: # not finished yet processes.append_left(p) time.sleep(5) HTH, George -- http://mail.python.org/mailman/listinfo/python-list

Re: namespaces and eval

2008-05-20 Thread George Sakkis
ouble(x): return 2*x def square(x): return x**2 def succ(x): return x+1 >>> print Composable(2) | float | succ | square | double | DONE 18.0 Admittedly 'DONE' is ugly but it's necessary to denote that the piping ends and the final value (rather than the Composable wrapper) should be returned. The OP's wrap class suffers from the same problem but it masks it by overriding __getattr__ in an old-style class. If the class is changed to new-style, it becomes more obvious that wrap(x).foo().foo().foo().foo() returns the wrap object, not x. George -- http://mail.python.org/mailman/listinfo/python-list

Segmentation fault on updating a BYTEA field [psycopg2]

2008-05-21 Thread George Sakkis
#x27;\xa1\xf22\xf6y\xd0\xbc \xea6\xf0Y\xf1"\xc9(\n'] >>> cur.execute('UPDATE duplicate SET orig_sig=%(orig_sig)s WHERE duplicate.sig >>> = %(duplicate_sig)s', ... dict(orig_sig=d[0], duplicate_sig=d[1])) Segmentation fault Am I (and SqlAlchemy) doing something silly or is this a bug in psycopg2 ? George -- http://mail.python.org/mailman/listinfo/python-list

MVC

2008-05-22 Thread George Maggessy
er. So, here goes my question. Is that OK if I follow this? Should I create DAOs, View Objects, Controllers and etc? Is there any sort of best practice / standard to Python? Cheers, George -- http://mail.python.org/mailman/listinfo/python-list

Re: Segmentation fault on updating a BYTEA field [psycopg2]

2008-05-23 Thread George Sakkis
On May 21, 6:32 pm, George Sakkis <[EMAIL PROTECTED]> wrote: > I have a simple DB table that stores md5 signature pairs: > >Table "public.duplicate" > Column | Type | Modifiers > --+---+--- > sig | bytea | not null >

Re: Assignment and comparison in one statement

2008-05-23 Thread George Sakkis
d readable of course: use two statements, as one should do regardless of the language, instead of resorting to error- prone hacks. George -- http://mail.python.org/mailman/listinfo/python-list

Re: Hungarian Notation

2008-05-27 Thread George Sakkis
might call > x2y. I use the same convention, though it's less than ideal if x or y consist of more than one word (typically joined with underscore), e.g. "value2row_id" or if the values are also dicts ("category2value2instances"). George -- http://mail.python.org/mailman/listinfo/python-list

Re: Python and Flaming Thunder

2008-05-28 Thread George Sakkis
phics look cool and the "single-asset 8-by-8 shotgun cross compiler, written entirely in assembly language" sounds impressive from an implementation point of view, in the sense that building Deep Blue with nothing but NAND gates would; utterly impressive and pointless at the sa

Re: Writing a function from within Python

2008-05-28 Thread George Sakkis
fer. The short answer is "yes". The longer answer is "yes but most likely there are better approaches to whatever you want to do". If you give a bit more context of the general problem you're trying to solve, I'm sure you'll get more helpful replies. George -- http://mail.python.org/mailman/listinfo/python-list

Re: How to add function return value

2008-05-31 Thread George Sakkis
@withlocals def foo(x, y=0, *args, **kwds): a = max(x,y) b = len(args) c = min(kwds.values()) return a+b+c r,locs = foo(1,2,3,4,a=5,b=6) print locs George -- http://mail.python.org/mailman/listinfo/python-list

Re: accumulator generators

2008-05-31 Thread George Sakkis
= yield n > > Although the problem is that you can't send it values the first time > round! > > >>> bar = foo('s') > >>> bar.next() > 's' > >>> bar.send('p') > 'sp' > >>> bar.send('am') >

ANN: equivalence 0.1

2008-06-01 Thread George Sakkis
dups.are_equivalent('www.pythondocs.com/index.htm', 'http://python.org/doc/ index.html') >>> True You can find more about the API in the included docs and the unittest file. Regards, George -- http://mail.python.org/mailman/listinfo/python-list

Re: Conjunction List

2008-06-01 Thread George Sakkis
y if you want to generalize it to more than three arguments, here's one way to do it: def conjunction(*args): if not args: return first = args[0][0] if all(arg[0]==first for arg in args): for e in zip(*(arg[1] for arg in args)): print e >>> conjuction(a,b,c) ('0', 'one', '0%') ('1', 'two', '50%') ('2', 'three', '100%') HTH, George -- http://mail.python.org/mailman/listinfo/python-list

Re: convert binary to float

2008-06-01 Thread George Sakkis
xc0@") >     Out[4]: (6.0,) > > But when I run the same code from my .py file: > >     f = open("test2.pc0", "rb") >     tagData = f.read(4) >     print tagData > > I get this (ASCII??): > „@ Remembering to put that struct.unpack() call in your module might help ;-) George -- http://mail.python.org/mailman/listinfo/python-list

Re: ANN: equivalence 0.1

2008-06-02 Thread George Sakkis
On Mon, Jun 2, 2008 at 6:31 AM, Giuseppe Ottaviano <[EMAIL PROTECTED]> wrote: > > On Jun 1, 2008, at 6:16 PM, George Sakkis wrote: > >> Equivalence is a class that can be used to maintain a partition of >> objects into equivalence sets, making sure that the equivalence

Re: Ideas for master's thesis

2008-06-02 Thread George Sakkis
about the lack of data hiding and try to add such a mechanism, preferably as a pure python add-on package ala zope.interface (only half-joking ;-)) George -- http://mail.python.org/mailman/listinfo/python-list

Re: Why does python not have a mechanism for data hiding?

2008-06-03 Thread George Sakkis
On Jun 3, 1:42 am, "Russ P." <[EMAIL PROTECTED]> wrote: > On Jun 2, 10:23 pm, alex23 <[EMAIL PROTECTED]> wrote: > > > Then again, I have no issue with the current convention and personally > > find the idea of adding a "private" keyword makes as much sense as > > being able to syntactically define

Re: Constructor re-initialization issue

2008-06-03 Thread George Sakkis
On Jun 3, 6:11 pm, [EMAIL PROTECTED] wrote: > Hello all, > > I have come across this issue in Python and I cannot quite understand > what is going on. > > class Param(): > def __init__(self, data={}, condition=False): > if condition: > data['class']="Advanced" > pri

ANN: equivalence 0.2

2008-06-03 Thread George Sakkis
Equivalence v0.2 has been released. Also the project is now hosted at http://code.google.com/p/pyquivalence/ (the name 'equivalence' was already taken but the module is still called equivalence). Changes === - The internals were largely rewritten, but the API remained effectively intact. - A n

Re: Tuples part 2

2008-06-05 Thread George Sakkis
; bearophile > > Hi, > > the result i would like is similar to a set of n tuples: tuple_1, > tuple_2,...,tuple_n. I use h in order to enumerate the tuples and > i,j,k would be the coordinates. >From the pseudocode you wrote at first, tuple_1, tuple_2, ..., tuple_n would be all equal. Is this intentional, and if so, what's the purpose ? George -- http://mail.python.org/mailman/listinfo/python-list

Re: Tuples part 2

2008-06-05 Thread George Sakkis
> tuple 2=((2, 1, 1), (2, 2, 1), (2, 3, 1), (2, 4, 1)) > > > > tuple 3=((3, 1, 1), (3, 2, 1), (3, 3, 1), (3, 4, 1)) > > > > and so on. Please help me and sorry for not taking the time to post my > > > questions properly. > > > > Victor > > > Or even

Re: Tuples part 2

2008-06-05 Thread George Sakkis
On Jun 5, 11:48 am, Ivan Illarionov <[EMAIL PROTECTED]> wrote: > On 5 июн, 19:38, George Sakkis <[EMAIL PROTECTED]> wrote: > > > > > On Jun 5, 11:21 am, Ivan Illarionov <[EMAIL PROTECTED]> wrote: > > > > On 5 июн, 18:56, Ivan Illarionov <[EMAIL PR

Re: Why does python not have a mechanism for data hiding?

2008-06-05 Thread George Sakkis
On Jun 5, 2:07 pm, "Russ P." <[EMAIL PROTECTED]> wrote: > The "private" keyword goes further and prevents > access even by derived classes. The double leading underscore in > Python does no such thing. Who develops these derived classes ? A competitor ? A malicious hacker ? A spammer ? Who are yo

Re: Web Crawler - Python or Perl?

2008-06-09 Thread George Sakkis
r, unless you're looking for an excuse to learn perl. In terms of performance they are comparable, and you can probably manage crawls in the order of 10-100K pages at best. For million-page or larger crawls though, you'll have to resort to C/C++ sooner or later. George -- http://mail.python.org/mailman/listinfo/python-list

Confusion with weakref, __del__ and threading

2008-06-10 Thread George Sakkis
was doing "self._thread.join()", assuming that the current thread is not self._thread, but as it turns out that's not always the case. So what is happening here for these ~50 minority cases ? Is __del__ invoked through the proxy ? George -- http://mail.python.org/mailman/listinfo/python-list

Producer-consumer threading problem

2008-06-10 Thread George Sakkis
cially if it has to do with proving or disproving its correctness, will be appreciated. George -- http://mail.python.org/mailman/listinfo/python-list

Re: Producer-consumer threading problem

2008-06-10 Thread George Sakkis
o the client doesn't have to bother with synchronization. Note that with "client" I mean the user of an API/ framework/library; the implementation of the library itself may of course use callbacks under the hood (e.g. to put incoming results to a Queue) but expose the API as a simple iterator. George -- http://mail.python.org/mailman/listinfo/python-list

Re: Producer-consumer threading problem

2008-06-11 Thread George Sakkis
m as it becomes available is more memory efficient than waiting for all of them to finish. George -- http://mail.python.org/mailman/listinfo/python-list

Re: Confusion with weakref, __del__ and threading

2008-06-11 Thread George Sakkis
On Jun 11, 1:40 am, Rhamphoryncus <[EMAIL PROTECTED]> wrote: > On Jun 10, 8:15 pm, George Sakkis <[EMAIL PROTECTED]> wrote: > > > > > I'm baffled with a situation that involves: > > 1) an instance of some class that defines __del__, > > 2) a thread w

Re: Confusion with weakref, __del__ and threading

2008-06-11 Thread George Sakkis
On Jun 11, 2:01 pm, Rhamphoryncus <[EMAIL PROTECTED]> wrote: > On Jun 11, 10:43 am, George Sakkis <[EMAIL PROTECTED]> wrote: > > > On Jun 11, 1:40 am, Rhamphoryncus <[EMAIL PROTECTED]> wrote: > > > The trick here is that calling proxy.sleep(0.01) first gets

Re: Simple and safe evaluator

2008-06-11 Thread George Sakkis
.next()('/etc/passwd') ... """ >>> eval(s, {"__builtins__":None}, {} ) Traceback (most recent call last): File "", line 1, in File "", line 3, in IOError: file() constructor not accessible in restricted mode Not an exploit yet but I wouldn't be surprised if there is one. Unless you fully trust your users, an ast-based approach is your best bet. George George -- http://mail.python.org/mailman/listinfo/python-list

Re: Confusion with weakref, __del__ and threading

2008-06-11 Thread George Sakkis
On Jun 11, 8:37 pm, Rhamphoryncus <[EMAIL PROTECTED]> wrote: > On Jun 11, 2:15 pm, George Sakkis <[EMAIL PROTECTED]> wrote: > > > > > On Jun 11, 2:01 pm, Rhamphoryncus <[EMAIL PROTECTED]> wrote: > > > > On Jun 11, 10:43 am, George Sakkis <[EM

Re: مقطع فيديو [الولاده القيصر يه] يمنع دخول ضعاف القلوب

2008-06-11 Thread George Sakkis
On Jun 12, 12:29 am, Collin <[EMAIL PROTECTED]> wrote: > a7labnt wrote: > > Is this arabic spam? Why, are you curious how V1agr@ or [EMAIL PROTECTED] are spelled in arabic ? -- http://mail.python.org/mailman/listinfo/python-list

Re: Producer-consumer threading problem

2008-06-11 Thread George Sakkis
On Jun 11, 10:13 am, Jean-Paul Calderone <[EMAIL PROTECTED]> wrote: > On Tue, 10 Jun 2008 22:46:37 -0700 (PDT), George Sakkis <[EMAIL PROTECTED]> > wrote: > >On Jun 10, 11:47 pm, Larry Bates <[EMAIL PROTECTED]> wrote: > > >> I had a little trouble under

Re: Producer-consumer threading problem

2008-06-11 Thread George Sakkis
On Jun 11, 3:07 pm, Carl Banks <[EMAIL PROTECTED]> wrote: > On Jun 10, 11:33 pm, George Sakkis <[EMAIL PROTECTED]> wrote: > > > I pasted my current solution athttp://codepad.org/FXF2SWmg. Any > > feedback, especially if it has to do with proving or disprovin

Re: Simple and safe evaluator

2008-06-12 Thread George Sakkis
On Jun 12, 1:51 pm, bvdp <[EMAIL PROTECTED]> wrote: > Matimus wrote: > > On Jun 11, 9:16 pm, George Sakkis <[EMAIL PROTECTED]> wrote: > >> On Jun 11, 8:15 pm, bvdp <[EMAIL PROTECTED]> wrote: > > >>> Matimus wrote: > >>>> T

Re: Finding a sense of word in a text

2008-06-13 Thread George Sakkis
is > written in perl (http://www.d.umn.edu/~tpederse/senserelate.html) :( > > I appreciate any pointers. http://osteele.com/projects/pywordnet/examples.html HTH, George -- http://mail.python.org/mailman/listinfo/python-list

Re: importing part of a module without executing the rest

2008-06-13 Thread George Sakkis
code smell. In general, modules intended to be imported should not have any side effects at global scope before the "if __name__ == '__main__':" part. Put the "print ..." and all other statements with side effects in one or more functions and let the importing module call them explicitly if necessary. George -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 3000 vs. Python 2.x

2008-06-13 Thread George Sakkis
x and it would be nice to understand > those as well. Thanks for all the help. Learn 2.5. When (or if) Python 3 becomes relevant in a few years down the road, you'll be able to pick up the differences and new features in a week or so. George -- http://mail.python.org/mailman/listinfo/python-list

Removing inheritance (decorator pattern ?)

2008-06-15 Thread George Sakkis
pass class ReversedSorted(Reversed, Sorted): pass if __name__ == '__main__': words = 'this is a test'.split() print SortedReversed(words).join() print ReversedSorted(words).join() So I'm wondering, is the decorator pattern applicable here ? If ye

Re: Removing inheritance (decorator pattern ?)

2008-06-16 Thread George Sakkis
On Jun 16, 5:04 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > Diez B. Roggisch wrote: > > George Sakkis schrieb: > >> I have a situation where one class can be customized with several > >> orthogonal options. Currently this is implemented with (m

Re: Removing inheritance (decorator pattern ?)

2008-06-16 Thread George Sakkis
On Jun 16, 1:49 pm, Gerard flanagan <[EMAIL PROTECTED]> wrote: > George Sakkis wrote: > > I have a situation where one class can be customized with several > > orthogonal options. Currently this is implemented with (multiple) > > inheritance but this leads to combinator

Re: Simple and safe evaluator

2008-06-16 Thread George Sakkis
7;.split(): globs[name] = getattr(math,name) return eval(s, globs, {}) The change to the _ast version is left as an exercise to the reader ;) George -- http://mail.python.org/mailman/listinfo/python-list

Re: 2Q's: How to autocreate instance of class;How to check for membership in a class

2008-06-16 Thread George Sakkis
n name2user: ... If you ask how to check if some name x is a User instance, use the isinstance() function: if isinstance(x, User): print x.password Checking for class membership though is usually considered unnecessary or even harmful in Python. Just assume 'x' is a User and use it anyway. George -- http://mail.python.org/mailman/listinfo/python-list

Re: Removing inheritance (decorator pattern ?)

2008-06-17 Thread George Sakkis
On Jun 16, 11:10 pm, Maric Michaud <[EMAIL PROTECTED]> wrote: > Le Monday 16 June 2008 20:35:22 George Sakkis, vous avez écrit : > > > > > On Jun 16, 1:49 pm, Gerard flanagan <[EMAIL PROTECTED]> wrote: > > > George Sakkis wrote: > > > > I have

Re: Function argument conformity check

2008-06-18 Thread George Sakkis
is that using these attributes, I would essentially have > to re-write the logic python uses when calling a function with a given > set of arguments. I was hoping there is a way to get at that logic > without rewriting it. Sure; copy it from someone that has already done it ;-) http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/551779 HTH, George -- http://mail.python.org/mailman/listinfo/python-list

Re: extra positional arguments before optional parameters syntax

2008-06-18 Thread George Sakkis
end='\n', file=None): > > File "", line 1 > def f(*args, sep=' ', end='\n', file=None): >^ > SyntaxError: invalid syntax > > Am I misunderstanding something? Is this type of syntax suppose to be > allowed in a future version of Python? (I can&#x

Re: Ultimate Prime Sieve -- Sieve Of Zakiya (SoZ)

2008-06-18 Thread George Sakkis
ing type declarations and running it through Cython but the improvement was much less impressive than Psyco. I'm not a Pyrex/Cython expert though so I may have missed something obvious. George -- http://mail.python.org/mailman/listinfo/python-list

Null pattern

2008-06-19 Thread George Sakkis
s rich comparisons: Should Null > x be allowed and if so, what it should return ? Then again, perhaps Null is an inherently domain-specific notion and there are no general answers to such questions, in which case it doesn't make sense trying to define an all-purpose Null object. George -- http://mail.python.org/mailman/listinfo/python-list

Re: An idiom for code generation with exec

2008-06-20 Thread George Sakkis
acket): > data = packet[2:6] > data.reverse() > return data > > This gave me a huge speedup, because each field now had its specific > function sitting in a dict that quickly extracted the field's data > from a given packet. It's still not clear why the generic version is so slower, unless you extract only a few selected fields, not all of them. Can you post a sample of how you used to write it without exec to clarify where the inefficiency comes from ? George -- http://mail.python.org/mailman/listinfo/python-list

Re: Python "is" behavior

2008-06-20 Thread George Sakkis
lse > > Can anyone explain this further? Why does it happen? 8-bit integer > differences? No, implementation-dependent optimization (caching). For all we know, the next python version may cache up to 1024 or it may turn off caching completely; do not rely on it. More generally, do not use 'is' when you really mean '=='. George -- http://mail.python.org/mailman/listinfo/python-list

Re: Python "is" behavior

2008-06-20 Thread George Sakkis
On Jun 20, 12:45 pm, [EMAIL PROTECTED] wrote: > On Jun 20, 9:42 am, George Sakkis <[EMAIL PROTECTED]> wrote: > > > > > On Jun 20, 12:31 pm, [EMAIL PROTECTED] wrote: > > > > I am not certain why this is the case, but... > > > > >>>

Re: An idiom for code generation with exec

2008-06-20 Thread George Sakkis
On Jun 20, 3:44 pm, eliben <[EMAIL PROTECTED]> wrote: > On Jun 20, 3:19 pm, George Sakkis <[EMAIL PROTECTED]> wrote: > > > > > On Jun 20, 8:03 am, eliben <[EMAIL PROTECTED]> wrote: > > > > On Jun 20, 9:17 am, Bruno Desthuilliers > > >

Re: An idiom for code generation with exec

2008-06-21 Thread George Sakkis
% (i,i)") instead of using a regular dictionary. - Using function names instead of the actual function objects and calling eval(), not knowing that functions are first-class objects (or not even familiar with what that means). So even if your use case belongs to the exceptional 1% where dynamic code generation is justified, you should expect people to question it by default. George -- http://mail.python.org/mailman/listinfo/python-list

Re: Storing value with limits in object

2008-06-22 Thread George Sakkis
lue if isinstance(second, cls): if minmax is None: minmax = second.min,second.max second = second._value return cls(op(first,second), *minmax) a = Limited(11, 0, 9) print a+1 print 1+a print a-1 print 1-a Needless to say, this is almost two or

Re: Learning Python in a group

2008-06-22 Thread George Oliver
the same situation as you and think a co-op method of learning could be effective and fun. I found the Tutor list that David mentioned a little while ago but also have been looking for a group (without success so far). So count me in! best, George -- http://mail.python.org/mailman/listinfo/python-list

Re: extend getattr()

2008-06-26 Thread George Sakkis
es? > > You could do it manually: > > c = getattr(getattr(a, 'b'), 'c') > > or make it automatic: > > def get_dotted_attr (obj, dotted_attr) : > for attr in dotted_attr.split('.') : > obj = getattr(obj, attr) >

2D online multiplayer framework?

2008-06-28 Thread George Oliver
play this through a web browser but I don't know if that's practical. This aspect of programming is pretty new to me so I'm not sure if I should start with something general like Twisted or if there's a different path I should take. thanks, George -- http://mail.python.or

Re: 2D online multiplayer framework?

2008-06-28 Thread George Oliver
On Jun 28, 9:04 am, Gary Herron <[EMAIL PROTECTED]> wrote: > > Pyglet is my favorite: http://www.pyglet.org/ > > Twisted might be fine for the "online multiplayer" parts, but really if > you want a 2D/3D real-time game, start with a game framework. > > Gary Herron Thanks Cédric and Gary for the s

Re: How do web templates separate content and logic?

2008-06-30 Thread George Sakkis
little presentational logic and (ideally) no business logic. Now, if all one wants to do is a quick and dirty way to, say, view a log file in the browser, a separate template is probably an overkill; there's nothing wrong with something like "for line in logfile: print cgi.escape(line.strip()) + ''". It's a matter of relative frequencies which language is the embedded one. George -- http://mail.python.org/mailman/listinfo/python-list

Re: How to pickle bound methods

2008-07-02 Thread George Sakkis
tw, you use the terminology backwards: the client calls a method on a remote server and the server executes it and returns back the results to the client. George [1] http://pyro.sourceforge.net/ -- http://mail.python.org/mailman/listinfo/python-list

Re: How do web templates separate content and logic?

2008-07-02 Thread George Sakkis
On Jun 30, 3:16 pm, Mike <[EMAIL PROTECTED]> wrote: > On Jun 30, 1:41 pm, George Sakkis <[EMAIL PROTECTED]> wrote: > > > > > Because _typically_ a web template consists of mostly HTML, with > > relatively little presentational logic and (ideally) no business &g

Re: Generating list of possible configurations

2008-07-03 Thread George Sakkis
pet module is not available yet. You will probably sound less negative if you refrain from projecting your own very specialized needs to those of the average pythonista. George -- http://mail.python.org/mailman/listinfo/python-list

Re: Singleton implementation problems

2008-07-03 Thread George Sakkis
ass X(Singleton): def __init__(self, a): self.a = a assert X(1) is X(2) Note however that the classic Singleton pattern is usually frowned upon in Python; the preferred approach is to use (module level) globals. Also search for the "Borg pattern". George -- http://mail.python.org/mailman/listinfo/python-list

Re: Generating list of possible configurations

2008-07-03 Thread George Sakkis
On Jul 3, 7:51 pm, Mensanator <[EMAIL PROTECTED]> wrote: > On Jul 3, 6:24 pm, George Sakkis <[EMAIL PROTECTED]> wrote: > > > Taking into account 2.6 too (we're not talking about only 3.0 here), > > probably not much less than those who even know what is gmpy,

Re: Dynamically Changing the Base Class

2008-07-07 Thread George Sakkis
m > 'object' > snip > > Is there a solution I am missing? > > Thanks in advance. Supposedly it should (usually) work, there's a 6 year old patch for this (http://bugs.python.org/issue635933). C

Re: Moving to functional programming

2008-07-11 Thread George Sakkis
x27;s map(itemgetter(0), tuple_list) since itemgetter() is a high order function (more specifically, a function that returns another function). The list comprehension is still the most pythonic approach though. Regards, George -- http://mail.python.org/mailman/listinfo/python-list

sending input to an embedded application

2008-07-12 Thread George Oliver
d pass along input, and receive and display the output? thanks, George -- http://mail.python.org/mailman/listinfo/python-list

Re: iterating "by twos"

2008-07-29 Thread George Trojan
kj wrote: Is there a special pythonic idiom for iterating over a list (or tuple) two elements at a time? I mean, other than for i in range(0, len(a), 2): frobnicate(a[i], a[i+1]) ? I think I once saw something like for (x, y) in forgotten_expression_using(a): frobnicate(x, y) Or may

Re: list question... unique values in all possible unique spots

2008-08-09 Thread George Sakkis
gt; 1-9 in any possible order. Here it's 1-26. Search for a permutation generator function. George -- http://mail.python.org/mailman/listinfo/python-list

ANN: papyros 0.2

2008-08-11 Thread George Sakkis
I am pleased to announce papyros-0.2, the second alpha release of papyros: http://code.google.com/p/papyros/. Compared to the initial release 14 months ago, only the basic goal has remained the same; both the API and the internals have been thoroughly revamped. Some of the highlights are: - As sim

Re: Passing function objects to timeit

2008-03-30 Thread George Sakkis
n is worse than the problem! > > > Perhaps it's time for me to take a different approach. > > [snip] > > Maybe the following enhancement of timeit would be worthwhile? [snip] That would be great. I sometimes avoid timeit altogether because setting up the environment is

Re: Dispatching functions from a dictionary

2008-03-30 Thread George Sakkis
variate(1), etc. In Python 2.5, you can also write this as: from functools import partial RVDict = {'1': partial(random.betavariate,1,1), '2': partial(random.expovariate,1), etc. George -- http://mail.python.org/mailman/listinfo/python-list

Re: Passing function objects to timeit

2008-03-31 Thread George Sakkis
On Mar 31, 6:15 am, Peter Otten <[EMAIL PROTECTED]> wrote: > George Sakkis wrote: > > On Mar 30, 9:03 am, Peter Otten <[EMAIL PROTECTED]> wrote: > >> Steven D'Aprano wrote: > >> > On Sun, 30 Mar 2008 01:27:18 -0300, Gabriel Genellina wrote: > >

Re: troll poll

2008-03-31 Thread George Sakkis
they spark some really > interesting and serious subthreads, while the nonsense of castironpi is > just irritating noise. Which is exactly why there are rarely any replies to his random gibberish, so I would say that he/she/it has almost no effect on c.l.py. Yet I wish plonking was possible thr

Re: class super method

2008-03-31 Thread George Sakkis
it, or at least stick to its basic usage. George [1] http://www.phyast.pitt.edu/~micheles/python/super.html [2] http://fuhm.net/super-harmful/ -- http://mail.python.org/mailman/listinfo/python-list

Re: python persistence

2008-03-31 Thread George Sakkis
On Mar 31, 8:51 pm, [EMAIL PROTECTED] wrote: > On Mar 31, 7:14 pm, 7stud <[EMAIL PROTECTED]> wrote: > > > > > On Mar 31, 5:31 pm, [EMAIL PROTECTED] wrote: > > > > Can you have a Python object stored entirely on disk? > > > import cPickle as cp > > > class Dog(object): > > def __init__(self, nam

Re: troll poll

2008-04-01 Thread George Sakkis
On Apr 1, 5:43 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > Delaney, Timothy (Tim) wrote: > > George Sakkis wrote: > > >> On Mar 31, 1:46 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > > >>>> More

Re: class super method

2008-04-01 Thread George Sakkis
On Mar 31, 10:41 pm, Ed Leafe <[EMAIL PROTECTED]> wrote: > On Mar 31, 2008, at 5:58 PM, George Sakkis wrote: > > >> is there any tutorial for super method (when/how to use it)? > > >> or maybe someone could explain me how it works? > > >> thx > >

Re: class super method

2008-04-01 Thread George Sakkis
On Apr 1, 10:21 am, Ed Leafe <[EMAIL PROTECTED]> wrote: > On Apr 1, 2008, at 8:43 AM, George Sakkis wrote: > > Pehaps, at least as long as you make sure that all superclasses have a > > compatible signature - which in practice typically means accept > > arbitrary *args

Re: generator functions: why won't this work?

2008-04-01 Thread George Sakkis
he result, you discard it as soon as it is returned. What you have to do is iterate over the returned iterable and yield its values: # don't need parentheses around the if expression if isinstance(arg, tuple): for scalar in getNextScalar(arg): yield scalar Hope this helps, George -- http://mail.python.org/mailman/listinfo/python-list

Re: generator functions: why won't this work?

2008-04-01 Thread George Sakkis
On Apr 1, 11:17 pm, George Sakkis <[EMAIL PROTECTED]> wrote: > On Apr 1, 10:56 pm, [EMAIL PROTECTED] wrote: > > > > > Hi all, > > > I'm trying to understand generator functions and the yield keyword. > > I'd like to understand why the following co

Re: Self-referencing decorator function parameters

2008-04-02 Thread George Sakkis
teMe class (although the class itself is not built yet). A subtle point is that in this case callMe is a plain function, not an (unbound) method such as DecorateMe.callMe. This may or may not matter, depending on what you do with it in the decorator. Some decorators that work fine with plain functions break if they are used to decorate methods (or vice versa) so it's good to have this in mind when writing or debugging a decorator. George -- http://mail.python.org/mailman/listinfo/python-list

Re: Manipulate Large Binary Files

2008-04-02 Thread George Sakkis
te(buff) > if len(buff) != buffsize: > break Or more idiomatically: from functools import partial for buff in iter(partial(INPUT.read, 10 * 1024**2), ''): # process each 10MB buffer George -- http://mail.python.org/mailman/listinfo/python-list

Re: april fools email backfires

2008-04-02 Thread George Sakkis
On Apr 2, 1:23 pm, Paul Rubin wrote: > Aaron Watters <[EMAIL PROTECTED]> writes: > > Grapevine says that an architect/bigot at a java/spring shop sent > > out an April Fools email saying they had decided to port everything > > to Django ASAP. > > > Of course the email was

Re: april fools email backfires

2008-04-02 Thread George Sakkis
On Apr 2, 1:29 pm, Grant Edwards <[EMAIL PROTECTED]> wrote: > On 2008-04-02, Paul Rubin wrote: > > > Django, pah.  They should switch to something REALLY advanced: > > >http://www.coboloncogs.org/INDEX.HTM > > ROTFLMAO! > > That's absolutely brilliant!  I particularly like the flashing > effect th

Re: Manipulate Large Binary Files

2008-04-02 Thread George Sakkis
def iterchunks(filename, buffering): return iter(partial(open(filename,buffering=buffering).read, buffering), '') for chunk in iterchunks(filename, 32*1024): pass #for chunk in iterchunks(filename, 1024**2): pass #for chunk in iterchunks(filename, 10*1024**2): pass George -- http://mail.python.org/mailman/listinfo/python-list

Re: Recursive function won't compile

2008-04-02 Thread George Sakkis
thon, but some weird cross-breed > beteween python and C - who are we to judge the semantics of that chimera? > > Diez Seems like a bad belated April Fool's day joke to me. George -- http://mail.python.org/mailman/listinfo/python-list

Re: Efficient way of testing for substring being one of a set?

2008-04-03 Thread George Sakkis
for x in substrings)).search p = search(somestring) if p is not None: print 'Found', p.group() George -- http://mail.python.org/mailman/listinfo/python-list

Re: Efficient way of testing for substring being one of a set?

2008-04-03 Thread George Sakkis
gt; >>> True in (word in name for word in words) > > > False > > > Perhaps not as obvious or readable as Jeff's example, but is > > essentially doing the same thing using generator syntax. > > That's pretty :) It's even prettier in 2.5: any(word in name for word in words) George -- http://mail.python.org/mailman/listinfo/python-list

Re: id functions of ints, floats and strings

2008-04-03 Thread George Sakkis
nts can be changed at will?) No. Regards, George -- http://mail.python.org/mailman/listinfo/python-list

Re: collecting results in threading app

2008-04-04 Thread George Sakkis
results are done ? Again there are several alternatives, but Python 2.5 adds two convenient Queue methods for this, task_done() and join(). Check out the example at the bottom of the Queue doc page [2] to see how it works. HTH, George [1] http://docs.python.org/lib/module-Queue.html [2] http://docs.python.org/lib/QueueObjects.html -- http://mail.python.org/mailman/listinfo/python-list

Tokenizer inconsistency wrt to new lines in comments

2008-04-04 Thread George Sakkis
( ... # hello world ... ) ... ''' >>> >>> for t in generate_tokens(StringIO(text).readline): ... print repr(t[1]) ... '\n' '# hello world\n' 'x' '=' '(' '\n' '# hello world' '\n' ')' &

Re: collecting results in threading app

2008-04-04 Thread George Sakkis
try: # try to get the result count = job.result except Exception, ex: # some exception was raised when executing this job print '* Exception raised for table %s: %s' % (table_name, ex) else: # jo

<    8   9   10   11   12   13   14   15   16   >