Re: Gateway to python-list is generating bounce messages.

2008-09-16 Thread Maric Michaud
Le Monday 15 September 2008 16:45:12 Maric Michaud, vous avez écrit : > This is not sufficient for auto-responses, and given the following rfcs, it > would smart to both : > ... > - add or modify the Return-Path and/or Reply-To header for badly > implemented auto-responders t

Re: Case-insensitive string compare?

2008-09-16 Thread Maric Michaud
Le Friday 05 September 2008 19:36:56 Fredrik Lundh, vous avez écrit : > Maric Michaud wrote: > > I suspect you are coming to conclusions a bit quickly, without taking the > > pain of understanding the whole discussion. > > I'm pretty sure I was the first one to post an an

Re: literals optimization (was Re: append on lists)

2008-09-16 Thread Maric Michaud
ame integer in some implementation is unrelated to the original problem. -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: literals optimization (was Re: append on lists)

2008-09-16 Thread Maric Michaud
Le Tuesday 16 September 2008 16:57:26 Grant Edwards, vous avez écrit : > On 2008-09-16, Maric Michaud <[EMAIL PROTECTED]> wrote: > > Le Tuesday 16 September 2008 15:57:53 Grant Edwards, vous avez écrit : > >> On 2008-09-16, Maric Michaud <[EMAIL PROTECTED]> wrot

Re: append on lists

2008-09-16 Thread Maric Michaud
Le Tuesday 16 September 2008 15:57:53 Grant Edwards, vous avez écrit : > On 2008-09-16, Maric Michaud <[EMAIL PROTECTED]> wrote: > > all expressions that return something, return a new object, > > That's not _quite_ true: > >>> a=1 > >>> b=

Re: Retrieving the name of the class calling an instance method

2008-09-05 Thread Maric Michaud
foo() > f.someMethod() > > class again(): > def __init__(self): > f = foo() > f.someMethod() > > bar() > again() > --- -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Case-insensitive string compare?

2008-09-05 Thread Maric Michaud
Le Friday 05 September 2008 16:00:39 J. Cliff Dyer, vous avez écrit : > Please keep the discussion on-list. > Sorry for the private email, I sent it again to the list.. > On Fri, 2008-09-05 at 15:36 +0200, Maric Michaud wrote: > > Le Friday 05 September 2008 14:33:22 J. Clifford

Re: Case-insensitive string compare?

2008-09-05 Thread Maric Michaud
e keys are case-sensitive, so this is not an option, the only way to do it fast is to index upon insertion all keys in another dict, so you get in final : d = { "kEy1" : 1, "Key1" : 2} indexes = { "key1" : ["kEy1", "Key1" ] } > Cheers, > Cliff > > > -- > http://mail.python.org/mailman/listinfo/python-list -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Core dumped while interacting with OpenOffice.org via pyuno

2008-09-05 Thread Maric Michaud
here something else I should do in order to have more clues > ("Read The Fine Manual (tm)" is an acceptable answer) You can try to find which function call exactly provoke the exception, the simplest way is to trace execution flow with some print statments and using non forking zope ins

Re: Case-insensitive string compare?

2008-09-05 Thread Maric Michaud
Le Friday 05 September 2008 08:24:29 Fredrik Lundh, vous avez écrit : > Maric Michaud wrote: > > "premature optimization is the root of all evil" > > So is use by that statement by people who don't have the slightest idea > about what it actually means. >

Re: Case-insensitive string compare?

2008-09-05 Thread Maric Michaud
Le Friday 05 September 2008 08:30:44 Fredrik Lundh, vous avez écrit : > Maric Michaud wrote: > > You''ll often see for loops written like this : > > > > for i in (e for e in iterable if predicate(e)) : > > ... > > luckily, I don't. most peop

Re: Case-insensitive string compare?

2008-09-04 Thread Maric Michaud
.lower()] = (key,whatever) > "premature optimization is the root of all evil" I don't recall the OP wanted a (a bit) faster solution to his problem in counterpart of memory loss and syntax complication. If the OP's proposal seems already messy, how about ths one : if lib.lower() not in ( e[0] for e in stage_map.items() ) : ... > - Chris > > > -- > > http://mail.python.org/mailman/listinfo/python-list -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Case-insensitive string compare?

