Re: Is this unpythonic?

2015-05-10 Thread Frank Millman
Johannes Bauer dfnsonfsdu...@gmx.de wrote in message news:min9t3$e56$1...@news.albasani.net... On 10.05.2015 10:58, Frank Millman wrote: It is then a simple extra step to say - EMPTY_L:IST = () and if required - EMPTY_DICT = () and expand the explanation to show why a tuple is

Re: Is this unpythonic?

2015-05-10 Thread Frank Millman
Johannes Bauer dfnsonfsdu...@gmx.de wrote in message news:min3f0$2gh$1...@news.albasani.net... On 08.05.2015 14:04, Dave Angel wrote: It might be appropriate to define the list at top-level, as EMPTY_LIST=[] and in your default argument as def x(y, z=EMPTY_LIST): and with

Re: Is this unpythonic?

2015-05-10 Thread Johannes Bauer
On 08.05.2015 14:04, Dave Angel wrote: It might be appropriate to define the list at top-level, as EMPTY_LIST=[] and in your default argument as def x(y, z=EMPTY_LIST): and with the all-caps, you're thereby promising that nobody will modify that list. (I'd tend to do the None

Re: Is this unpythonic?

2015-05-10 Thread Johannes Bauer
On 10.05.2015 10:58, Frank Millman wrote: It is then a simple extra step to say - EMPTY_L:IST = () and if required - EMPTY_DICT = () and expand the explanation to show why a tuple is used instead. So if there was a situation where the overhead of testing for None became a

Re: Is this unpythonic?

2015-05-09 Thread Frank Millman
Gregory Ewing greg.ew...@canterbury.ac.nz wrote in message news:cr5sc6fgfm...@mid.individual.net... Frank Millman wrote: The absolutely clearest way to write it would probably be def f(things = None): things is a mapping of stuff to be operated on if things: for

Re: Is this unpythonic?

2015-05-09 Thread Gregory Ewing
Frank Millman wrote: There are two operations I might perform on the dictionary - 1. iterate over the keys and retrieve the values 2: use 'in' to test if a given string exists as a key Both of these operations will work on a tuple and give the desired result, so it is a very valid

Re: Is this unpythonic?

2015-05-09 Thread Frank Millman
Frank Millman fr...@chagford.com wrote in message news:mik7j6$59n$1...@ger.gmane.org... Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote in message news:554cd119$0$12977$c3e8da3$54964...@news.astraweb.com... On Fri, 8 May 2015 08:53 pm, Frank Millman wrote: Does z have to be a

Is this unpythonic?

2015-05-08 Thread Frank Millman
Hi all I have often read about the gotcha regarding 'mutable default arguments' that frequently trips people up. I use them from time to time, but I have never had a problem. I have just delved a bit deeper to see if I am skating on thin ice. AFAICT my usage is safe. If I use a list as an

Re: Is this unpythonic?

2015-05-08 Thread Chris Angelico
On Fri, May 8, 2015 at 6:01 PM, Frank Millman fr...@chagford.com wrote: I have often read about the gotcha regarding 'mutable default arguments' that frequently trips people up. I use them from time to time, but I have never had a problem. I have just delved a bit deeper to see if I am

Re: Is this unpythonic?

2015-05-08 Thread Frank Millman
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote in message news:554c8b0a$0$12992$c3e8da3$54964...@news.astraweb.com... On Fri, 8 May 2015 06:01 pm, Frank Millman wrote: Hi all [...] However, every time I look at my own code, and I see def x(y, z=[]): . it looks wrong

Re: Is this unpythonic?

2015-05-08 Thread Steven D'Aprano
On Fri, 8 May 2015 06:01 pm, Frank Millman wrote: Hi all I have often read about the gotcha regarding 'mutable default arguments' that frequently trips people up. I use them from time to time, but I have never had a problem. I have just delved a bit deeper to see if I am skating on thin

Re: Is this unpythonic?

2015-05-08 Thread Steven D'Aprano
On Fri, 8 May 2015 08:53 pm, Frank Millman wrote: Does z have to be a list? Could you use an empty tuple instead? def x(y, z=()): ... That was Chris' suggestion as well (thanks Chris). The idea appealed to me, but then I found a situation where I pass in a dictionary instead of a list,

