Re: Restricted Access

2006-07-11 Thread Maric Michaud
ble by providing a wrapper function for file and open (see the Guards.py module). IMO, it worth to be tried, and I don't see any other short-term, less hacky, solution. regards, -- _ Maric Michaud _ Aristote - www.aristote.info 3 place des tapis 69004 Lyon Tel: +33

Re: Accessors in Python (getters and setters)

2006-07-12 Thread Maric Michaud
hods. And in python the reverse can be true : class a(object) : def __init__(self, ro_attr) : self.__attr = ro_attr def _getAttr(self) : """A method which serves an attribute""" return self.__attr attr = property(_ge

Re: Editing File

2006-07-12 Thread Maric Michaud
class_)(val)) for class_, val in csv.reader(file('config.csv')) ] In [54]: [ (e, e.val) for e in l ] Out[54]: [(<__main__.Z object at 0xa76c218c>, 0), (<__main__.Z object at 0xa76c260c>, 1), (<__main__.Z object at 0xa76c256c>, '0'), (<__main__.Z object at

Re: help in xml and python

2006-07-13 Thread Maric Michaud
into a readable not one-liner code is left as an exercise :) In [117]: print xmloutput /home/moq/buc/2 mod2.py 200607131001 /home/moq/buc/1 mod2.py 200607131000 /home/moq/buc/1 mod3.py 200607131001

Re: Newbie doing lengthy initialization with Tkinter gui

2006-08-13 Thread Maric Michaud
: import thread In [34]: thread.start_new_thread(process, (p,)) and main.mainloop() Of course the last line is tricky, the thread should be started by the App(Tix.Tk) mainloop. > Pasi -- _____ Maric Michaud _ Aristote - www.aristote.info 3 place des tapis 69004 Lyo

Re: __LINE__ and __FILE__ functionality in Python?

2006-08-13 Thread Maric Michaud
rrentframe() In [48]: c.f_lineno Out[48]: 1 In [49]: c.f_code.co_filename Out[49]: '' Of course, in the console, these are not truly relevant. -- _ 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: __LINE__ and __FILE__ functionality in Python?

2006-08-13 Thread Maric Michaud
currentframe().f_code.co_filename) -- _ 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: selecting base class from user input

2006-08-14 Thread Maric Michaud
name) AttributeError: not defined or found in objects "work" In [49]: Lion().isA(Worker) Out[49]: False In [50]: Lion(Worker).isA(Worker) Out[50]: True In [51]: Lion(Worker).work() hard -- _ 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: Newbie doing lengthy initialization with Tkinter gui

2006-08-14 Thread Maric Michaud
start_new_thread(initFunc, params) Toplevel.mainloop(self) -- _ 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: convert a long string in binary