2008-09-04 Thread Maric Michaud
an one brain cycle to achieve. Try the regexp solution and make your choice, more than often, I keep the straightforward, "read as pseudo-code", python expression. -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: why is self not passed to id()?

2008-09-04 Thread Maric Michaud
Le Thursday 04 September 2008 23:35:18 Terry Reedy, vous avez écrit : > Maric Michaud wrote: > > Le Thursday 04 September 2008 22:26:53 Ruediger, vous avez écrit : > >> class foo(list): > >>     __hash__ = lambda x: id(x) > > > > Wow ! You are really going on

Re: why is self not passed to id()?

2008-09-04 Thread Maric Michaud
[EMAIL PROTECTED]:~> python test01.py > Traceback (most recent call last): > File "test01.py", line 9, in > _s_.add(bar()) > TypeError: id() takes exactly one argument (0 given) > > -- > http://mail.python.org/mailman/listinfo/python-list -- _

Re: overwrite set behavior

2008-09-04 Thread Maric Michaud
ay to go is one like Diez show you in a previous post. >  >>> class foo(set): > ...  def __contains__(self, value): > ...   print value > ... >  >>> a = foo((1,2)) >  >>> -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: cPickle

2008-09-04 Thread Maric Michaud
>>>[1]: import shelve >>>[2]: s = shelve.open('db') >>>[3]: for name, value in s.items() : print name, value ...: b 4.0 a 5 c ('foo', 'bar') >>>[5]: del s['b'] >>>[6]: s['c'] += ('baz',) &g

Re: properties setting each other

2008-09-03 Thread Maric Michaud
it's an optimization problem, duplicating such a data is a caching mechanism, and should be done knowingly, in acceptance of all the complication it comes with. -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: properties setting each other

2008-09-03 Thread Maric Michaud
self._val=val value = property(fgetvalue, fsetvalue) def fgetsquare(self): return self.value ** 2 def fsetsquare(self,s): self.value = math.sqrt(s) square = property(fgetsquare, fsetsquare) -- _ Maric Michaud -- http

Re: properties setting each other

2008-09-03 Thread Maric Michaud
Le Wednesday 03 September 2008 16:44:10 Maric Michaud, vous avez écrit : >          def _setsquare(self, v) : >                  # some extra logic here >                  self._square = s > >          def fsetsquare(self,s): >                  self._setsquare(s) >          

Re: properties setting each other

2008-09-03 Thread Maric Michaud
def fsetsquare(self,s): self._setsquare(s) self._setvalue = math.sqrt(s) def _setvalue(self, val): # some extra logic here self._internalval=val def fsetvalue(self, val): self._setvalue(val)

Re: Multiple values for one key

2008-08-28 Thread Maric Michaud
ert into 'table1' values (?, ?)", ('ddd', '4 street')).rowcount ...[114]: 1 >>>[115]: for i in db.execute("select * from 'table1' where name like '___'") : print i .: (u'ddd', u'3 street') (u'ddd', u'4 street') >>>[116]: db.execute("insert into 'table1' values (?, ?)", ('ddd', '4 street')).rowcount --- IntegrityErrorTraceback (most recent call last) /home/maric/ in () IntegrityError: columns name, address are not unique > > Steve > [EMAIL PROTECTED] > -- > http://mail.python.org/mailman/listinfo/python-list -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Multiple values for one key

2008-08-27 Thread Maric Michaud
ctures in pure python), but what would be the syntax for modifying an existing value, for example, what should be the result of two consecutive assignements ? d[5] = None d[5] = 0 d[5] == [ None, 0 ] ?? What exactly are you trying to achieve ? -- _ Maric Michaud -- http://mail.py

Re: import error between 2 modules