Re: Is this unpythonic?

2015-05-08 Thread Frank Millman
Dave Angel da...@davea.name wrote in message news:554ca652.1000...@davea.name... On 05/08/2015 06:53 AM, Frank Millman wrote: It might be appropriate to define the list at top-level, as EMPTY_LIST=[] and in your default argument as def x(y, z=EMPTY_LIST): and with the all-caps,

Re: Is this unpythonic?

2015-05-08 Thread Frank Millman
Ben Finney ben+pyt...@benfinney.id.au wrote in message news:85y4kzb90f@benfinney.id.au... Frank Millman fr...@chagford.com writes: If I use a list as an argument, I only use it to pass values *into* the function, but I never modify the list. You've had good reasons why a mutable

Re: Is this unpythonic?

2015-05-08 Thread Dave Angel
On 05/08/2015 06:53 AM, Frank Millman wrote: Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote in message news:554c8b0a$0$12992$c3e8da3$54964...@news.astraweb.com... On Fri, 8 May 2015 06:01 pm, Frank Millman wrote: Hi all [...] However, every time I look at my own code, and I

Re: Is this unpythonic?

2015-05-08 Thread Frank Millman
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote in message news:554cd119$0$12977$c3e8da3$54964...@news.astraweb.com... On Fri, 8 May 2015 08:53 pm, Frank Millman wrote: Does z have to be a list? Could you use an empty tuple instead? def x(y, z=()): ... That was Chris'

Re: Is this unpythonic?

2015-05-08 Thread Ben Finney
Frank Millman fr...@chagford.com writes: If I use a list as an argument, I only use it to pass values *into* the function, but I never modify the list. You've had good reasons why a mutable default argument is a good idea. I'll address another aspect of the question: passing a structured

Re: Encapsulation unpythonic?

2013-09-02 Thread 88888 Dihedral
two underscores before the name of a variable within a class declaration but in the many examples of code I looked at this is not widely used. I also read that encapsulation is unpythonic. Questions: 2) If it is in fact true that encapsulation is rarely used

Re: Encapsulation unpythonic?

2013-09-02 Thread Rhodri James
On Sat, 31 Aug 2013 12:46:52 +0100, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: # THIS DOES NOT HAPPEN IN PYTHON # or any other language, as far as I am aware x = 23 y = x # y now has the value 23 x = 42 # change the value of the object ### NOT SO! ### print y = prints 42

Re: Encapsulation unpythonic?

2013-09-01 Thread Steven D'Aprano
On Sat, 31 Aug 2013 05:57:47 -0700, Fabrice Pombet wrote: Steve, I think that your definition of encapsulation is too wide to give a reasonable answer to the question at hand. My definition of encapsulation is based on the plain language definition. It is also common in computer programming

Re: Encapsulation unpythonic?

2013-09-01 Thread Chris Angelico
On Sun, Sep 1, 2013 at 6:10 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: Java and C++ allow you to declare members as public, so it is *not true* that calling methods is the only way to change members. If you accept Steve Holden's (wrong) definition above, Java and C++ don't

Re: Encapsulation unpythonic?

2013-09-01 Thread Fabrice Pombet
That said, though, when you consider the language ecosystem rather than just the language, there is a strong tendency for Java and C++ code to wrap everything up with functions (no public data members), whereas Python code is far more likely to have external code directly access data

Re: Encapsulation unpythonic?

2013-09-01 Thread Ethan Furman
On 09/01/2013 03:09 AM, Fabrice Pombet wrote: So I guess that we are actually all agreeing on this one. No, we are not. encapsulation != inaccessible except by getters/setters -- ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list

Re: Encapsulation unpythonic?

2013-09-01 Thread Roy Smith
In article mailman.455.1378062400.19984.python-l...@python.org, Ethan Furman et...@stoneleaf.us wrote: On 09/01/2013 03:09 AM, Fabrice Pombet wrote: So I guess that we are actually all agreeing on this one. No, we are not. encapsulation != inaccessible except by getters/setters