2006-08-22 Thread Maric Michaud
ry("testing string") > > Surely there are ways to make it shorter (But it's fast enough). > Maybe this one is more elegant : In [305]: trans = {} In [306]: for i in range(256) : .: trans[chr(i)] = ''.join(i & 2**j and '1' or '0

Re: Python and STL efficiency

2006-08-22 Thread Maric Michaud
figured with: ../src/configure -v --enable-languages=c,c++,java,fortran,objc,obj-c++,ada,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --program-suffix=-4.1 --enable-__cxa_atexit --enable

Re: Python and STL efficiency

2006-08-23 Thread Maric Michaud
Le mardi 22 août 2006 23:15, Fredrik Lundh a écrit : > Maric Michaud wrote: > > The problem here, is that the strings in the set are compared by value, > > which is not optimal, and I guess python compare them by adress ("s*n is > > s*n" has the same complexity than

Re: Python and STL efficiency

2006-08-23 Thread Maric Michaud
s address and then string equality. > Yes, furthermore, that is *exactly* what the python code is doing (see my other post to Fredrik). -- _ 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: Why do this?

2006-10-05 Thread Maric Michaud
O, one proof I see is that you forgot the spaces after periods in your first example, and it's even not easy to figure it out... In fact this is a typical case I replace the first by the second, when the string comes a little complex. -- _ Maric Michaud _ Aristote

Re: Subclassing built-in classes

2006-10-05 Thread Maric Michaud
ut what prevents to interpret literals as a call to __builtins__ objects and functions ? optimization ? what else ? -- _ 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: Subclassing built-in classes

2006-10-05 Thread Maric Michaud
feature of __builtin__ module IMO (at less I expected it to work like this when I first tried it). -- _ 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: Access to static members from inside a method decorator?

2006-10-05 Thread Maric Michaud
def f(self) :pass ...: @expose ...: def g(self) :pass ...: ...: exposed : g In [8]: class b(a) : ...: @expose ...: def h(self) :pass ...: ...: exposed : h -- _ Maric Michaud _ Aristote - www.aristote.info 3 place des tapis

Re: Subclassing built-in classes

2006-10-06 Thread Maric Michaud
t;...couldn't python (in theory)...", I was discussing if it would be possible for python (in some future version) to manage the literals so that they use the constructors in the __builtin__ module, I didn't say it works actually (I'm aware it's not the case). -- ___

Re: An algorithm problem

2006-05-31 Thread Maric Michaud
"elegant but not optimized" one. -- _________ 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: Best Python Editor

2006-05-31 Thread Maric Michaud
good IDE (didn't try Pydev). -- _____ 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: Function mistaken for a method

2006-06-01 Thread Maric Michaud
False i expect this is not what you want) -- _____ 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: Function mistaken for a method

2006-06-01 Thread Maric Michaud
Le Jeudi 01 Juin 2006 13:29, Maric Michaud a écrit : > this exactly the same as : > >    def f(self, val) : >        return x != 0 oops, def f(self, val) : return val != 0 -- _____ Maric Michaud _ Aristote - www.aristote.info 3 place des tapis 69

Re: Function mistaken for a method

2006-06-01 Thread Maric Michaud
ppens to return a bound method. I don't think it's about c-coded versus python-coded stuff, C1.f is a type, C2.f is a method. In [14]: class t : pass : In [15]: class u : : f = t : : In [16]: u().f() Out[16]: <__main__.t instance at 0xa795a9ec>

Re: Function mistaken for a method

2006-06-01 Thread Maric Michaud
class C2(C):    def __init__(self) : self.f = lambda x: x != 0 -- _____ 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: Function mistaken for a method

2006-06-01 Thread Maric Michaud
Le Jeudi 01 Juin 2006 15:36, Christophe a écrit : >        self.x = self.__class__.f(0) nope, this will result in a TypeError "unbound method must be called with instance as first argument" -- _____ Maric Michaud _ Aristote - www.aristote.info 3 place des tap

Re: An oddity in list comparison and element assignment

2006-06-01 Thread Maric Michaud
cs exists in python, it's the 'is' assertion. a is b and then, do what you want with a (or b), a is b remains True. THIS is the meaning of expr1 = expr2, but in computer science, this is not as important as it is in pure logic (most languages do not even provide the 'is&

Re: An oddity in list comparison and element assignment

2006-06-02 Thread Maric Michaud
) *is* e !!! this would not be very useful nor consistent I guess and prefer the one used in python : seq1 == seq2 => for all e in seq1, seq2[seq1.index(e) == e -- _ 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: how to define a static field of a given class

2006-06-02 Thread Maric Michaud
l override VAL in the instance : In [2]: t=toto() In [3]: t.VAL=4 In [4]: toto.VAL Out[4]: 5 In [5]: t.__dict__ Out[5]: {'VAL': 4} You must explicitly modify t.__class__.VAL or toto.VAL : In [8]: t1, t2 = toto(), toto() In [9]: t1.__class__.VAL = 4 In [10]: t2.VAL Out[

Re: how to define a static field of a given class

2006-06-02 Thread Maric Michaud
hism, after all, classes are just instances of type). -- _____ 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: Import Issue

2006-06-02 Thread Maric Michaud
to understand what happens. But as Albert said before, don't do that ! -- _ 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: strategy pattern and non-public virtual functions

2006-06-05 Thread Maric Michaud
rty(fget=lambda s : s.__strat, fset=__setStrategy) The main purpose of this is to define a common API for all Strategies, and this is really useful if you intend to manage many of them. -- _ 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: Storing nothing in a dictionary and passing it to a function

2006-06-05 Thread Maric Michaud
Le Lundi 05 Juin 2006 19:18, [EMAIL PROTECTED] a écrit : > Any thoughts? In [24]: a, b = (lambda : 'works like this'), (lambda a, b : (a,b)) In [25]: a(*()) Out[25]: 'works like this' In [26]: b(4,3) Out[26]: (4, 3) -- _ Maric Michaud _ Arist

Re: Storing nothing in a dictionary and passing it to a function

2006-06-05 Thread Maric Michaud
Le Lundi 05 Juin 2006 19:40, Maric Michaud a écrit : > Le Lundi 05 Juin 2006 19:18, [EMAIL PROTECTED] a écrit : > > Any thoughts? > oups wanted to wirte this : In [27]: a, b = (lambda : 'works like this'), (lambda *a : a) In [28]: a(*()) Out[28]: 'works like th

Re: Again, Downloading and Displaying an Image from the Internet in Tkinter

2006-06-05 Thread Maric Michaud
ke this (untested) : (assuming you have put your image data in a file-like object, ie. a StringIO, named self._dled_img) Label(self.frame, image=TkImage(Image.open(self._dled_img))) -- _________ Maric Michaud _ Aristote - www.aristote.info 3 place des tapis 69004 Lyon Tel: +33 426

Re: OT: unix newbie questions

2006-06-06 Thread Maric Michaud
d("myfile.txt", 0404) rather, >>> os.chmod("myfile.txt", 0400) I guess. or maybe you want something like this : import os, stat os.chmod("myfile.txt", os.stat("myfile.txt").st_mode - stat.S_IRGRP) -- _ Maric Michaud __

Re: CONSTRUCT - Python's way of Ruby's "alias_method"

2006-06-08 Thread Maric Michaud
. return new_result if not hasattr(service, '_old_method') : service._old_method = service.method service.method = my_impl once this file is imported, all future calls to "method" of service instances will use my_impl. -- _ Maric Michau

Re: CONSTRUCT - Python's way of Ruby's "alias_method"

2006-06-08 Thread Maric Michaud
oto.BaseClass = SqliteAdapter, but you must ensure that this code is imported before any other where classes inherit from BaseClass. The one I porpose in my other post is robust, several packages can even patch the same method with no side effects. -- _ Maric Michaud ___

Re: how to switch from os.tmpnam to os.tmpfile

2006-06-08 Thread Maric Michaud
d its content are lost. from the doc : " The file has no directory entries associated with it and will be automatically deleted once there are no file descriptors for the file." You must maintain a reference to it in your program untill you don't need it anymore.

Re: how to switch from os.tmpnam to os.tmpfile

2006-06-08 Thread Maric Michaud
ks, and if you don't need to flush the datas on disk (if they fit in memory), you can use a file-like buffer (StringIO) instead of a tmpfile, this will save resources. This said, you should consider writing your temporary file in a directory owned by you and not world writeable, which is

Re: Importing again and again

2006-06-09 Thread Maric Michaud
.Base) : pass ...: In [3]: reload(temp) Out[3]: In [4]: class b(temp.Base) : pass ...: In [7]: b.__base__, a.__base__, b.__base__ is a.__base__ Out[7]: (, , False) In [8]: isinstance(a(), temp.Base), isinstance(b(), temp.Base) Out[8]: (False, True) -- _ Maric Michaud _

Re: CONSTRUCT - Python's way of Ruby's "alias_method"

2006-06-10 Thread Maric Michaud
that should work ! -- _____ 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: Very newbie programming

2006-06-10 Thread Maric Michaud
/media' not in x: continue > icon = i > dvc = x[11:-1] > break > this will do exactly the same for icon_file in (open(dskt + e) for e in os.listdir(dskt) if '.desktop' in e) : for line in icon_file : if 'URL=/media' in line : icon = icon.name dvc = line[11:-1] break -- _ 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: Function to remove elements from a list not working

2006-06-12 Thread Maric Michaud
pair not in pairList: >             element.remove(l4) >     l5.append(element) element ??? >     print "l5 is",l5 -- _ 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: An error ?

2006-06-12 Thread Maric Michaud
Le Lundi 12 Juin 2006 09:07, Steve Holden a écrit : > print "Content-Type: text\plain\n" a typo I guess, print "Content-Type: text/plain\n" -- _ Maric Michaud _ Aristote - www.aristote.info 3 place des tapis 69004 Lyon Tel: +33 426 880 097 --

Re: Function to remove elements from a list not working (corrected)

2006-06-12 Thread Maric Michaud
s this work in your case ? def getl5(): pairList = [[1,2],[3,4],[3,5],[3,6],[9,7],[8,9],[8,7],[7,9],[11,10]] l4 = [[4,2],[4,7],[4,10],[4,12],[9,2],[9,7],[9,10],[9,12],[11,2],[11,7]] l4 = [ e for e in l4 if e in pairList ] print "l5 is", l4 -- _ Maric Michaud

Re: Function to remove elements from a list not working (corrected)

2006-06-12 Thread Maric Michaud
at if none of the pairs are > in pairList, element = []. How can i do that? element ? I guess it's already the case with lst = [ e for e in lst if e in pairs ] In [1]: lst = (1,2,3,4) In [2]: pairs=(5,) In [3]: lst=[e for e in lst if e in pairs] In [4]: lst Out[4]: [] -- ___

Re: a string problem

2006-06-13 Thread Maric Michaud
strip(string.punctuation) for e in 're string2, ,string1'.split() ]" 10 loops, best of 3: 6.99 usec per loop -- _ 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: determining file type