2008-08-27 Thread Maric Michaud
self.worker.answerCall(message) if __name__ == "__main__": emp=Employer() emp.callWorker("report to work") workmodule.py -- class Worker: def __init__(self, employer): from empmodule import Employer if not isinstance(

Re: generate methods at runtime, but the wrong one gets called

2008-08-25 Thread Maric Michaud
ng for too long to see it. > > http://mail.python.org/pipermail/python-list/2007-June/446601.html > shows a somewhat comparable constellation and it was a good guideline. > But there, the function is created by the class factory, as well and I > unfortunately can't do that. > > Thank you very much, > > Steve > -- > http://mail.python.org/mailman/listinfo/python-list -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: recursively change values in list of lists

2008-08-24 Thread Maric Michaud
hints, and/or suggestions are greatly appreciated, > > > Carson > -- > http://mail.python.org/mailman/listinfo/python-list -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: What is class method?

2008-08-24 Thread Maric Michaud
; It is a common advice that staticmethod should not exist in python, as they do nothing compared to module level functions, and we should always use classmethods in place of them. > -- > Thank you for your time. > -- > http://mail.python.org/mailman/listinfo/python-list -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Imports visibility in imported modules problem

2008-08-24 Thread Maric Michaud
stated anything > > that appears to be a problem with how Python works. If two different > > modules import the same third module, there is no big performance > > penalty. The initialization code for the third module is only > > executed on the first import, and the cost of havi

Re: A variables variables

2008-08-24 Thread Maric Michaud
quot;easy" >>>[156]: var2 = "proper" >>>[157]: var3 = "locals" >>>[158]: print "a %(var2)s and %(var1)s use of %(var3)s with %(var3)s()" % locals() a proper and easy use of locals with locals() -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Filling in Degrees in a Circle (Astronomy)

2008-08-22 Thread Maric Michaud
= float(b[1] - a[1]) / (b[0] - a[0]) return [ slope * float(i) for i in xrange(b[0]-a[0] + 1) ] : >>>[23]: interpolate((0, 0), (180, 45)) ...[23]: [0.0, 0.25, 0.5, 0.75, 44.5, 44.75, 45.0] >>>[29]: interpolate((80, 20), (180, 45)) [0.0, 0.25, 0.5, 0.75,

Re: exception handling in complex Python programs

2008-08-22 Thread Maric Michaud
Le Friday 22 August 2008 15:03:21 Bruno Desthuilliers, vous avez écrit : > Maric Michaud a écrit : > > Le Thursday 21 August 2008 09:34:47 Bruno Desthuilliers, vous avez écrit : > >>> The point > >>> is that EAFP conflicts with the interest of reporting errors as

Re: exception handling in complex Python programs

2008-08-22 Thread Maric Michaud
rollback unwanted changes, and application logic to continue execution the right way. This is hard to do in C because you have no way to trap an error which happen randomly in the program, ie. a segfault will interrupt the execution anyway. -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: help with parsing email

2008-08-18 Thread Maric Michaud
access emails directly on the Exchange server via standard python modules poplib or imaplib, my preferred choice if one of these protocols are supported by your environment. You won't need no extensions, just a standard python installation, and your code will work with most mail deliv

Re: Python does not get environment variable when using cron.

2008-08-18 Thread Maric Michaud
-l -c ..., the -l option forces a login shell even in non-interactive session. -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: print "%s"

2008-08-18 Thread Maric Michaud
h > > string except the first. > > Or use the str.join method: > > print "\t".join(list("avtRsf")) > Not related to OP's question, but why one would want to convert a string to a list to make it iterable ? >>>[3]: print '\t'.join('azerty') a z e r t y > -- > http://mail.python.org/mailman/listinfo/python-list -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Dynamically defined functions via exec in imported module

2008-08-16 Thread Maric Michaud
provided by the user, this is legal and perfect use of exec because here the user is a trusted one (the programer himself). I'd say that everywhere exec/eval are used in a application/function/lib that doesn't mean to interpret arbitrary and user provided python code, it is a bad usage.

Re: Trying ZODB, background in Relational: mimic auto_increment?

2008-08-15 Thread Maric Michaud
on most application. But, > The problem is more complex than you think. > Not that complex, strength of ZODB is right here, this entirely covered by the introduction to zodb (ZODB/ZEO programming guide), see userdb and chatter examples. > Christian > > -- > http://mail.python.o

Re: Why nested scope rules do not apply to inner Class?

2008-08-13 Thread Maric Michaud
Calvin Spealman a écrit : On Wed, Aug 13, 2008 at 7:41 PM, Maric Michaud <[EMAIL PROTECTED]> wrote: I was not aware of any "nested classes are unsupported" before and didn't consider nested classes as bad practice till now, even with the pickle limitation (not every cla

Re: Why nested scope rules do not apply to inner Class?

2008-08-13 Thread Maric Michaud
without introducing a subtle incompatibility with actual code. This is exactly this case which would be a problem (your example raise an error and is not exactly a "running code"): G = 1 class A(object) : G = 0 def f(self) : return G -- _ Maric Michaud -- http://m

Re: Why nested scope rules do not apply to inner Class?

2008-08-13 Thread Maric Michaud
a in range(5) for b in l) (2) This won't work as it would with nested functions, you need to build the new calss directly with type('dynamic', (object,), {"type_": type_}) def create_type(type_) : class dynamic(object) : type_ = type_ return dynamic -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Why nested scope rules do not apply to inner Class?

2008-08-12 Thread Maric Michaud
, 6, 7, 8] >>>[78]: class A(object) : l = list( a for a in range(5) ) m = list( e + f for f in range(5) for e in l ) : : ------- NameError Traceback (most recent call last) /home/maric/ in () /home/maric/ in A() /home/maric/ in ((f,)) NameError: global name 'l' is not defined -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: simple error i hope