Re: Encapsulation unpythonic?

2013-09-01 Thread Ethan Furman
@value.setter def value(self, new_value) validate(new_value) self._value = new_value class PlainPython: value = None In the Javaesque class we see the unPythonic way of using getters/setters; in the ProtectedPython* class we see the pythonic way of providing getters/setters

Re: Encapsulation unpythonic?

2013-09-01 Thread Tim Delaney
On 2 September 2013 06:33, Ethan Furman et...@stoneleaf.us wrote: class PlainPython: value = None In the Javaesque class we see the unPythonic way of using getters/setters; in the ProtectedPython* class we see the pythonic way of providing getters/setters**; in the PlainPython class

Re: Encapsulation unpythonic?

2013-09-01 Thread Roy Smith
In article mailman.461.1378072496.19984.python-l...@python.org, Tim Delaney timothy.c.dela...@gmail.com wrote: On 2 September 2013 06:33, Ethan Furman et...@stoneleaf.us wrote: class PlainPython: value = None In the Javaesque class we see the unPythonic way of using getters

Re: Encapsulation unpythonic?

2013-09-01 Thread Ben Finney
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes: […] programmers have been using the *principle* of encapsulation since before Grace Hopper was an admiral. […] Encapsulation and information hiding are distinct things -- you can have one without the other. […] One of the most

Re: Encapsulation unpythonic?

2013-09-01 Thread Ethan Furman
On 09/01/2013 02:54 PM, Tim Delaney wrote: Roy Smith wrote: Nothing is accessible in Python except via getters and setters. The only difference between Python and, say, C++ in this regard is that the Python compiler writes them for you most of the time and doesn't make you put ()'s at the end

Re: Encapsulation unpythonic?