2006-06-14 Thread Maric Michaud
on my debian) In [69]: f = file ('samurai_tux.jpg') In [70]: s = f.read(2) In [71]: s == '\xff\xd8' Out[71]: True > Thanks, > Ritesh -- _ 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: Correctly reading stdout/stderr from subprocess

2006-06-14 Thread Maric Michaud
run = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) # Wait for the process to return out, err = [ e.splitlines() for e in run.communicate() ] return run.returncode, out, err -- _ 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: determining file type

2006-06-14 Thread Maric Michaud
Le Mercredi 14 Juin 2006 12:41, Ritesh Raj Sarraf a écrit : > Also, > f = file ('some_file.jpg') > > throws an error. > "str object is not callable" stange, did you define a function named file ? You can use open instead. -- _ Ma

Re: Correctly reading stdout/stderr from subprocess

2006-06-14 Thread Maric Michaud
Le Mercredi 14 Juin 2006 13:14, Maric Michaud a écrit : > or use a > threaded version here it is. I did it just to validate my point and because i don't use threads very often in python, some exercises can't hurt :) def run(command): import subprocess run = subproce

Re: prog1 | prog2 . How not to make prog2 block if not piped?

2006-06-14 Thread Maric Michaud
newlines ('\n'), doesn't terminate the read call, you can stop the read by typing ctrl+d at the beginnning of a new line in a normal unix terminal. -- _ 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: Correctly reading stdout/stderr from subprocess