2008-08-01 Thread Maric Michaud
e_, file) won't work anymore if you do so. -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Strong/weak typing

2008-08-01 Thread Maric Michaud
nk of the following lines : a, b = 0, 1 a += b a, b = b, a s = "foo" s = s.upper() -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Difference between type and class

2008-07-31 Thread Maric Michaud
here. > >>> int > > > > >>> myint > > > > despite int and myint having the same metaclass. So if the > representation is really defined in the 'type' metaclass, then > type.__repr__ has to make some kind of distinction between int and > myint, so they cannot be on absolute equal footing. You're right, type(int) is type, the way it renders differently is a detail of its implementation, you can do things with builtin types (written in C) you coudn't do in pure python, exactly as you couldn't write recursive types like 'object' and 'type'. -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Difference between type and class

2008-07-31 Thread Maric Michaud
Le Thursday 31 July 2008 16:46:28 Nikolaus Rath, vous avez écrit : > Maric Michaud <[EMAIL PROTECTED]> writes: > >> > Can someone explain to me the difference between a type and a class? > >> > >> If your confusion is of a more general nature I suggest r

Re: Difference between type and class

2008-07-31 Thread Maric Michaud
ey can be instantiated and they produce objects (ordinary object in general) with theirslef as a type. - metatypes or metaclass, are subclasses of "type", their instances are new types. For all tjis work together you must admit the following recursivity : 'type' is both a

Re: Difference between type and class

2008-07-31 Thread Maric Michaud
at the means is that int is not a user type but a builtin type, instances of int are not types (or classes) but common objects, so its nature is the same as any classes. The way it prints doesn't matter, it's just the __repr__ of any instance, and the default behavior for instances of type is to return '', but it can be easily customized. >>>[1]: class A(object) : ...: class __metaclass__(type) : ...: def __repr__(self) : return "" ...: ...: >>>[2]: A ...[2]: >>>[3]: type('toto', (object,), {}) ...[3]: -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Standard module for parsing emails?

2008-07-30 Thread Maric Michaud
Le Wednesday 30 July 2008 19:25:31 Diez B. Roggisch, vous avez écrit : > Maric Michaud wrote: > > Le Wednesday 30 July 2008 17:55:35 Aspersieman, vous avez écrit : > >> For parsing the mails I would recommend pyparsing. > > > > Why ? email module is a great parser I

Re: Standard module for parsing emails?

2008-07-30 Thread Maric Michaud
Le Wednesday 30 July 2008 17:55:35 Aspersieman, vous avez écrit : > For parsing the mails I would recommend pyparsing. Why ? email module is a great parser IMO. -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Standard module for parsing emails?

2008-07-30 Thread Maric Michaud
x27;t respect RFCs (notably about encoding)... -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Pointers/References in Python?