2013-09-01 Thread Roy Smith
In article mailman.464.1378078348.19984.python-l...@python.org, Ben Finney ben+pyt...@benfinney.id.au wrote: One of the more annoying traits of humanity is that whatever context we first encounter a term is disproportionately privileged, causing us to irrationally dismiss better (more useful,

Re: Encapsulation unpythonic?

2013-09-01 Thread Roy Smith
In article mailman.468.1378083075.19984.python-l...@python.org, Ethan Furman et...@stoneleaf.us wrote: On 09/01/2013 02:54 PM, Tim Delaney wrote: Roy Smith wrote: Nothing is accessible in Python except via getters and setters. The only difference between Python and, say, C++ in this

Re: Encapsulation unpythonic?

2013-09-01 Thread Steven D'Aprano
On Sun, 01 Sep 2013 15:13:06 -0400, Roy Smith wrote: In article mailman.455.1378062400.19984.python-l...@python.org, Ethan Furman et...@stoneleaf.us wrote: On 09/01/2013 03:09 AM, Fabrice Pombet wrote: So I guess that we are actually all agreeing on this one. No, we are not.

Re: Encapsulation unpythonic?

2013-09-01 Thread Steven D'Aprano
On Sun, 01 Sep 2013 20:59:25 -0400, Roy Smith wrote: In article mailman.468.1378083075.19984.python-l...@python.org, Ethan Furman et...@stoneleaf.us wrote: On 09/01/2013 02:54 PM, Tim Delaney wrote: Roy Smith wrote: Nothing is accessible in Python except via getters and setters. The

Re: Encapsulation unpythonic?

2013-09-01 Thread Ethan Furman
On 09/01/2013 05:59 PM, Roy Smith wrote: Ethan Furman wrote: On 09/01/2013 02:54 PM, Tim Delaney wrote: Roy Smith wrote: Nothing is accessible in Python except via getters and setters. The only difference between Python and, say, C++ in this regard is that the Python compiler writes them

Re: Encapsulation unpythonic?

2013-08-31 Thread Fabrice Pombet
On Saturday, August 31, 2013 4:35:39 AM UTC+2, Steven D'Aprano wrote: On Fri, 30 Aug 2013 10:43:28 -0700, Fabrice Pombet wrote: On Saturday, August 17, 2013 2:26:32 PM UTC+2, Fernando Saldanha wrote: 2) If it is in fact true that encapsulation is rarely used, how do I deal

Re: Encapsulation unpythonic?

2013-08-31 Thread Marco Buttu
On 08/31/2013 08:07 AM, Fabrice Pombet wrote: well, look at that: a=(1,2) a=2+3 -a is an object and I have changed its type and value from outside. No, `a` is not an object, so you did not change the type of any object. `a` is just a name (a label), that initially refers to the tuple (1,

Re: Encapsulation unpythonic?

2013-08-31 Thread Gary Herron
On 08/30/2013 11:07 PM, Fabrice Pombet wrote: ... long discussion elided ... well, look at that: a=(1,2) a=2+3 -a is an object and I have changed its type and value from outside. As far as I am concerned this is one hell of an encapsulation violation... Could you do this -strictly speaking-

Re: Encapsulation unpythonic?

2013-08-31 Thread Fabrice Pombet
On Saturday, August 31, 2013 9:03:58 AM UTC+2, Gary Herron wrote: On 08/30/2013 11:07 PM, Fabrice Pombet wrote: ... long discussion elided ... well, look at that: a=(1,2) a=2+3 -a is an object and I have changed its type and value from outside. As far as I am

Re: Encapsulation unpythonic?

2013-08-31 Thread Fabrice Pombet
On Saturday, August 31, 2013 9:42:55 AM UTC+2, Fabrice Pombet wrote: On Saturday, August 31, 2013 9:03:58 AM UTC+2, Gary Herron wrote: On 08/30/2013 11:07 PM, Fabrice Pombet wrote: ... long discussion elided ... well, look at that:

Re: Encapsulation unpythonic?

2013-08-31 Thread Steven D'Aprano
On Fri, 30 Aug 2013 23:07:47 -0700, Fabrice Pombet wrote: well, look at that: a=(1,2) a=2+3 -a is an object and I have changed its type and value from outside. Incorrect. You have not changed the type or value of any object. a is not an object, it is a *name*, and while you can change

Re: Encapsulation unpythonic?

2013-08-31 Thread Ned Batchelder
On 8/31/13 7:46 AM, Steven D'Aprano wrote: On Fri, 30 Aug 2013 23:07:47 -0700, Fabrice Pombet wrote: well, look at that: a=(1,2) a=2+3 -a is an object and I have changed its type and value from outside. Incorrect. You have not changed the type or value of any object. a is not an object, it

Re: Encapsulation unpythonic?

2013-08-31 Thread Fabrice Pombet
http://nedbatchelder.com/text/names.html --Ned. This is an excellent explanation, thank you. It is mostly of theoretical interest though, and in practice, I still contend that the consequences towards the syntax are (or seem, if you prefer) analogous to those of the lack of

Re: Encapsulation unpythonic?

2013-08-31 Thread Fabrice Pombet
On Saturday, August 31, 2013 1:46:52 PM UTC+2, Steven D'Aprano wrote: On Fri, 30 Aug 2013 23:07:47 -0700, Fabrice Pombet wrote: well, look at that: a=(1,2) a=2+3 -a is an object and I have changed its type and value from outside. Incorrect. You have not changed

Re: Encapsulation unpythonic?

2013-08-31 Thread Tim Delaney
On 1 September 2013 03:31, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: On Fri, 30 Aug 2013 23:07:47 -0700 (PDT), Fabrice Pombet fp2...@gmail.com declaimed the following: well, look at that: a=(1,2) a=2+3 -a is an object and I have changed its type and value from outside. As far as I

Re: Encapsulation unpythonic?

2013-08-30 Thread Fabrice Pombet
declaration but in the many examples of code I looked at this is not widely used. I also read that encapsulation is unpythonic. Questions: 2) If it is in fact true that encapsulation is rarely used, how do I deal with the fact that other programmers can easily alter the values

Re: Encapsulation unpythonic?

2013-08-30 Thread Steven D'Aprano
On Fri, 30 Aug 2013 10:43:28 -0700, Fabrice Pombet wrote: On Saturday, August 17, 2013 2:26:32 PM UTC+2, Fernando Saldanha wrote: 2) If it is in fact true that encapsulation is rarely used, how do I deal with the fact that other programmers can easily alter the values of members of my

