Re: new-style class or old-style class?

2012-09-26 Thread Ramchandra Apte
On Tuesday, 25 September 2012 20:14:05 UTC+5:30, Jayden  wrote:
 In learning Python, I found there are two types of classes? Which one are 
 widely used in new Python code? Is the new-style much better than old-style? 
 Thanks!!

Next time just Google your questions.
:-)
Good luck with Python
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new-style class or old-style class?

2012-09-26 Thread Roy Smith
In article 2e8a9e88-9e7e-43f7-a070-ea9054e62...@googlegroups.com,
 Jayden jayden.s...@gmail.com wrote:

 In learning Python, I found there are two types of classes? Which one are 
 widely used in new Python code? Is the new-style much better than old-style? 
 Thanks!!

If you're just learning Python 2.x, you might as well use new-style 
classes, since that's what all classes are in 3.x.

On the other hand, if you're just learning, it probably doesn't matter 
which kind you use.  Until you get into some pretty sophisticated stuff, 
you won't notice any difference between the two.

On the third hand, all it takes to create a new-style class is to have 
it inherit from object.  It's no big deal to write

 class Foo(object):

instead of just

 class Foo:

so you might as well use new-style classes :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new-style class or old-style class?

2012-09-26 Thread wxjmfauth
Le mardi 25 septembre 2012 16:44:05 UTC+2, Jayden a écrit :
 In learning Python, I found there are two types of classes? Which one are 
 widely used in new Python code? Is the new-style much better than old-style? 
 Thanks!!

Use Python 3 and classes. 


---

The interesting point or my question.

Why a Python beginner arrives here and should ask about this?

jmf
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new-style class or old-style class?

2012-09-26 Thread alex23
On Sep 27, 6:15 am, wxjmfa...@gmail.com wrote:
 The interesting point or my question.
 Why a Python beginner arrives here and should ask about this?

Would you prefer that they'd instead make some kind of false
assumption and then post endless screeds condemning it?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new-style class or old-style class?

2012-09-25 Thread Littlefield, Tyler

On 9/25/2012 8:44 AM, Jayden wrote:

In learning Python, I found there are two types of classes? Which one are 
widely used in new Python code? Is the new-style much better than old-style? 
Thanks!!



Perhaps this is useful:
http://docs.python.org/reference/datamodel.html
It's 3.3 I think.

--
Take care,
Ty
http://tds-solutions.net
The aspen project: a barebones light-weight mud engine:
http://code.google.com/p/aspenmud
He that will not reason is a bigot; he that cannot reason is a fool; he that 
dares not reason is a slave.

--
http://mail.python.org/mailman/listinfo/python-list


Re: new-style class or old-style class?

2012-09-25 Thread Chris Angelico
On Wed, Sep 26, 2012 at 12:44 AM, Jayden jayden.s...@gmail.com wrote:
 In learning Python, I found there are two types of classes? Which one are 
 widely used in new Python code? Is the new-style much better than old-style? 
 Thanks!!

Definitely go with new-style. In Python 3, old-style classes aren't
supported, and the syntax that would create an old-style class in
Python 2 will implicitly create a new-style class. (Explicitly
subclassing object still works in Py3, so you can happily use that
syntax for both.)

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new-style class or old-style class?

2012-09-25 Thread Steven D'Aprano
On Tue, 25 Sep 2012 07:44:04 -0700, Jayden wrote:

 In learning Python, I found there are two types of classes? Which one
 are widely used in new Python code? 

New-style classes.

 Is the new-style much better than old-style?

Yes.

Always use new-style classes, unless you have some specific reason for 
needing old-style (classic) classes.

Advantages of new-style classes:

1) They are the future. In Python 3, all classes are new-style and 
classic classes are gone.

2) Multiple inheritance works correctly. Multiple inheritance for classic 
classes is buggy.

3) New-style classes support awesome features like super(), properties, 
descriptors, and __getattribute__. Old-style do not.

The main disadvantage is that automatic delegation is a pain to do 
correctly in new-style classes, but trivially simple in classic classes. 
Still, all things considered, it's a good trade.



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new-style class or old-style class?

2012-09-25 Thread Mark Lawrence

On 25/09/2012 17:20, Steven D'Aprano wrote:

On Tue, 25 Sep 2012 07:44:04 -0700, Jayden wrote:


In learning Python, I found there are two types of classes? Which one
are widely used in new Python code?


New-style classes.


Is the new-style much better than old-style?


Yes.

Always use new-style classes, unless you have some specific reason for
needing old-style (classic) classes.

Advantages of new-style classes:

1) They are the future. In Python 3, all classes are new-style and
classic classes are gone.

