Re: Metaclass of a metaclass

2012-06-05 Thread bruno.desthuilli...@gmail.com
On Jun 5, 10:48 am, Steven D'Aprano wrote: > Apparently it gives an error. Can anyone explain why this does not work? > > # Python 3.2 > > >>> class MyType(type):  # A metaclass... > > ...     def __repr__(self): > ...             s = super().__repr__() > ...             return s.replace('class',

Re: Why not use juxtaposition to indicate function application

2012-03-16 Thread bruno.desthuilli...@gmail.com
On Mar 16, 1:45 pm, Ray Song wrote: > I confess i've indulged in Haskell and found >     f a > more readable than >     f(a) Hmmm... What about: f a b versus f(a(b)) or was it supposed to be read as f(a)(b) or as f(a, b) ?-) > And why aren't functions curried (partially

Re: Id of methods

2012-02-09 Thread bruno.desthuilli...@gmail.com
On Feb 9, 5:06 am, Chris Angelico wrote: > On Thu, Feb 9, 2012 at 2:48 PM, Emeka wrote: > > > My question is why is it that the id of Boo.daf  is different from daf's hex > > value in the above dict? > > > daf is not a function, it's a special object for an unbound method. http://wiki.python.org

Re: Help about dictionary append

2012-02-06 Thread bruno.desthuilli...@gmail.com
On Feb 5, 4:29 pm, Andrew Berg wrote: > This has nothing to do with dictionaries. If you want to add, delete, or > change items, use a list (or a set if there aren't supposed to be any > duplicates). AND you don't care about ordering... -- http://mail.python.org/mailman/listinfo/python-list

Re: SnakeScript? (CoffeeScript for Python)

2012-02-06 Thread bruno.desthuilli...@gmail.com
On Feb 2, 9:23 pm, Michal Hantl wrote: > See the link I attached. > Ruby-like blocks would be nice too. > Implicit returns. > Better strings like """My name is #{name}""". Uhu... Looks like you want Ruby, not Python -- http://mail.python.org/mailman/listinfo/python-list

Re: Closures and Partial Function Application

2011-08-31 Thread bruno.desthuilli...@gmail.com
On 31 août, 18:45, Travis Parks wrote: > I was a little disappointed the other day when I realized that > closures were read-only. I like to use closures quite a bit. They are not _strictly_ read only, but Python being first and foremost an OO language, it's usually way simpler to use OO instead

Re: Trying to learn about metaclasses

2011-07-30 Thread bruno.desthuilli...@gmail.com
On 25 juil, 17:36, "Steven W. Orr" wrote: > I have been doing a lot of reading. I'm starting to get it. I think it's > really cool as well as dangerous, Dangerous ??? Why so ? Is there anything "dangerous" in a constructor or an initialiser ??? A metaclass is just a class, and a class is just an

Re: PyWart: PEP8: A cauldron of inconsistencies.

2011-07-30 Thread bruno.desthuilli...@gmail.com
On 28 juil, 00:34, rantingrick wrote: > In Python4000 i'm making it a syntax error to > include ANY blank lines in a func/meth body. Hopefully this is not going to happen. (snip remaining stupidities). -- http://mail.python.org/mailman/listinfo/python-list

Re: NoneType and new instances

2011-07-30 Thread bruno.desthuilli...@gmail.com
On 28 juil, 17:39, Ethan Furman wrote: > > --> bool(0) is bool(0) > True > This test is not reliable - a same id can be reused for terms (I have already seen such things happening). If you want a reliable test, use: #> a = bool(0) #> b = bool(0) #> a is b True Note that this still fails to prov

Re: Use self.vars in class.method(parameters, self.vars)

2011-07-22 Thread bruno.desthuilli...@gmail.com
On Jul 22, 1:12 pm, caccolangrifata wrote: Totally OT but others already answered the question... > class foo(object): class names should start with an uppercase letter: class Foo(object): > >         __init__(self, len = 9): 1/ you want to add a "def" statement before "__init__" 2/ the argu

Re: PEP 8 and extraneous whitespace

2011-07-21 Thread bruno.desthuilli...@gmail.com
On 21 juil, 20:46, Andrew Berg wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: RIPEMD160 > > On 2011.07.21 01:32 PM, Thomas Jollans wrote:> So, the PEP says: do not align > operators. End of story. > > I'm pretty sure that colons, commas and equals signs are not operators. 1/ you can consid

Re: None versus MISSING sentinel -- request for design feedback

2011-07-15 Thread bruno.desthuilli...@gmail.com
On Jul 15, 10:28 am, Teemu Likonen wrote: > > How about accepting anything but ignoring all non-numbers? Totally unpythonic. Better to be explicit about what you expect and crash as loudly as possible when you get anything unexpected. -- http://mail.python.org/mailman/listinfo/python-list

Re: None versus MISSING sentinel -- request for design feedback

2011-07-15 Thread bruno.desthuilli...@gmail.com
On Jul 15, 9:44 am, Cameron Simpson wrote: > On 15Jul2011 15:28, Steven D'Aprano > wrote: > | Against MISSING: users may expect to be able to choose their own sentinel by > | assigning to MISSING. I don't want to support that. > > Well, we don't have readonly values to play with :-( > Personally

Re: None versus MISSING sentinel -- request for design feedback

2011-07-15 Thread bruno.desthuilli...@gmail.com
On Jul 15, 7:28 am, Steven D'Aprano wrote: > > I'm designing an API for some lightweight calculator-like statistics > functions, such as mean, standard deviation, etc., and I want to support > missing values. Missing values should be just ignored. E.g.: (snip) > Against None: it's too easy to m

Re: Possible File iteration bug

2011-07-15 Thread bruno.desthuilli...@gmail.com
On Jul 14, 9:46 pm, Billy Mays wrote: > I noticed that if a file is being continuously written to, the file > generator does not notice it: > > def getLines(f): >      lines = [] >      for line in f: >          lines.append(line) >      return lines what's wrong with file.readlines() ? -- http:

Re: None versus MISSING sentinel -- request for design feedback

2011-07-15 Thread bruno.desthuilli...@gmail.com
On Jul 15, 8:08 am, Chris Angelico wrote: > > Agreed that float('nan') and "" and "spam" are all bad values for > Missings. Possibly "" should come out as 0 "In the face of ambiguity, refuse the temptation to guess." As far as I'm concerned, I'd expect this to raise a TypeError... -- http://m

Re: list(), tuple() should not place at "Built-in functions" in documentation

2011-07-15 Thread bruno.desthuilli...@gmail.com
On Jul 15, 9:27 am, "bruno.desthuilli...@gmail.com" wrote: > On Jul 15, 4:58 am, Inside wrote: > > > Hey guy,thx for you feedback first. > > > But I can't follow your opinion.Why?because of the list & tuple are placed > > at built-in function,

Re: list(), tuple() should not place at "Built-in functions" in documentation

2011-07-15 Thread bruno.desthuilli...@gmail.com
On Jul 15, 4:58 am, Inside wrote: > Hey guy,thx for you feedback first. > > But I can't follow your opinion.Why?because of the list & tuple are placed at > built-in function,so before I type 'list' unintentionally on the pyshell and > it show me "", I never know that the name 'list' is a type,I

Re: Please critique my script

2011-07-15 Thread bruno.desthuilli...@gmail.com
On Jul 15, 8:36 am, Chris Angelico wrote: > This can alternatively be done with map(): > > sortlist = map(lambda x,y: x+y, npalist, nxxlist) > > > (It would have been a lot cleaner if Python exposed its operators as > functions. from operator import add -- http://mail.python.org/mailman/list

Re: "Python Wizard," with apologies to The Who

2011-07-13 Thread bruno.desthuilli...@gmail.com
On Jul 12, 6:40 pm, John Keisling wrote: > After too much time coding Python scripts and reading Mark Lutz's > Python books, I was inspired to write the following lyrics. Brillant. This deserves to become a cpython easter egg along with import this or from __future__ import braces. -- http://mai

Re: How to write a file generator

2011-07-12 Thread bruno.desthuilli...@gmail.com
On Jul 12, 4:46 pm, Billy Mays wrote: > I want to make a generator that will return lines from the tail of > /var/log/syslog if there are any Err... I must have missed something, but python files are their own iterators. Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) [GCC 4.4.5] on linux2 Type

Re: Wgy isn't there a good RAD Gui tool fo python

2011-07-11 Thread bruno.desthuilli...@gmail.com
On Jul 11, 2:42 am, Adam Tauno Williams wrote: > > But Open Source land is simply too fragmented.  There are too many > database bindings [and RAD requires something like an ORM (think > SQLalchemy)] and far too many GUI toolkits [Qt, Gtk, wx, and the list > goes on and on]. > > Nothing can muster

Re: Project-wide variable...

2011-06-23 Thread bruno.desthuilli...@gmail.com
On Jun 23, 4:42 pm, Peter Otten <__pete...@web.de> wrote: (snip) > > However I end up doing it in every submodule, so it seems a little > > redundant. I wish I could load the variable in the parent program and > > have it be available in all submodules. Am I missing something? > > You can modify th

Re: Using django ORM from web browser and from command line apps

2011-06-22 Thread bruno.desthuilli...@gmail.com
On Jun 22, 2:21 am, News123 wrote: > Out of curiousity: Do you know whether the imports would be executed for > each potential command as soon as I call manage.py or only > 'on demand'? Why would you care ? Just importing the module shouldn't have any side effect. -- http://mail.python.org/mailm

Re: What's the best way to write this base class?

2011-06-18 Thread bruno.desthuilli...@gmail.com
On 18 juin, 13:24, Tim Chase wrote: > On 06/18/2011 05:55 AM, bruno.desthuilli...@gmail.com wrote: > > > On 18 juin, 06:17, John Salerno  wrote: > >> class Character: > > >>      base_health = 50 > >>      base_resource = 10 > > >>      de

Re: What's the best way to write this base class?

2011-06-18 Thread bruno.desthuilli...@gmail.com
On 18 juin, 06:17, John Salerno wrote: > Note: I have in mind that when a specific subclass (Warrior, Wizard, > etc.) is created, the only argument that will ever be passed to the > __init__ method is the name. The other variables will never be > explicitly passed, but will be set during initiali

Re: How to avoid "()" when writing a decorator accepting optional arguments?

2011-06-17 Thread bruno.desthuilli...@gmail.com
On Jun 17, 3:53 pm, Ian Kelly wrote: > > That works, but I would be concerned about forgetting to specify the > argument by keyword (snip funny side effect description) >  Also, as in my suggestion, it doesn't seem > like a big improvement to have to type out "replacement=" when you > need the r

Re: How to avoid "()" when writing a decorator accepting optional arguments?

2011-06-17 Thread bruno.desthuilli...@gmail.com
On Jun 11, 10:28 pm, Ian Kelly wrote: > > Since there is no way to distinguish the two cases by the arguments, def deprecated(func=None, replacement=None): if replacement: # handle the case where a replacement has been given elif func: # handle the case where no replacement

Re: Python for Web

2011-06-15 Thread bruno.desthuilli...@gmail.com
On Jun 15, 9:50 am, sidRo wrote: > Is Python only for server side? Is it a theoretical question or a practical one ?-) More seriously: except for the old proof-of-concept Grail browser, no known browser uses Python as a client-side scripting language. -- http://mail.python.org/mailman/listinfo/

Re: BadValueError: Property title is required

2011-05-31 Thread bruno.desthuilli...@gmail.com
On May 31, 10:32 am, Chris Rebert wrote: > On Tue, May 31, 2011 at 1:21 AM, michal.bulla wrote: > > Hello, > > > I'm trying to create simple method to create category. I set the model > > category: > > > class Category(db.Model): > >  title = db.StringProperty(required=True) > >  clashes_count =

Re: Bring out yer dead Bring out yer dead

2011-03-30 Thread bruno.desthuilli...@gmail.com
On 30 mar, 09:12, harrismh777 wrote: >       2.6.2 >       2.5.1 >    == >       (___)     \--- ( 3.2 ) > > Cartman: Bring out yer dead,..  bring out yer dead... > > Devlpr:         Here' one...  (Python27) > > Cartman: ... nine pence! > > Python27:               I'm not dead! > >

Re: Converting an array of string to array of float

2011-03-25 Thread bruno.desthuilli...@gmail.com
On 25 mar, 16:19, joy99 wrote: > Dear Group, > > I got a question which might be possible but I am not getting how to > do it. > > If I have a list, named, > list1=[1.0,2.3,4.4,5.5] > > Now each element in the array holds the string property if I want to > convert them to float, how would I do

Re: Redundant importing of modules

2010-12-21 Thread bruno.desthuilli...@gmail.com
On 21 déc, 03:03, Steve Holden wrote: > On 12/20/2010 8:36 PM, Jshgwave wrote:> > > When writing a function that uses a module such as NumPy, it is tempting > > to include the statement "import numpy" or "import numpy as np" in the > > definition of the function, in case the  function is used in a

Re: string identity and comparison

2010-12-16 Thread bruno.desthuilli...@gmail.com
On 16 déc, 15:53, Jean-Michel Pichavant wrote: > Mel wrote: > > Jean-Michel Pichavant wrote: > > >> Fellows, > > >> I'd like to illutrate the fact that comparing strings using identity is, > >> most of the time, a bad idea. However I'm searching a short example of > >> code that yields 2 different

Re: string identity and comparison

2010-12-16 Thread bruno.desthuilli...@gmail.com
On 16 déc, 15:52, Jean-Michel Pichavant wrote: > bruno.desthuilli...@gmail.com wrote: > > On 16 d c, 12:55, Jean-Michel Pichavant > > wrote: > > >> id('foo') > >> 3082385472L > >> id('foo') > >> 3082385472L > > &g

Re: string identity and comparison

2010-12-16 Thread bruno.desthuilli...@gmail.com
On 16 déc, 12:55, Jean-Michel Pichavant wrote: > Fellows, > > I'd like to illutrate the fact that comparing strings using identity is, > most of the time, a bad idea. However I'm searching a short example of > code that yields 2 differents object for the same string content. > > id('foo') > 308238

Re: while True or while 1

2010-12-15 Thread bruno.desthuilli...@gmail.com
On 14 déc, 21:38, Arnaud Delobelle wrote: > I almost used: > >     True = "to be" or not "to be" # that is the question KEYBOARD !-) -- http://mail.python.org/mailman/listinfo/python-list

Re: Objects and validation

2010-12-13 Thread bruno.desthuilli...@gmail.com
On 12 déc, 15:28, pyt...@lists.fastmail.net wrote: > I have a routine in Python which is extracting information from a > website. This information is read and inserted into objects. > > I currently have all the validations and checks implemented in the > routines which are reading the HTML and crea

Re: v = vte.Terminal() AttributeError: 'module' object has no attribute 'Terminal'

2010-12-07 Thread bruno.desthuilli...@gmail.com
On 7 déc, 12:05, Steve wrote: > Hi, > > I try to run a terminal emulation using Python+Gtk+Vte. Before develop > my own sources, i'm testing some examples like this > ;http://www.eurion.net/python-snippets/snippet/Embed%20a%20VTE%20termi... > > But when i try to run, i get this message error; > >

Re: How can I define class methods outside of the class?

2010-12-02 Thread bruno.desthuilli...@gmail.com
On 2 déc, 15:45, Jeremy wrote: > On Dec 1, 10:47 pm, James Mills wrote: > > > > > On Thu, Dec 2, 2010 at 3:36 PM, Jeremy wrote: > > > I have some methods that I need (would like) to define outside of the > > > class.  I know this can be done by defining the function and then > > > setting it equ

Re: How can I define class methods outside of the class?

2010-12-02 Thread bruno.desthuilli...@gmail.com
On 2 déc, 06:36, Jeremy wrote: > I have some methods that I need (would like) to define outside of the > class.  I know this can be done by defining the function and then > setting it equal to some member "assignement" or "binding" might be the terms you were looking for here ;) Also in Python

