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: [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: 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: 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: reading from sys.stdin

2007-04-12 Thread Maric Michaud
-20)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> f=open('txt') >>> for l in f : ... print l, ... print "rest : " + f.read() ... foo Traceback (most recent call last): File &qu

Re: Calling private base methods

2007-04-12 Thread Maric Michaud
ctically this is rarely needed). Python is alot about conventions, please read and follow the PEP 8 : http://www.python.org/dev/peps/pep-0008/ -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list

Re: reading from sys.stdin

2007-04-12 Thread Maric Michaud
tead of using the straightforward readline method ? >>> import sys >>> l=sys.stdin.readline() >>> while(l) : ... print l, ... l=sys.stdin.readline() -- _ Maric Michaud _ Aristote - www.aristote.info 3 place des tapis 69004 Lyon Tel: +

threading and multicores, pros and cons

2007-02-13 Thread Maric Michaud
uld be really appreciated. regards, -- _ Maric Michaud _ Aristote - www.aristote.info 3 place des tapis 69004 Lyon Tel: +33 426 880 097 Mobile: +33 632 77 00 21 -- http://mail.python.org/mailman/listinfo/python-list

Re: threading and multicores, pros and cons

2007-02-13 Thread Maric Michaud
it strong enough ? -- _____ Maric Michaud _ Aristote - www.aristote.info 3 place des tapis 69004 Lyon Tel: +33 426 880 097 Mobile: +33 632 77 00 21 -- http://mail.python.org/mailman/listinfo/python-list

Re: replacing substrings within strings

2007-02-14 Thread Maric Michaud
r > way of doing this? Why not : In [4]: s="010203040506" In [5]: print s[4:6] + s[2:4] + s[0:2] + s[6:] 030201040506 ? -- _ Maric Michaud _ Aristote - www.aristote.info 3 place des tapis 69004 Lyon Tel: +33 426 880 097 Mobile: +33 632 77 00 21 -- http://mail.python.org/mailman/listinfo/python-list

Re: threading and multicores, pros and cons

2007-02-14 Thread Maric Michaud
hreaded code take significantly longer to execute." Very interesting point, this is exactly the sort of thing I'm looking for. Any valuable link on this ? -- _ Maric Michaud _ Aristote - www.aristote.info 3 place des tapis 69004 Lyon Tel: +33 426 880 097 Mobile

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: Package that imports with name of dependent package

2006-05-13 Thread Maric Michaud
nal package): A/__init__.py A/B/__init__.py A/B/C.py X/__init__.py X/B/__init__.py X/B/C.py just write in X/__init__.py : import A.B.C, B.C A.B.C = B.C and all "from A.B import C" following an import of X will return X.B.C. This is how we "monkeypatch" products in Zope. -

Re: Large Dictionaries

2006-05-15 Thread Maric Michaud
Le Lundi 15 Mai 2006 19:24, Roy Smith a écrit : > d = {} > d.reserve (10*1000*1000) d={}.fromkeys(xrange(5*10**6)) ? -- _ Maric Michaud _ Aristote - www.aristote.info 3 place des tapis 69004 Lyon Tel: +33 426 880 097 -- http://mail.python.org/mailman/listinfo/

Re: Large Dictionaries

2006-05-15 Thread Maric Michaud
ill be probably big" but can't predict what keys will be in. -- _ Maric Michaud _ Aristote - www.aristote.info 3 place des tapis 69004 Lyon Tel: +33 426 880 097 -- http://mail.python.org/mailman/listinfo/python-list

Re: problem with namespaces using eval and exec

2006-05-16 Thread Maric Michaud
eval func (the local one is not in the scope of b defintion) try this : exec s // like exec s in globals(), locals() eval("b(2)") // like , eval("b(2)", globals(), locals()) or if you to keep this dictionnary as a specific scope in your appplication : exec s in ns eval(&q

Re: A better way of making subsclassing of built-in types stick for attributes?

2006-05-17 Thread Maric Michaud
s : s._x : setX = lambda s, v : setattr(s, '_x', mystr(v)) : X = property(getX, setX) : : In [14]: r=myrow() In [15]: r.X = 'toto' In [16]: r.X Out[16]: 'toto' In [17]: type(r.X) Out[17]: -- _ M

Re: Use of lambda functions in OOP, any alternative?

2006-05-23 Thread Maric Michaud
bute(self): return self._attr attr = vprop('Attribute') class Derived(Base): def getAttribute(self): return 2*self._attr -- _ Maric Michaud _ Aristote - www.aristote.info 3 place des tapis 69004 Lyon Tel: +33 426 880 097 -- http://mail.python.org/mailman/listinfo/python-list

Re: Bind an instance of a base to a subclass - can this be done?

2006-05-24 Thread Maric Michaud
('frwiki-20060511-abstract.xml') Out[20]: In [21]: myFile('frwiki-20060511-abstract.xml').myreadline() yo In [22]: -- _ Maric Michaud _ Aristote - www.aristote.info 3 place des tapis 69004 Lyo

Re: Why can't timedeltas be divided?

2006-05-24 Thread Maric Michaud
Le Jeudi 25 Mai 2006 00:07, Dan Bishop a écrit : > If I try to write something like: > >     num_weeks = time_diff / datetime.timedelta(days=7) because it has no meaning, what you want is : num_weeks = time_diff.days / 7 or num_weeks = (time_diff / 7).days -- _____ Mari

Re: Bind an instance of a base to a subclass - can this be done?

2006-05-25 Thread Maric Michaud
return td.days * 24* 3600 * 10**6 + td.seconds * 10 ** 6 + td.microseconds def toseconds(td) : return float(tomicroseonds(td)) / 10 ** 6 tominute, tohours, todays, toweeks, etc... and use float and int / and % operators. This is an easy and clean implementation IMHO. -- _

Re: Why can't timedeltas be divided?

2006-05-25 Thread Maric Michaud
define some helper functions like this : def tomicroseconds(td) : return td.days * 24* 3600 * 10**6 +   td.seconds * 10 ** 6 + td.microseconds def toseconds(td) : return float(tomicroseonds(td)) / 10 ** 6 tominute, tohours, todays, toweeks, etc... and use float and int / and % operat

Re: Use of lambda functions in OOP, any alternative?

2006-05-26 Thread Maric Michaud
elf.setattr(v) attr = property(fget=__gattr, fset=__sattr) But, this is too verbose for me, I would opt for the lambda syntax :). _ Maric Michaud _ Aristote - www.aristote.info 3 place des tapis 69004 Lyon Tel: +33 426 880 097 -- 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

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: 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: 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
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: 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: 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: 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: 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: 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
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: '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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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
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: 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
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: (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: 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: 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: 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: 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: 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: 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: 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: 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
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: 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: 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
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
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: 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: 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: 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: 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-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
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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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
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
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: 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: 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: 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 -- _

<    1   2   3   >