2008-07-30 Thread Maric Michaud
>>[61]: b, c ...[61]: ([[1, 0], 3], [[1, 0]]) This is if you want to make a true copy (called deep copy) that you'll have to do extra steps (using copy module for example). -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Maric Michaud
ist). And a reader would probably not see your intention here (he already expect a scalar due to the name of the variable). This is exactly the problem ABC is intended to solve. Without ABC, to explicitly ensure amount is a scalar, just doing a int(amount) or int(abs(amount)) if you want to deal

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Maric Michaud
also wrong assuming that because amount compare to zero, it can be added to sample. If you want to make type checking just check the type or convert your parameter to an int, but the test "== 0" is of no help here. The only valuable point I see for this idiom is to make more explicit I

Re: multiple inheritance and __getattr__

2008-07-29 Thread Maric Michaud
e) def __getattr__(self, name) : try : return old_one(self, name) except AttributeError : try : g = super(class_, self).__getattr__ except : raise AttributeError('no more __getattr__') return g(name) if not getattr(C, '_C_fixed__', False) : C._C_fixed__ = C.__getattr__ C.__getattr__ = collaborative_getattr(C, '_C_fixed__') That said, if your class C is a real facade for its ancestors A and B (A and B won't appear at all in the hierarchies of your subclasses), your solution is near the best one in terms of simplicity-efficiency. I said near the best one because your __getattr__ isn't collaborative yet ! :). -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Where is the correct round() method? Use math.ceil

2008-07-28 Thread Maric Michaud
8999 >>>[29]: 0.51 ...[29]: 0.51001 >>>[28]: 1.1 ...[28]: 1.1001 >>>[35]: round(0.5) ...[35]: 1.0 -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: sub typing built in type with common attributes. Am I right?

2008-07-18 Thread Maric Michaud
-- AttributeErrorTraceback (most recent call last) /home/maric/ in () AttributeError: can't set attribute -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: (silly?) speed comparisons

2008-07-09 Thread Maric Michaud
The signature should be : vector move_slice(vector& vec, int start, int stop, int dest) or vector move_slice(vector& vec, int start, int stop, int dest) -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: List Performance

2008-06-30 Thread Maric Michaud
self.obj = obj def __len__(self) : return self.size def __iter__(self) : return itertools.repeat(self.obj, len(self)) : : -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: insertion sorts...

2008-06-30 Thread Maric Michaud
ist[:] = new_list" these are same i > think ? Not at all, try to figure out what happen with the following : >>>[3]: l=[] >>>[4]: g=[] >>>[5]: l == g ...[5]: True >>>[6]: l is g ...[6]: False >>>[7]: l = [4] >>>[8]: l is g ...[8]: False >>>[9]: l == g ...[9]: False >>>[10]: l = g >>>[11]: l is g ...[11]: True >>>[12]: l[:] = [4] >>>[13]: l == g ...[13]: True >>>[14]: l is g ...[14]: True >>>[15]: g ...[15]: [4] -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: List Performance

2008-06-30 Thread Maric Michaud
ge, as a pure python optimization for dealing with long list, to replace an algorithm with a lot of append by something like this : mark = object() datas = [ mark ] * expected_size # working with the datas while maintaining the effective currrently used size Of course one could even subclass list

Re: Help with Borg design Pattern

2008-06-30 Thread Maric Michaud
need to have a logging procedure which queue the message waitinig for system to be operational and deliver them lazily. This is quite an easy thing to implement (hint : use stdlib data structures that support multi threading from the beginning). -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: List Performance

2008-06-30 Thread Maric Michaud
s to be out of memory and begin to swap, while it's not, of course, an issue with python lists... -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Mako vs. Cheetah?

2008-06-27 Thread Maric Michaud
itor could modify them without breaking the logic of the template. -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: this is simple...

2008-06-27 Thread Maric Michaud
t b else: B.remove(b) .: .: 1 2 3 4 5 >>>[176]: B ...[176]: [1, 2, 3, 4, 5] Note that this can be easily done with the simpler : B = [ e for e in B if e*e not in A ] -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Help with Borg design Pattern

2008-06-27 Thread Maric Michaud
.py : ModuleOptions = {} othermodule.py : import mymodule mymodule.ModuleOptions['Verbose'] = True or if you think encapsulation is important : mymodule.py : _ModuleOptions = {} def get_option(opt) : return _ModuleOptions[opt] And you're done. -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Do I need "self" and "other"?