2) Multiple inheritance works correctly. Multiple inheritance for classic
classes is buggy.

3) New-style classes support awesome features like super(), properties,
descriptors, and __getattribute__. Old-style do not.

The main disadvantage is that automatic delegation is a pain to do
correctly in new-style classes, but trivially simple in classic classes.
Still, all things considered, it's a good trade.





Thanks for this reminder, my port of the J word code to Python has just 
been simplified :)


--
Cheers.

Mark Lawrence.

--
http://mail.python.org/mailman/listinfo/python-list


Re: new style class

2007-12-12 Thread Bruce Coram
Steven

Regrettably I have to reply to your post because it misses the point of 
my initial post completely.  I suggested that Eric Raymond's advice 
provided cover for people who were rude, hostile or arrogant.  There are 
two obvious responses:  his advice does not provide such cover or it 
does but it does not matter.  It make no assertions about any particular 
person or group of persons.  It merely suggests that people who were 
disposed to rudeness could point to his article as supporting their 
approach.  It was a plea that we conduct ourselves in a civil manner and 
treat other people with respect.

I might be justified in assuming that you have spent some time working 
with politicians because you impute arguments to me that I do not make.  
At no point do I suggest that pointing somebody at Eric Raymond's advice 
is rude, hostile or arrogant, and your interpretation of my words to 
arrive at this is perverse.  It may be that English is not your first 
language in which case such a slip could be excused.  If not, it is 
evidence either of slipshod thinking or wilfull manipulation and 
obfuscation. If it is the latter then the post does not sit well in a 
forum that strives for accuracy.

Had I written:
The best response to those who *we assume* can not be bothered  to do 
the necessary work is either no reply or a simple You would be  well 
advised to do some research before asking your question.

you would be justified in claiming that my advice was not to give any 
advice. I did not include the words 'we assume' and therefore my advice 
either to stop replying or to give a polite sign off was based on there 
being evidence that a person seeking advice could not be bothered i.e. 
there had been sufficient contact to allow that conclusion to be drawn 
in a reasonable manner.  English is a language that permits great 
precision in conveying meaning.  However, it is necessary on occasions 
to do some work and thinking in order to extract the writer's idea.

You also seem to have overlooked that I state twice that Eric Raymond's 
advice is good or very good.

I have no desire to to indulge in online verbal brawling but please take 
more care in drafting a reply, particularly in a situation where your 
interpretation of my post might lead others who post to believe that I 
thought them rude, hostile or arrogant.

Bruce Coram



Steven D'Aprano wrote:
 On Sat, 08 Dec 2007 23:14:44 +, Bruce Coram wrote:

   
 http://www.catb.org/~esr/faqs/smart-questions.html
   
   
 Eric Raymond's advice on how to ask questions the smart way would seem
 to provide an excuse for people with ego control problems to indulge
 themselves at the expense of others.  While it is undoubtedly true that
 there are people who post who should spend more time reading and
 researching the problem, that is no excuse for replies that  are rude,
 hostile or exhibit similar displays of ill-tempered arrogance.
 

 Pointing somebody at Eric Raymond's advice is neither rude, hostile or 
 arrogant. It may be brusque. It may fail to sugar-coat the message 
 sufficiently, and hurt some recipient's feelings, but that's their 
 problem, not that of the sender.


   
 Eric
 Raymond should perhaps re-read his advice and re-draft it to avoid
 providing cover for those 'experts' who are either rude or ignorant - or
 both.
 

 Why don't you do so yourself? He solicits suggestions and revisions.

 Or ask for permission to fork the document and come up with your own. 
 (You have to ask first, because as far as I can see the document is not 
 released with an open licence.)


   
 If an 'expert' has time to indulge his/her ego is such an
 intemperate manner then he/she probably doesn't have enough to do, or
 enjoys being rude.  
 

 Dare I suggest that perhaps YOU should read smart-questions? In 
 particular, the bits where Raymond writes about RTFM:

 You shouldn't be offended by this; by hacker standards, your respondent 
 is showing you a rough kind of respect simply by not ignoring you. You 
 should instead be thankful for this grandmotherly kindness.

 Pointing somebody at smart-questions is a rather more polite form of RTFM.


   
 The best response to those who can not be bothered
 to do the necessary work is either no reply 
 

 Ignoring people's request for help to punish them for poor behaviour is 
 not only rude but it is counter-productive. Not only do you not solve 
 their immediate problem, but you keep them in a state of ignorance as to 
 why they are being shunned -- thus guaranteeing that they will invariably 
 transgress again.


   
 or a simple You would be
 well advised to do some research before asking your question.
 

 Again leaving them no better off and still likely to transgress in the 
 future. How much is some? What sort of research? Asking on Usenet is 
 research isn't it? Why should I be expected to struggle with this on my 
 own when there are people out there who already know the answer?

 