Re: Encapsulation unpythonic?

2013-08-22 Thread chaz2cry
declaration but in the many examples of code I looked at this is not widely used. I also read that encapsulation is unpythonic. Questions: 1) Is there a good text where I can read about the language philosophy? What practices are pythonic or unpythonic? 2) If it is in fact

Re: Encapsulation unpythonic?

2013-08-21 Thread random832
On Mon, Aug 19, 2013, at 3:05, Steven D'Aprano wrote: In this toy example, both parties are at fault: the author of Parrot for unnecessary data-hiding of something which is so obviously a useful piece of information and should be part of the public interface, It may wish to be notified when

Re: Encapsulation unpythonic?

2013-08-21 Thread Ian Kelly
On Aug 21, 2013 10:53 AM, random...@fastmail.us wrote: On Mon, Aug 19, 2013, at 3:05, Steven D'Aprano wrote: In this toy example, both parties are at fault: the author of Parrot for unnecessary data-hiding of something which is so obviously a useful piece of information and should be part

Re: Encapsulation unpythonic?

2013-08-21 Thread Steven D'Aprano
On Wed, 21 Aug 2013 12:52:06 -0400, random832 wrote: On Mon, Aug 19, 2013, at 3:05, Steven D'Aprano wrote: In this toy example, both parties are at fault: the author of Parrot for unnecessary data-hiding of something which is so obviously a useful piece of information and should be part of

Re: Encapsulation unpythonic?

2013-08-19 Thread Steven D'Aprano
On Sun, 18 Aug 2013 18:15:10 +0100, Joshua Landau wrote: On 17 August 2013 17:17, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Sat, 17 Aug 2013 05:26:32 -0700, fsaldan1 wrote: how do I deal with the fact that other programmers can easily alter the values of members of my

Re: Encapsulation unpythonic?

2013-08-18 Thread Joshua Landau
On 17 August 2013 17:17, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Sat, 17 Aug 2013 05:26:32 -0700, fsaldan1 wrote: how do I deal with the fact that other programmers can easily alter the values of members of my classes? ... If they insist on messing with your private

Encapsulation unpythonic?

2013-08-17 Thread fsaldan1
. I also read that encapsulation is unpythonic. Questions: 1) Is there a good text where I can read about the language philosophy? What practices are pythonic or unpythonic? 2) If it is in fact true that encapsulation is rarely used, how do I deal with the fact that other programmers can easily

Re: Encapsulation unpythonic?

2013-08-17 Thread Skip Montanaro
In Guido's own words: We're all consenting adults here. http://importthis.tumblr.com/post/6719643315/public-private-attributes Skip -- http://mail.python.org/mailman/listinfo/python-list

Re: Encapsulation unpythonic?

2013-08-17 Thread David
On 17 August 2013 22:26, fsald...@gmail.com wrote: 1) Is there a good text where I can read about the language philosophy? What practices are pythonic or unpythonic? 2) If it is in fact true that encapsulation is rarely used, how do I deal with the fact that other programmers can easily

Re: Encapsulation unpythonic?

2013-08-17 Thread Chris Angelico
On Sat, Aug 17, 2013 at 1:26 PM, fsald...@gmail.com wrote: 2) If it is in fact true that encapsulation is rarely used, how do I deal with the fact that other programmers can easily alter the values of members of my classes? Very simply: You accept it. Let them! It's their responsibility.

Re: Encapsulation unpythonic?

2013-08-17 Thread Steven D'Aprano
that encapsulation is unpythonic. That's *data hiding*, not encapsulation. Very few languages -- possibly none at all -- can hide data from a sufficiently motivated programmer. Python doesn't even try. We're all adults here is the philosophy, and data hiding is by convention, not enforced

Re: Encapsulation unpythonic?

2013-08-17 Thread Gary Herron
examples of code I looked at this is not widely used. I also read that encapsulation is unpythonic. Questions: 1) Is there a good text where I can read about the language philosophy? What practices are pythonic or unpythonic? 2) If it is in fact true that encapsulation is rarely used, how do I deal

Re: Encapsulation unpythonic?