2006-06-15 Thread Maric Michaud
he problem with getting it from an attribute (returncode) ? -- _ 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: __lt__ slowing the "in" operator even if not called

2006-06-15 Thread Maric Michaud
nd, the in oprerator is slower in these classes because of the overhead of function calls (in StateLt there is also an overhead due to internal lookup, IMO). Converting to dicts and looking for keys is *really* and equally fast in all cases, it does not depend on success or failure. -- __

Re: __lt__ slowing the "in" operator even if not called

2006-06-15 Thread Maric Michaud
at the end of list: 28249 <- here converting to dict : 79 in operator for a dict for 6 elements: 14 in operator at the beginning of list: 202 in operator at the end of list: 30472 <- and here -- _________ Maric Michaud _ Aristote - www.aristote.info 3 place des tap

Re: __lt__ slowing the "in" operator even if not called

2006-06-15 Thread Maric Michaud
(for new style classes as it seems we have not this overhead with old style classes) should be the fist step... -- _ 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: comparing two arrays

2006-06-20 Thread Maric Michaud
Le Mardi 20 Juin 2006 12:09, Diez B. Roggisch a écrit : > [i for i, equals in enumerate((x == y for x, y in zip(a, b))) if equals] No needs to nest comprehensions, should be : [ i for i, v in enumerate(zip(a, b)) if v[0] == v[1] ] -- _ Maric Michaud _ Arist

Re: Specifing arguments type for a function