Re: new style class

2007-12-08 Thread Bruce Coram
Aahz wrote:
 In article [EMAIL PROTECTED],
 Nigel Rantor  [EMAIL PROTECTED] wrote:
   
 I think what Boris was being exceedingly unhelpful in saying was why 
 should it work when you're calling methods that do not exist
 

 http://www.catb.org/~esr/faqs/smart-questions.html
   
Eric Raymond's advice on how to ask questions the smart way would seem 
to provide an excuse for people with ego control problems to indulge 
themselves at the expense of others.  While it is undoubtedly true that 
there are people who post who should spend more time reading and 
researching the problem, that is no excuse for replies that  are rude, 
hostile or exhibit similar displays of ill-tempered arrogance.  Eric 
Raymond should perhaps re-read his advice and re-draft it to avoid 
providing cover for those 'experts' who are either rude or ignorant - or 
both.   If an 'expert' has time to indulge his/her ego is such an 
intemperate manner then he/she probably doesn't have enough to do, or 
enjoys being rude.  The best response to those who can not be bothered 
to do the necessary work is either no reply or a simple You would be 
well advised to do some research before asking your question.   We do 
not need to make life any more difficult than it already is.  Civility 
costs nothing.  Eric Raymond's article, which offer's good advice, is 
rather misguided in not only providing an excuse for poor behaviour but 
almost actively encouraging it.  This is a pity since the essence of the 
document is very good advice.

Bruce Coram

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new style class

2007-12-08 Thread Steven D'Aprano
On Sat, 08 Dec 2007 23:14:44 +, Bruce Coram wrote:

 http://www.catb.org/~esr/faqs/smart-questions.html
   
 Eric Raymond's advice on how to ask questions the smart way would seem
 to provide an excuse for people with ego control problems to indulge
 themselves at the expense of others.  While it is undoubtedly true that
 there are people who post who should spend more time reading and
 researching the problem, that is no excuse for replies that  are rude,
 hostile or exhibit similar displays of ill-tempered arrogance.

Pointing somebody at Eric Raymond's advice is neither rude, hostile or 
arrogant. It may be brusque. It may fail to sugar-coat the message 
sufficiently, and hurt some recipient's feelings, but that's their 
problem, not that of the sender.


 Eric
 Raymond should perhaps re-read his advice and re-draft it to avoid
 providing cover for those 'experts' who are either rude or ignorant - or
 both.

Why don't you do so yourself? He solicits suggestions and revisions.

Or ask for permission to fork the document and come up with your own. 
(You have to ask first, because as far as I can see the document is not 
released with an open licence.)


 If an 'expert' has time to indulge his/her ego is such an
 intemperate manner then he/she probably doesn't have enough to do, or
 enjoys being rude.  

Dare I suggest that perhaps YOU should read smart-questions? In 
particular, the bits where Raymond writes about RTFM:

You shouldn't be offended by this; by hacker standards, your respondent 
is showing you a rough kind of respect simply by not ignoring you. You 
should instead be thankful for this grandmotherly kindness.

Pointing somebody at smart-questions is a rather more polite form of RTFM.


 The best response to those who can not be bothered
 to do the necessary work is either no reply 

Ignoring people's request for help to punish them for poor behaviour is 
not only rude but it is counter-productive. Not only do you not solve 
their immediate problem, but you keep them in a state of ignorance as to 
why they are being shunned -- thus guaranteeing that they will invariably 
transgress again.


 or a simple You would be
 well advised to do some research before asking your question.

Again leaving them no better off and still likely to transgress in the 
future. How much is some? What sort of research? Asking on Usenet is 
research isn't it? Why should I be expected to struggle with this on my 
own when there are people out there who already know the answer?

These are all reasonable thoughts that a poster might have. Then there 
are the unreasonable thoughts, like the poster who once told me off for 
asking for a traceback so we could see what his error was. He actually 
took the time to write to me to abuse me for wasting *his* time, when I 
could just as easily copy the code from his post, fix the broken 
indentation and typos, save it to a file and run it myself.

How do you expect people to learn better if we follow your advice?


 We do not need to make life any more difficult than it already is.

Following your advise will make life worse.

 Civility costs nothing.

Teaching people to ask appropriate questions is being civil.

 Eric Raymond's article, which offer's good advice, is
 rather misguided in not only providing an excuse for poor behaviour but
 almost actively encouraging it.  This is a pity since the essence of the
 document is very good advice.