2013-08-17 Thread Terry Reedy
On 8/17/2013 11:50 AM, Chris Angelico wrote: On Sat, Aug 17, 2013 at 1:26 PM, fsald...@gmail.com wrote: 2) If it is in fact true that encapsulation is rarely used, how do I deal with the fact that other programmers can easily alter the values of members of my classes? Very simply: You

Re: Encapsulation unpythonic?

2013-08-17 Thread Chris Angelico
On Sat, Aug 17, 2013 at 10:22 PM, Terry Reedy tjre...@udel.edu wrote: On 8/17/2013 11:50 AM, Chris Angelico wrote: On Sat, Aug 17, 2013 at 1:26 PM, fsald...@gmail.com wrote: 2) If it is in fact true that encapsulation is rarely used, how do I deal with the fact that other programmers can

Re: unpythonic use of property()?

2009-04-22 Thread Luis Zarrabeitia
On Monday 20 April 2009 11:29:19 am J Kenneth King wrote: Changing the ID value would break things on the server, so I wanted to write the interface class to respect those conventions. Then, take this opportunity fix the server and prevent it from breaking once you change the ID, because:

Re: unpythonic use of property()?

2009-04-22 Thread J Kenneth King
Luis Zarrabeitia ky...@uh.cu writes: On Monday 20 April 2009 11:29:19 am J Kenneth King wrote: Changing the ID value would break things on the server, so I wanted to write the interface class to respect those conventions. Then, take this opportunity fix the server and prevent it from

Re: unpythonic use of property()?

2009-04-22 Thread Luis Zarrabeitia
On Wednesday 22 April 2009 01:44:38 pm J Kenneth King wrote: Then, take this opportunity fix the server and prevent it from breaking once you change the ID, because: Unfortunately it's not my server to fix. I can suggest a patch, but that's it. Yes, that's unfortunate. Btw, when I re-read

Re: unpythonic use of property()?

2009-04-22 Thread J Kenneth King
Luis Zarrabeitia ky...@uh.cu writes: On Wednesday 22 April 2009 01:44:38 pm J Kenneth King wrote: Then, take this opportunity fix the server and prevent it from breaking once you change the ID, because: Unfortunately it's not my server to fix. I can suggest a patch, but that's it. Yes,

Re: unpythonic use of property()?

2009-04-20 Thread J Kenneth King
        self.foo = foo     @property     def id(self):         return self._id ... I was recently informed that it was 'unpythonic' and have since been a little confused by the term. I've heard it bandied about before but never paid much attention. What is 'unpythonic'? What about

Re: unpythonic use of property()?