2008-06-27 Thread Maric Michaud
s rather ugly. Finally, to come to a more functionnal style the method could have been written like this : from itertools import izip ... def __add__(self, other) : return Vector(x + y for x, y in izip(self, other)) -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Use of the "is" statement

2008-06-27 Thread Maric Michaud
d be written "f.tell()" and "not f.tell()" in python. if not f.tell() : print 'at the beginning of the file" -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: using urllib2

2008-06-27 Thread Maric Michaud
sub('<.+?>', '', e) for e in re.findall('.*?', res) ] ...[229]: ['Python Gallery', 'Coffret Monty Python And Co 3 DVD : La Premi\xe8re folie des Monty ...', 'Re: os x, panther, python & co: msg#00041', 'Re: os x, panth

Re: Email Bounce Detection

2008-06-27 Thread Maric Michaud
e.get_payload() : ....: if i.get_content_type() == 'message/delivery-status' : : print i.get_payload()[1]['status'] : : 5.0.0 -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Freeze problem with Regular Expression

2008-06-25 Thread Maric Michaud
rackets is the character '|', so there is no reason for it to appears twice. Very complicated regexps are always evil, and a two or three stage filtering is likely to do the job with good, or at least better, readability. But once more, what are you trying to do ? This is not even clear that regexp matching is the best tool for it. -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: binary representation of an integer

2008-06-24 Thread Maric Michaud
looping with a hex->bin lookup table > would be probably much faster than the general baseconvert from the > recipe. > > What do you think? Something like that, less typing with octal conversion :) >>>[8]: oct2bin = {'0':'000', '

Re: An idiom for code generation with exec

2008-06-23 Thread Maric Michaud
at import time to avoid the rather time consuming parsing stage. -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Fwd: xml to mysql (vice versa ) too

2008-06-23 Thread Maric Michaud
xml = """ """ In [89]: def print_nodes(node) : print node if node.attributes : for n, v in node.attributes.items() : print n, v for i in node.childNodes : print_nodes(i) : : In [94]: dom = parseString(xml) In [95]:

Re: Question: How do I format printing in python

2008-06-23 Thread Maric Michaud
print "%-6s %3s %2s %4s%-7s" % tuple(items) In python, str objects have a splitlines method for portability it is better, a shorthand for split(os.sep). -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: listcomprehension, add elements?

2008-06-23 Thread Maric Michaud
Le Monday 23 June 2008 13:51:34 John Machin, vous avez écrit : > On Jun 23, 9:16 pm, Maric Michaud <[EMAIL PROTECTED]> wrote: > > Le Monday 23 June 2008 11:39:44 Boris Borcic, vous avez écrit : > > > John Machin wrote: > > > > Instead of sum(a + b for a, b in zi

Re: listcomprehension, add elements?

2008-06-23 Thread Maric Michaud
provide sequences of datas as iterators when they can grow in size. -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: An idiom for code generation with exec

2008-06-23 Thread Maric Michaud
what "compilation" means in python, just don't use it, use closures or callable instances, there are many way to achieve this. -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Removing inheritance (decorator pattern ?)

2008-06-16 Thread Maric Michaud
Le Tuesday 17 June 2008 05:10:57 Maric Michaud, vous avez écrit : > The class complextiy problem is actually solved by : > > inst_with_alg1 = MyClassUsingStrategies((algo1_strategy,), > (algo1_strategy,)) inst_with_alg1_alg2 = MyClassUsi

Re: Removing inheritance (decorator pattern ?)

2008-06-16 Thread Maric Michaud
eth1(self, arg) : for i in self._meth1_strategies : i.do_init(...) for i in self._meth1_strategies : i.do_job(...) for i in self._meth1_strategies : i.do_finalize(...) ... The class complextiy problem is actually solved by : inst_with_alg1 = MyClassUsingStrategies((algo1_strategy,), (algo1_strategy,)) inst_with_alg1_alg2 = MyClassUsingStrategies( (algo1_strategy,), (algo2_strategy,) ) inst_with_alg12 = MyClassUsingStrategies( (algo1_strategy, algo2_strategy), (algo1_strategy, algo2_strategy) ) etc... -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: 'string'.strip(chars)-like function that removes from the middle?

2008-06-16 Thread Maric Michaud
one more step, can be considered as premature optimisation and the one liner : ''.join(e for in string_ if e not in 'chars') may be preferred. -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Summing a 2D list

2008-06-13 Thread Maric Michaud
Le Friday 13 June 2008 18:55:24 Maric Michaud, vous avez écrit : > > approximately the double amount of memory compared to the other. > > I don't see how you came to this conclusion. Are you sure the extra list > take twice more memory than the extra dictionary ? twice less

Re: Summing a 2D list

2008-06-13 Thread Maric Michaud
Hello, Le Friday 13 June 2008 17:55:44 Karsten Heymann, vous avez écrit : > Maric Michaud <[EMAIL PROTECTED]> writes: > > So, writing C in python, which has dictionnary as builtin type, > > should be considered "more elegant" ? > > IMO that's a bi

Re: Summing a 2D list

2008-06-13 Thread Maric Michaud
((u[r%3000], random.randint(0,1)) for r in range(5*10**6)) print "with list", do(c_list, u, v) print "with dict", do(c_dict, u, v) The result is pretty close now : [EMAIL PROTECTED] 17:04:36:~$ ./test.py with list 1.40726399422 with dict 1.63094091415 So why use list where the obvious and natural data structure is a dictionnary ? -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

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

2008-06-11 Thread Maric Michaud
cally, wether a program has bugs or not is not computable. Static analysis as they imply is just nonsense. AFAIK, the efforts needed to make good static analysis are proven, by experience, to be at least as time consuming than the efforts needed to make good unit and dynamic testing.

Re: catastrophic regexp, help!

2008-06-11 Thread Maric Michaud
Le Wednesday 11 June 2008 09:08:53 Maric Michaud, vous avez écrit : > "this is zlatan example.' > compare with 'this is zlatan example', 'z'=='.', false > compare with 'this is zlatan ', 'z'=='e', false > compare w

Re: catastrophic regexp, help!

2008-06-11 Thread Maric Michaud
hould do this according to regexcoach but it seems to send my computer into 100%CPU-power and not closable. """ In [172]: list(e[0] for e in re.findall("((\w+\s*)+)", s, re.M) if re.findall('zlatan\s+ibrahimovic', e[0], re.I)) Out[172]: ['i want to find a in a big string a sentence containing Zlatan\nIbrahimovic and some other text', 'ie return the first sentence containing the name Zlatan Ibrahimovic', 'zlatan ibrahimovic '] -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Can I find out (dynamically) where a method is defined?

2008-06-09 Thread Maric Michaud
if meth_name in ty.__dict__: > return ty > return None > > Cheers, > Allen > Oh ! you're just right, my first writing of this was : for m in 'a', 'b', 'c' : print [ t for t in type(i).mro() if m in t.__dict__ ] which I

Re: Can this be done with list comprehension?

2008-06-09 Thread Maric Michaud
http://mail.python.org/mailman/listinfo/python-list A one liner, though it's a bit lispy : list(itertools.chain((something,), (someMethod(i) for i in some_list))) -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Can I find out (dynamically) where a method is defined?

2008-06-09 Thread Maric Michaud
erence on this and "super", it worths the effort. -- _ Maric Michaud _ Aristote - www.aristote.info 3 place des tapis 69004 Lyon Tel: +33 4 26 88 00 97 Mobile: +33 6 32 77 00 21 -- http://mail.python.org/mailman/listinfo/python-list

Re: How to find the first space?

2008-06-09 Thread Maric Michaud
remember the last time I used re module in production code in python (unlike in perl or shell). > > Thanks > L. > -- > http://mail.python.org/mailman/listinfo/python-list -- _ Maric Michaud _ Aristote - www.aristote.info 3 place des tapis 69004 Lyon Tel: +33 4 26 88 00 97 Mobile: +33 6 32 77 00 21 -- http://mail.python.org/mailman/listinfo/python-list

Re: Decorator metaclass

2008-05-22 Thread Maric Michaud
each in dir(hbar.decorator()): print each hbar.decorator().p() hbar.decorator().inc() hbar.decorator().p() hb2 = HBar2(5) hb2.p() hb2.p2() hb2.inc() hb2.p() hb2.p2() hb2.inc2() hb2.p() hb2.p2() -- _ Maric Michaud _ -- http://mail.python.org/mailman/listinfo/python-list

Problem with generator expression and class definition

2007-12-07 Thread Maric Michaud
I faced a strange behavior with generator expression, which seems like a bug, for both python 2.4 and 2.5 : >>> class A : ... a = 1, 2, 3 ... b = 1, 2, 3 ... C = list((e,f) for e in a for f in b) ... Traceback (most recent call last): File "", line 1, in File "", line 4, in A

Re: How to clean a module?

2007-05-31 Thread Maric Michaud
ai a écrit : > It assumes that there is a module A which have two global variables X > and Y. If I run "import A" in the IDLE shell, then I can use A.X and > A.Y correctly. But if I want to change the module A and then delete > the variable Y, I find I can use A.Y just the same as before! It's unl

Re: Rats! vararg assignments don't work

2007-05-30 Thread Maric Michaud
samwyse a écrit : > George Sakkis wrote: >> On May 29, 11:33 pm, Matimus <[EMAIL PROTECTED]> wrote: >> >> >>> Your attemtp: >>> >>> [code] >>> first, rest = arglist[0], arglist[1:] >>> [/code] >>> >>> Is the most obvious and probably the most accepted way to do what you >>> are looking for. As for

Re: [B,IX] = sort(A,...) - Order for sort()-function

2007-05-29 Thread Maric Michaud
Orlando Döhring a écrit : > ... > A = [ 3 7 5 > 0 4 2 ]; > > # in Python: A = [[3,7,5],[0,4,2]] > > [B,IX] = sort(A,2) > > # sort by rows > > B = > 3 5 7 > 0 2 4 > > IX = > 1 3 2 > 1 3 2 > > # first line: 3 was formerly in the fi

Re: Is PEP-8 a Code or More of a Guideline?

2007-05-29 Thread Maric Michaud
Steve Howell a écrit : > --- Carsten Haese <[EMAIL PROTECTED]> wrote: > >> On Sun, 2007-05-27 at 07:30 +, OKB (not >> okblacke) wrote: >>> Underscores are harder to type than any >> alphanumeric character. >> >> This is a discussion about underscores versus >> capital letters d

Re: os.path.walk not pruning descent tree (and I'm not happy with that behavior?)

2007-05-28 Thread Maric Michaud
I'm really sorry, for all that private mails, thunderbird is awfully stupid dealing with mailing lists folder. Gabriel Genellina a écrit : > En Sun, 27 May 2007 22:39:32 -0300, Joe Ardent <[EMAIL PROTECTED]> escribió: > > > - iterate backwards: > > for i in range(len(names)-1, -1, -1): >f

Re: Is PEP-8 a Code or More of a Guideline?

2007-05-28 Thread Maric Michaud
Ben Finney a écrit : > Paul McGuire <[EMAIL PROTECTED]> writes: > >> It is a bit reassuring that I am not the only one who turns a blind >> eye to this part of the PEP, that l_c_w_u bothers others as well. > > I see similar support for lower_case, and opposition to > camelCase. It's nice that we'

Re: Can python create a dictionary from a list comprehension?

2007-05-28 Thread Maric Michaud
Pierre Quentel a écrit : > On 27 mai, 22:55, erikcw <[EMAIL PROTECTED]> wrote: >> Hi, >> >> I'm trying to turn o list of objects into a dictionary using a list >> comprehension. ... > > entries = dict([ (int(d.date.strftime('%m')),d.id) for d in links] ) > > With Python2.4 and above you can use a

Re: Basic Class/Instance Question

2007-05-23 Thread Maric Michaud
Alan Franzoni a écrit : > Il 23 May 2007 04:53:55 -0700, Siah ha scritto: > > [cut] > > No. > > It's because the *body* of the function gets evaluated every time the > function is called, while the *definition* of the function gets evaluated > just once, when the function is 'declared'. > > You

  1   2   3   >