Shame you haven't understood it, because your suggestions are 
diametrically opposed to his message. Raymond's message is about teaching 
people how to learn for themselves. Your message is to ignore their 
request for help and let them keep floundering in the dark.



-- 
Steven.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new style class

2007-11-02 Thread Wildemar Wildenburger
gert wrote:
 oops the code is like this but doesn't work
 
 class Test(object):
 
 def m1(self,v):
 return v
 
 def m2(v):
 return v
 
 if  __name__ == '__main__':
 gert = Test()
 print gert.m1('1')
 print Test.m2('2')
 


Well, what do you think:
 In [9]: gert = Test()
 
 In [10]: print gert.m1('1')
: print Test.m2('2')
: 
 1
 ---
 type 'exceptions.TypeError' Traceback (most recent call last)
 
 /home/wildemar/ipython console in module()
 
 type 'exceptions.TypeError': unbound method m2() must be called with Test 
 instance as first argument (got str instance instead)

(Another hint: look at what m1 has that m2 lacks.)

/W
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new style class

2007-11-02 Thread Tim Chase
gert wrote:
 On Nov 2, 12:27 pm, Boris Borcic [EMAIL PROTECTED] wrote:
 gert wrote:
 class Test(object):
 def execute(self,v):
 return v
 def escape(v):
 return v
 if  __name__ == '__main__':
 gert = Test()
 print gert.m1('1')
 print Test.m2('2')
 Why doesn't this new style class work in python 2.5.1 ?
 why should it ?
 
 I don't know I thought it was supported from 2.2?

I don't recall Python supporting non-existent method-calls (such
as m1/m2 when they aren't actually defined) in ANY version of Python.

But once you change that, you'll likely also want to investigate
the classmethod decorator if you want to create class-methods.

-tkc



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new style class

2007-11-02 Thread Wildemar Wildenburger
gert wrote:
 On Nov 2, 12:27 pm, Boris Borcic [EMAIL PROTECTED] wrote:
 gert wrote:
 class Test(object):
 def execute(self,v):
 return v
 def escape(v):
 return v
 if  __name__ == '__main__':
 gert = Test()
 print gert.m1('1')
 print Test.m2('2')
 Why doesn't this new style class work in python 2.5.1 ?
 why should it ?
 
 I don't know I thought it was supported from 2.2?
 
Look at the error you get.

Repeat: LOOK AT THE ERROR YOU GET!

(Hint: m1 not in (execute, escape))

Nothing to do with old- or new-style classes.
/W
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new style class

2007-11-02 Thread gert
On Nov 2, 12:31 pm, gert [EMAIL PROTECTED] wrote:
 On Nov 2, 12:27 pm, Boris Borcic [EMAIL PROTECTED] wrote:



  gert wrote:
   class Test(object):

   def execute(self,v):
   return v

   def escape(v):
   return v

   if  __name__ == '__main__':
   gert = Test()
   print gert.m1('1')
   print Test.m2('2')

   Why doesn't this new style class work in python 2.5.1 ?

  why should it ?

 I don't know I thought it was supported from 2.2?

oops the code is like this but doesn't work

class Test(object):

def m1(self,v):
return v

def m2(v):
return v

if  __name__ == '__main__':
gert = Test()
print gert.m1('1')
print Test.m2('2')

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new style class

2007-11-02 Thread Martin Sand Christensen
 gert == gert  [EMAIL PROTECTED] writes:
gert Why doesn't this new style class work in python 2.5.1 ?

Whether you declare your class as a new style class or an old style
class, your code is completely and utterly broken. Calling non-existing
methods has never been a good way of getting things done. :-)

Martin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new style class

2007-11-02 Thread gert
On Nov 2, 12:27 pm, Boris Borcic [EMAIL PROTECTED] wrote:
 gert wrote:
  class Test(object):

  def execute(self,v):
  return v

  def escape(v):
  return v

  if  __name__ == '__main__':
  gert = Test()
  print gert.m1('1')
  print Test.m2('2')

  Why doesn't this new style class work in python 2.5.1 ?

 why should it ?

I don't know I thought it was supported from 2.2?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new style class

2007-11-02 Thread Boris Borcic
gert wrote:
 Could not one of you just say @staticmethod for once damnit :)
 

I did, did I not ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new style class

2007-11-02 Thread Bjoern Schliessmann
Wildemar Wildenburger wrote:
 Bjoern Schliessmann wrote:

 No, since everyone's crystal balls are in repair.
 
 I don't even have crystal balls!

Not many are rich *and* impotent. :)

Regards,


Björn

-- 
BOFH excuse #14:

sounds like a Windows problem, try calling Microsoft support

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new style class