2006-06-20 Thread Maric Michaud
purpose the right test should be : if not getattr(arg, '__iter__') and not getattr(arg, '__getitem__') : raise ValueError('Function accepts only iterables') # or error handling code -- _ Maric Michaud _ Aristote - www.aristote.i

Re: Specifing arguments type for a function

2006-06-20 Thread Maric Michaud
Le Mardi 20 Juin 2006 13:28, Maric Michaud a écrit : > if not getattr(arg, '__iter__') and not getattr(arg, '__getitem__') : >     raise ValueError('Function accepts only iterables') # or error handling > code oops, hasattr of course : if not hasat

Re: __getattribute__ doesn't work on 'type' type for '__class__'

2006-06-20 Thread Maric Michaud
'z') Out[27]: 'zzz' is exactly the same as : In [25]: str.__getattribute__('aaa', 'replace')('a', 'z') Out[25]: 'zzz' or even : In [26]: object.__getattribute__('aaa', 'replace')('a', 'z') Out[26]: 'zzz' -- _ 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: Search substring in a string and get index of all occurances

2006-06-21 Thread Maric Michaud
27; > substr = ' ' # space > > I would like to get this list: >[4, 8, 10, 17, 22] > > How can I do that without using "for i in mystring" which might be > expensive for large strings? > > Thanks in advance, > Nico -- _ 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: Search substring in a string and get index of all occurances

2006-06-21 Thread Maric Michaud
more efficient than Lundh's > > effbot's solution finds overlapping occurrences, whereas your solution > finds non-overlapping occurrences. Missed that. > So efficiency comparisons are not valid. Right, but anyway, the problem is more about memory usage. Regards, -- __

Re: How to override the doc of an object instance.

2006-06-21 Thread Maric Michaud
;         self._x = value >         print self._x, 'Ok' >     x = property(fget = fget, fset = fset, doc= "It prints") > > > print widget.x.__doc__ > > w = widget() > w.x = 5 > print w.x.__doc__ This is w.__class__.x.__doc__. w.x return the value you put in se

Re: How to override the doc of an object instance.

2006-06-21 Thread Maric Michaud
Le Mercredi 21 Juin 2006 15:58, David Huard a écrit : > On Wed, 21 Jun 2006 15:39:02 +0200, Maric Michaud wrote: > > This is w.__class__.x.__doc__. > > Thanks, > > So in order to implement what I want, I should rather consider an > ipython hack to print w.__class__.

Re: returning index of minimum in a list of lists

2006-06-21 Thread Maric Michaud
ers, not a list of lists. > Thanks, > Josh In [7]: min([3, 3, 1, 3]) Out[7]: 1 In [8]: min(min(e) for e in [ [3, 3], [3, 3, 1, 3], [3, 3, 3] ]) Out[8]: 1 regards, -- _____ Maric Michaud _ Aristote - www.aristote.info 3 place des tapis 69004 Lyon Tel: +33

Re: How to override the doc of an object instance.

2006-06-21 Thread Maric Michaud
nterpreter for attr in path[1:-1] : target=getattr(target, attr) target = getattr(target.__class__, path[-1], None) if isinstance(target, property) : new_eval_string += '.__class__' ret

Re: How to generate all permutations of a string?

2006-06-22 Thread Maric Michaud
aba', 'aab', 'baa']) In [6]: list(permute([1, 3, 3])) Out[6]: [[1, 3, 3], [3, 1, 3], [3, 3, 1], [1, 3, 3], [3, 1, 3], [3, 3, 1]] In [7]: set(permute([1, 3, 3])) # warning --- exceptions.TypeError Traceback (most recent call last) /ho

Re: Registry of Methods via Decorators

2006-06-22 Thread Maric Michaud
lobal is usually the module level scope (where no 'collect_methods' exists), and, in the case of a class definition, local is the class __dict__ (the local namespace is not same the class and its method). But I'm not sure of what you really want : a list of all decorated methods of all subclasses of a class, or a list of marked method in each class ? -- _ 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: Using metaclassed to dynamically generate a class based on a parameter to the objects init function.

2006-06-23 Thread Maric Michaud
ete_with_int', (Abstract,), _attr_type=int) In [125]: Concrete()._attr Out[125]: 0 In [126]: type(Concrete) Out[126]: In [127]: type(Concrete()) Out[127]: regards, -- _ 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: Using metaclassed to dynamically generate a class based on a parameter to the objects init function.