Re: strange TypeError exception in function compiled from a string

2010-12-01 Thread bruno.desthuilli...@gmail.com
On 1 déc, 14:48, nelson wrote: > Hi all, >   I have this function, defined in a string and ecetuted through ad > exec call > > def cell1(d): > >     x=d.get('x') >     print x > >     import y >     return y.add(y.add(self.adf0(x),self.adf0(x)),self.adf0(x)) > > d is a dict of this kind {'x':2} >

Re: Python recursively __getattribute__

2010-11-23 Thread bruno.desthuilli...@gmail.com
On 22 nov, 21:44, Roman Dolgiy wrote: >> http://stackoverflow.com/questions/4247036/python-recursively-getattr... > > I need to support a lot of legacy code, with THC4k's approach I'll > have to modify project's existing code to use obj.attr1.val instead of > obj.attr1 but this is not suitable. Y

Re: Descriptors and decorators

2010-10-26 Thread bruno.desthuilli...@gmail.com
On 25 oct, 17:18, Joost Molenaar wrote: > Thanks, Bruno. > Your python-wiki page and walk-through for the Decorator code make it > clear. I now finally understand that methods are in fact ordinary > functions at the time the class is created, and that the descriptor > protocol turns them into boun

Re: Why "flat is better than nested"?

2010-10-25 Thread bruno.desthuilli...@gmail.com
On 25 oct, 15:34, Alex Willmer wrote: > On Oct 25, 11:07 am, kj wrote: > > > In "The Zen of Python", one of the "maxims" is "flat is better than > > nested"?  Why?  Can anyone give me a concrete example that illustrates > > this point? > > I take this as a reference to the layout of the Python st