2009-04-20 Thread Michele Simionato
On Apr 17, 7:21 pm, J Kenneth King ja...@agentultra.com wrote: Consider: code: class MyInterface(object):     def __get_id(self):         return self.__id     id = property(fget=__get_id)     def __init__(self,

unpythonic use of property()?

2009-04-17 Thread J Kenneth King
or generators. I'd like a more concrete explanation from someone who has encountered a scenario where it was required. I was recently informed that it was 'unpythonic' and have since been a little confused by the term. I've heard it bandied about before but never paid much attention. What is 'unpythonic

Re: unpythonic use of property()?

2009-04-17 Thread Carl Banks
version stores its data in a name-mangled attribute (two underscores), but you can also use a name-mangled attribute for the MyInterface2 version if you want. Neither version is foolproof. I was recently informed that it was 'unpythonic' and have since been a little confused by the term. I've

Re: unpythonic use of property()?

2009-04-17 Thread Scott David Daniels
__init__(self, id, foo): self.__id = id self.foo = foo class MyInterface2(object): def __init__(self, id, foo): self._id = id self.foo = foo @property def id(self): return self._id ... I was recently informed that it was 'unpythonic' and have

Re: unpythonic use of property()?

2009-04-17 Thread Carl Banks
id(self):         return self._id ... I was recently informed that it was 'unpythonic' and have since been a little confused by the term. I've heard it bandied about before but never paid much attention. What is 'unpythonic'? What about this example is unpythonic? There are different

Unpythonic? Impossible??

2006-03-19 Thread BrJohan
Assume having this class hierarchy: (in principle and without details) class A(object): class B1(A): class B2(A): class C1(A1): class C2(A1): class C3(B1): class C4(B2): each of those classes have an initializer __init__(self, data): and an overloaded __new__(cls,

Re: Unpythonic? Impossible??

2006-03-19 Thread Scott David Daniels
factory - and could work around using such a mechanism. However I am interested to know if I could let the classes do the work by themselves. Yes, it can be done. Yes, it is unclear (and hence UnPythonic). The class factory _is_ the straightforward way to do this. The following

Re: Unpythonic? Impossible??

2006-03-19 Thread Felipe Almeida Lessa
Em Dom, 2006-03-19 às 08:54 -0800, Scott David Daniels escreveu: class A(object): def __new__(class_, *args, **kwargs): if class_ is A: if want_a_B1(*args, **kwargs): return B1(*args, **kwargs) elif

Re: Unpythonic? Impossible??

2006-03-19 Thread BrJohan
be done. Yes, it is unclear (and hence UnPythonic). The class factory _is_ the straightforward way to do this. The following is the workaround (if you have to maintain A(...)): class A(object): def __new__(class_, *args, **kwargs): if class_

Re: Unpythonic? Impossible??

2006-03-19 Thread Scott David Daniels
Felipe Almeida Lessa wrote: Em Dom, 2006-03-19 às 08:54 -0800, Scott David Daniels escreveu: class A(object): def __new__(class_, *args, **kwargs): if class_ is A: if want_a_B1(*args, **kwargs): return B1(*args, **kwargs)

Re: Unpythonic? Impossible??

2006-03-19 Thread Erik Max Francis
BrJohan wrote: I know how to use a class factory - and could work around using such a mechanism. However I am interested to know if I could let the classes do the work by themselves. You can, but a class factory is going to be much clearer and probably more maintainable. From the user's

Re: Unpythonic? Impossible??

2006-03-19 Thread Paul Rubin
Erik Max Francis [EMAIL PROTECTED] writes: You can, but a class factory is going to be much clearer and probably more maintainable. From the user's perspective, there's no difference from calling a class A to instantiate it, and calling a factory function called A that selects the appropriate

Re: Unpythonic? Impossible??

2006-03-19 Thread Erik Max Francis
Paul Rubin wrote: I remember having a similar problem involving multiple base classes and deciding that factory functions couldn't do quite what I wanted. Here's a thread about it, with a recipe using metaclasses by Roeland Rengelink: http://tinyurl.com/rz6ne Unfortunately, the

Re: A rather unpythonic way of doing things

2005-10-01 Thread Tom Anderson
On Thu, 29 Sep 2005, Peter Corbett wrote: One of my friends has recently taken up Python, and was griping a bit about the language (it's too prescriptive for his tastes). In particular, he didn't like the way that Python expressions were a bit crippled. So I delved a bit into the language,

A rather unpythonic way of doing things

2005-09-29 Thread Peter Corbett
One of my friends has recently taken up Python, and was griping a bit about the language (it's too prescriptive for his tastes). In particular, he didn't like the way that Python expressions were a bit crippled. So I delved a bit into the language, and found some sources of syntactic sugar that I

Re: A rather unpythonic way of doing things

2005-09-29 Thread Richie Hindle
[Peter] http://www.pick.ucam.org/~ptc24/yvfc.html Beautiful! Greenspun's Tenth Rule[1] performed before your very eyes! (Not quite, because you started with Python so you were already half way there. And yours probably isn't buggy. 8-) [1] http://en.wikipedia.org/wiki/Greenspun's_Tenth_Rule

Re: A rather unpythonic way of doing things

2005-09-29 Thread Paul Rubin
Peter Corbett [EMAIL PROTECTED] writes: http://www.pick.ucam.org/~ptc24/yvfc.html Madness! I love it. -- http://mail.python.org/mailman/listinfo/python-list

Re: A rather unpythonic way of doing things

2005-09-29 Thread Jeff Schwab
Peter Corbett wrote: One of my friends has recently taken up Python, and was griping a bit about the language (it's too prescriptive for his tastes). In particular, he didn't like the way that Python expressions were a bit crippled. So I delved a bit into the language, and found some sources

Re: A rather unpythonic way of doing things

2005-09-29 Thread Richie Hindle
[Peter] http://www.pick.ucam.org/~ptc24/yvfc.html [Jeff] Yuma Valley Agricultural Center? Yaak Valley Forest Council? I went through the same process. My guess is Yes, Very F'ing Clever. Peter? -- Richie Hindle [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: A rather unpythonic way of doing things

2005-09-29 Thread Peter Corbett
Richie Hindle [EMAIL PROTECTED] writes: [Peter] http://www.pick.ucam.org/~ptc24/yvfc.html [Jeff] Yuma Valley Agricultural Center? Yaak Valley Forest Council? I went through the same process. My guess is Yes, Very F'ing Clever. Peter? You're all thinking about it the wrong way (he

Re: A rather unpythonic way of doing things

2005-09-29 Thread Michael Ekstrand
On Thursday 29 September 2005 04:53, Peter Corbett wrote: One of my friends has recently taken up Python, and was griping a bit about the language (it's too prescriptive for his tastes). In particular, he didn't like the way that Python expressions were a bit crippled. So I delved a bit into

Re: A rather unpythonic way of doing things

2005-09-29 Thread fraca7
Richie Hindle a écrit : [Peter] http://www.pick.ucam.org/~ptc24/yvfc.html [Jeff] Yuma Valley Agricultural Center? Yaak Valley Forest Council? I went through the same process. My guess is Yes, Very F'ing Clever. Peter? print ''.join(map(lambda x: chrord(x) - ord('a')) + 13)

Re: A rather unpythonic way of doing things

2005-09-29 Thread Jeff Schwab
fraca7 wrote: Richie Hindle a écrit : [Peter] http://www.pick.ucam.org/~ptc24/yvfc.html [Jeff] Yuma Valley Agricultural Center? Yaak Valley Forest Council? I went through the same process. My guess is Yes, Very F'ing Clever. Peter? print ''.join(map(lambda x: chrord(x) -

Re: A rather unpythonic way of doing things

2005-09-29 Thread Cyril Bazin
Crypthonic could be the exact word...On 29 Sep 2005 15:19:11 +0100, Peter Corbett [EMAIL PROTECTED] wrote:Richie Hindle [EMAIL PROTECTED] writes: [Peter] http://www.pick.ucam.org/~ptc24/yvfc.html [Jeff] Yuma Valley Agricultural Center? Yaak Valley Forest Council? I went through the same

Re: A rather unpythonic way of doing things

2005-09-29 Thread Rocco Moretti
fraca7 wrote: Richie Hindle a écrit : [Peter] http://www.pick.ucam.org/~ptc24/yvfc.html [Jeff] Yuma Valley Agricultural Center? Yaak Valley Forest Council? I went through the same process. My guess is Yes, Very F'ing Clever. Peter? print ''.join(map(lambda x: chrord(x) -

Re: A rather unpythonic way of doing things

2005-09-29 Thread Fredrik Lundh
fraca7 wrote: print ''.join(map(lambda x: chrord(x) - ord('a')) + 13) % 26) + ord('a')), 'yvfc')) that's spelled print yvfc.decode(rot-13) or, if you prefer, print yvfc.encode(rot-13) , in contemporary python. /F -- http://mail.python.org/mailman/listinfo/python-list

Re: A rather unpythonic way of doing things

2005-09-29 Thread Simon Brunning
On 9/29/05, Fredrik Lundh [EMAIL PROTECTED] wrote: fraca7 wrote: print ''.join(map(lambda x: chrord(x) - ord('a')) + 13) % 26) + ord('a')), 'yvfc')) that's spelled print yvfc.decode(rot-13) or, if you prefer, print yvfc.encode(rot-13) , in contemporary python. I'm not

A (unpythonic) pythonable mixin recipe.

2005-08-16 Thread Paolino
I had always been negative on the boldeness of python on insisting that unbound methods should have been applied only to its im_class instances. Anyway this time I mixed in rightly, so I post this for comments. ## looking for a discovery .Start # class _Mixin(object): def