2006-06-23 Thread Maric Michaud
Le Vendredi 23 Juin 2006 17:09, Maric Michaud a écrit : > Hmmm, rigourously speaking, metaclasses in OOP are classes whose instances > are class. Ooops, sorry i didn't notice you were calling type's __new__ (and not object'sone). -- _____ Maric Michaud __

Re: module docstring, documentation, anything? please note is the module type/object NOT some module

2006-06-24 Thread Maric Michaud
elif isinstance(v, ClassType) : print 'old style class : ', k : : In [76]: find_classes(subprocess) new style class : Popen In [77]: find_classes(sys) In [78]: find_classes(os) old style class : _Environ new style class : stat_result old style class : error new

Re: DictProxy? What is this?

2006-06-26 Thread Maric Michaud
_', ), ('__module__', '__main__'), ('foo', at 0xa79528ec>), ('__weakref__', ), ('__doc__', None)] In [7]: a().foo() Out[7]: True or : In [9]: setattr(a, 'bar', lambda s : False) In [10]: a().bar() Out[10]: False -- _ 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: Get List of Classes

2006-06-26 Thread Maric Michaud
rt types, sys In [9]: isinstance(sys, types.ModuleType) Out[9]: True ? Seems rather explicit IMO. -- _ 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: Replace Whole Object Through Object Method

2006-06-26 Thread Maric Michaud
gt; class instance that calls it into that new object. I hope I'm making > sense here. > > Basically what I need is for the method to be able to find out the name > of the instance, then I can just go to the globals dictionary to do the > replacement. > > Advance thanks t

Re: replace a method in class: how?

2006-06-26 Thread Maric Michaud
None t.other_prop, u.other_prop This.__dict__.items() t.__dict__, u.__dict__ -- _ 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: replace a method in class: how?

2006-06-26 Thread Maric Michaud
= lambda x, self=t, func=another_update : func(self, x) In [33]: t.update Out[33]: at 0xa7744aac> So we have a function and know it (probably) belongs to the instance. -- _ Maric Michaud _ Aristote - www.aristote.info 3 place des tapis 69004 Lyon Tel: +33 426 880 09

Re: TypeError: Cannot create a consistent method resolution order (MRO) for bases object

2006-06-26 Thread Maric Michaud
wich appear to be the ancestor of another). -- _____ 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: Replace Whole Object Through Object Method

2006-06-26 Thread Maric Michaud
y different patterns (delegation, composition, strategy, etc.). You should google on "design patterns" and make your choice. -- _ 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: replace a method in class: how?

2006-06-26 Thread Maric Michaud
Le mardi 27 juin 2006 06:21, Bruno Desthuilliers a écrit : > Maric Michaud a écrit : > (snip) > > > In OOP Methods are defined in *classes* not in any arbitrary object > > Chapter and verse, please ? AFAIK, the first O in OOP stands for > "object", not for &qu

Re: Relying on the behaviour of empty container in conditional statements

2006-07-11 Thread Maric Michaud
uage. 'if len(container) :" means "if container's length is not zero", while "if container :" means "if container is empty". Using the second is far better because a random container can implement a faster algorithm to test its emptiness

Re: String formatting with nested dictionaries

2006-08-24 Thread Maric Michaud
ot;*9 % tuple(range(9)) % nested_dict_wrapper(complex_dict) ------- exceptions.KeyError Traceback (most recent call last) /home/maric/ /home/maric/ in __getitem__(self, v) KeyError: '8 not found in dict and subdicts' -- _ 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: Anonymous dynamic import

2006-08-28 Thread Maric Michaud
s is the case you can't use import machinery, You could go that way : #temp.py A=0 def test_execfile() : print A In [1]: d={} In [2]: execfile('temp.py',d, d) In [3]: d['test_execfile'] Out[3]: In [4]: d['test_execfile']() 0 In [5]: d['A&

Re: What are super()'s semantics?

2006-09-04 Thread Maric Michaud
: print 'c' .: .: In [143]: class D(B,C) : pass .: In [147]: super.__getattribute__(super(D,D()), 'sup')() b In [148]: super.__getattribute__(super(B,D()), 'sup')() c In [149]: super.__getattribute__(super(C,D()), 'sup')() a Hope this is clear. _ 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: What are super()'s semantics?