Re: Descriptors and decorators

2010-10-25 Thread bruno.desthuilli...@gmail.com
On 25 oct, 14:15, Joost Molenaar wrote: > WebOb contains this little nugget of code that allows you to define a > decorator that works on both methods and functions: > > class Decorator(object): >     def __init__(self, func): >         self.func = func >     def __get__(self, object, type=None):

Re: init inside def

2010-10-25 Thread bruno.desthuilli...@gmail.com
On 25 oct, 12:05, targetsmart wrote: > Hi, > today I just came across a python code snippet where __init__ was > defined inside a function.. > I am not able to understand the reason why > > The code snippet was similar like > > def func1(a,b): >   def __init__(): >     func2(a,b) >   def func2(a,b

Re: subclass constructor problem

2010-10-06 Thread bruno.desthuilli...@gmail.com
On 5 oct, 17:52, de...@web.de (Diez B. Roggisch) wrote: > Btw, you are a bit on the overprotective side. The convention for > marking attributes (methods or objects alike) "private" s/private/implementation/ I find that thinking in terms of "interface / implementation" instead of "public / privat

Re: namespace hacking question

2010-10-01 Thread bruno.desthuilli...@gmail.com
On 1 oct, 14:12, Fuzzyman wrote: > On Sep 30, 6:07 pm, kj wrote: > > > > > This is a recurrent situation: I want to initialize a whole bunch > > of local variables in a uniform way, but after initialization, I > > need to do different things with the various variables. > > > What I end up doing i

Re: if the else short form

2010-10-01 Thread bruno.desthuilli...@gmail.com
On 30 sep, 19:22, Andreas Waldenburger wrote: > On Thu, 30 Sep 2010 03:42:29 -0700 (PDT) > > "bruno.desthuilli...@gmail.com" wrote: > > On 29 sep, 19:20, Seebs wrote: > > > On 2010-09-29, Tracubik wrote: > > > > button = gtk.Button(("Fals

Re: namespace hacking question

2010-09-30 Thread bruno.desthuilli...@gmail.com
On 30 sep, 19:07, kj wrote: > This is a recurrent situation: I want to initialize a whole bunch > of local variables in a uniform way, but after initialization, I > need to do different things with the various variables. > > What I end up doing is using a dict: > > d = dict() > for v in ('spam', '

Re: if the else short form

2010-09-30 Thread bruno.desthuilli...@gmail.com
On 29 sep, 19:20, Seebs wrote: > On 2010-09-29, Tracubik wrote: > > button = gtk.Button(("False,", "True,")[fill==True]) > Oh, what a nasty idiom. > Well, it's not very different from dict-based dispatch , which is the core of OO polymorphic dispatch in quite a few dynamic OOPLs. Anyway, it's

Re: if the else short form

2010-09-29 Thread bruno.desthuilli...@gmail.com
On 29 sep, 13:38, Hrvoje Niksic wrote: > Tracubik writes: > > > button = gtk.Button(("False,", "True,")[fill==True]) (snip) > BTW adding "==True" to a boolean value is redundant and can even break > for logically true values that don't compare equal to True (such as the > number 10 or the strin

Re: list problem...

2010-09-29 Thread bruno.desthuilli...@gmail.com
On 29 sep, 14:17, Steven D'Aprano wrote: > On Tue, 28 Sep 2010 20:11:51 +0100, Rog wrote: > > On Tue, 28 Sep 2010 11:59:08 -0700, geremy condra wrote: > > >> On Tue, Sep 28, 2010 at 11:44 AM, Rog wrote: > >>> Hi all, > >>> Have been grappling with a list problem for hours... a = [2, 3, 4, > >>> 5

Re: Learning inheritance

2010-09-18 Thread bruno.desthuilli...@gmail.com
On 18 sep, 17:25, Niklasro wrote: > Hi > How can I make the visibility of a variable across many methods or > files? To avoid repeating the same line eg     url = > os.environ['HTTP_HOST'] if os.environ.get('HTTP_HOST') else > os.environ['SERVER_NAME'] First learn to use Python correctly: url =

Re: palindrome iteration

2010-08-29 Thread bruno.desthuilli...@gmail.com
On 29 août, 06:39, Gregory Ewing wrote: > Steven D'Aprano wrote: > >  I'm not entirely sure what the use-case for swapcase is. > > Obviously it's for correcting things that were typed > in with tHE cAPS lOCK kEY oN bY mISTAKE. :-) > +1 QOTW !-) -- http://mail.python.org/mailman/listinfo/python-l

Re: palindrome iteration

2010-08-29 Thread bruno.desthuilli...@gmail.com
On 27 août, 20:05, Jussi Piitulainen > def palindromep(s): >     return ( s == "" or >              ( s[0] == s[-1] and >                palindromep(s[1:-1]) ) ) > I-can-write-lisp-in-any-language-p !-) -- http://mail.python.org/mailman/listinfo/python-list

Re: palindrome iteration

2010-08-29 Thread bruno.desthuilli...@gmail.com
On 27 août, 18:20, Mark Lawrence wrote: > On 27/08/2010 15:43, Bruno Desthuilliers wrote: > > > Dave Angel a écrit : > > (snip) > > >> or (untested) > >> def is_palindrom(s): > >> s = s.lower() > >> return s == s[::-1] > > > Right, go on, make me feel a bit more stupid :-/ > > Who's next ? > > It

Re: Newsgroup for beginners

2009-11-24 Thread bruno.desthuilli...@gmail.com
On 20 nov, 20:42, Ethan Furman wrote: > Aahz wrote: > > In article , > > Grant Edwards   wrote: > > >>You've really got to try pretty hard to create one.  But if you > >>want to, here's how to do it: > > >>1) Start by complaining that your program doesn't work because > >>   of a bug in Python. >