2007-11-02 Thread Nigel Rantor
gert wrote:
 Could not one of you just say @staticmethod for once damnit :)
 

why were you asking if you knew the answer?

yeesh
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new style class

2007-11-02 Thread Nigel Rantor
gert wrote:
 On Nov 2, 12:27 pm, Boris Borcic [EMAIL PROTECTED] wrote:
 gert wrote:
 class Test(object):
 def execute(self,v):
 return v
 def escape(v):
 return v
 if  __name__ == '__main__':
 gert = Test()
 print gert.m1('1')
 print Test.m2('2')
 Why doesn't this new style class work in python 2.5.1 ?
 why should it ?
 
 I don't know I thought it was supported from 2.2?
 

I think what Boris was being exceedingly unhelpful in saying was why 
should it work when you're calling methods that do not exist

I don't see 'm1' or 'm2' defined for the class 'Test'.

   n

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new style class

2007-11-02 Thread Wildemar Wildenburger
Bjoern Schliessmann wrote:
 gert wrote:
 Could not one of you just say @staticmethod for once damnit :)
 
 No, since everyone's crystal balls are in repair.
 

I don't even have crystal balls!

/W
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new style class

2007-11-02 Thread Boris Borcic
gert wrote:
 class Test(object):
 
 def execute(self,v):
 return v
 
 def escape(v):
 return v
 
 if  __name__ == '__main__':
 gert = Test()
 print gert.m1('1')
 print Test.m2('2')
 
 Why doesn't this new style class work in python 2.5.1 ?
 

why should it ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new style class

2007-11-02 Thread gert
On Nov 2, 4:04 pm, Boris Borcic [EMAIL PROTECTED] wrote:
 gert wrote:
  Could not one of you just say @staticmethod for once damnit :)

 I did, did I not ?

i am sorry, yes you did :)

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new style class

2007-11-02 Thread gert
On Nov 2, 2:10 pm, Wildemar Wildenburger
[EMAIL PROTECTED] wrote:
 Bjoern Schliessmann wrote:
  gert wrote:
  Could not one of you just say @staticmethod for once damnit :)

  No, since everyone's crystal balls are in repair.

 I don't even have crystal balls!

 /W

lol

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new style class

2007-11-02 Thread Boris Borcic
gert wrote:
[...]

 Why doesn't this new style class work in python 2.5.1 ?
 why should it ?
 I don't know I thought it was supported from 2.2?
 
 oops the code is like this but doesn't work
 
 class Test(object):
 
 def m1(self,v):
 return v
 
 def m2(v):
 return v
 
 if  __name__ == '__main__':
 gert = Test()
 print gert.m1('1')
 print Test.m2('2')
 

You should put a '@staticmethod' decorator before your m2 method definition


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new style class

2007-11-02 Thread Bjoern Schliessmann
gert wrote:

 oops the code is like this but doesn't work

For sake of the god of your choice, please always provide runnable
code as well as hints to

- what you think it should do
- what you want it to do
- what exact error message(s) you get

NOT just it doesn't work.
 
Regards,


Björn

-- 
BOFH excuse #279:

The static electricity routing is acting up...

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new style class

2007-11-02 Thread gert
Could not one of you just say @staticmethod for once damnit :)

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new style class

2007-11-02 Thread Bjoern Schliessmann
gert wrote:
 Could not one of you just say @staticmethod for once damnit :)

No, since everyone's crystal balls are in repair.

Regards,


Björn

-- 
BOFH excuse #256:

You need to install an RTFM interface.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new style class

2007-11-02 Thread Aahz
In article [EMAIL PROTECTED],
Nigel Rantor  [EMAIL PROTECTED] wrote:

I think what Boris was being exceedingly unhelpful in saying was why 
should it work when you're calling methods that do not exist

http://www.catb.org/~esr/faqs/smart-questions.html
-- 
Aahz ([EMAIL PROTECTED])   * http://www.pythoncraft.com/

Typing is cheap.  Thinking is expensive.  --Roy Smith
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new style class

2007-11-02 Thread Gabriel Genellina
En Fri, 02 Nov 2007 08:58:32 -0300, gert [EMAIL PROTECTED] escribió:

 Could not one of you just say @staticmethod for once damnit :)

Do we have to read your mind now? You miss-typed the method names the  
first time. You could equally have forgotten to type the 'self' parameter.  
Don't you expect too much?

BTW, most of the time staticmethods are NOT required at all. Using a plain  
function instead is perfectly valid unless you have a special reason to  
prefer a staticmethod.

-- 
Gabriel Genellina

-- 
http://mail.python.org/mailman/listinfo/python-list