2006-09-04 Thread Maric Michaud
n [154]: type.mro(A) Out[154]: [, ] -- _ 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: What are super()'s semantics?

2006-09-04 Thread Maric Michaud
: : In [25]: A.__class__ Out[25]: In [26]: A().__class__ Out[26]: In [27]: isinstance(A(), list) # ouch ! Out[27]: True In [29]: type(A()) Out[29]: In [30]: type(A()).mro() Out[30]: [, ] -- _____ Maric Michaud _ Aristote - www.aristote.info 3 place des tapis 6

Re: change property after inheritance

2006-09-06 Thread Maric Michaud
- exceptions.AttributeErrorTraceback (most recent call last) /home/maric/ AttributeError: can't set attribute In [49]: ib=b() In [50]: print ib.p None In [51]: ib.p = 5 In [52]: print ib.p 5 In [53]: ib._p Out[53]: 5 --

Re: change property after inheritance

2006-09-08 Thread Maric Michaud
def setx(self, v) : self._x = v ...: p=LateBindingProperty(getx, setx) ...: ...: In [5]: class B(A) : ...: def setx(self, v) : A.setx(self, 2*v) ...: ...: In [8]: a=A() In [9]: a.p = 5 In [10]: a.p Out[10]: 5 In [11]: a._x Out[11]: 5 In [12]: b=B() In [13]: b.p=5 In [14]: b.p Out[1

Re: Question about subclassing - version 2

2006-09-08 Thread Maric Michaud
t;API only" usage of abstract classes like in Java nad its interfaces. > You may have classes with undefined methods (they may raise > NotImplementedError). C++ "pure virtual methods" is only the C++ way of doing something which is a more general concept in OOP. -- __

Re: Question about subclassing - version 2

2006-09-08 Thread Maric Michaud
to work with such complex situations, but it seems to me that partial implementation is not a bad choice, specifically in regard to duck typing. -- _ 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: Request for tips on my first python script.

2006-09-08 Thread Maric Michaud
CTED] ven sep 08 13:55:46:~$ python -c 'import os > print os.path.expanduser("~") > ' /etc -- _ 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: Request for tips on my first python script.

2006-09-08 Thread Maric Michaud
Le vendredi 08 septembre 2006 13:56, Maric Michaud a écrit : > [EMAIL PROTECTED] jeu sep 07 09:17:51:~/test$ export HOME=/etc > [EMAIL PROTECTED] ven sep 08 13:53:17:/home/maric/test$ cd ~ > [EMAIL PROTECTED] ven sep 08 13:53:22:~$ pwd > /etc > [EMAIL PROTECTED] ven sep 08 13:55:

Re: Iterate through a dictionary of lists one "line" at a time

2007-04-19 Thread Maric Michaud
values = ( d[k] for k in sorted_keys ) In [150]: for vals in chain([sorted_keys], izip(*sorted_values)) : .: print '%5s'*len(d) % vals .: .: 0123456 7 89 1111111111 012

Re: Execute commands from file

2007-05-17 Thread Maric Michaud
e, block = {}, "" for line in commands : line=line[:-1] if not line : continue if line[0].isspace() : block += '\n' + line continue else : if block.strip() : exec block in namespace block = line exec block i

Re: An expression that rebinds a variable?

2007-05-17 Thread Maric Michaud
same as : In [40]: eval(compile('x=5', '', 'exec')) -- _ 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 reference 1 instance of an object by more names ? rephrase

2007-05-23 Thread Maric Michaud
Stef Mientki a écrit : > hi Bruno, > > after study it carefully, > it's much more complex than I thought > (I can't understand it completely, which is of less importance). > Your solution works great, > but I need one little extension, > which I can create, but just at the cost of a lot of code. >

Re: using google search api for python

2007-05-23 Thread Maric Michaud
Larry Bates a écrit : > Gerardo Herzig wrote: >> Hi all. Im looking for the pyGoogle for making google searchs y a python >> script. The thing is, all im founding is an AJAX api, but the >> application ill use is NOT a web app. So, someone know if there is a >> pure python api that i can download 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

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: 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: 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

  1   2   3   >