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/mai

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 ques

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

2012-09-26 Thread Roy Smith
ween 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 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 --

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

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 re

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

2012-09-25 Thread Chris Angelico
27;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 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. -- Ta

new-style class or old-style class?

2012-09-25 Thread Jayden
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!! -- http://mail.python.org/mailman/listinfo/python-list

Pickle of the instance of new style class fails when execute with exec statement

2009-05-26 Thread Борис Казаков
Hi, I'm trying to execute the following code: d = {} exec('import cPickle') in d desc = """ class A(object): pass """ exec(desc) in d exec('a = A()') in d exec('cPickle.dump(a, open("tmp.txt","wb"))')in d for some reason it fails with the following traceback: Traceback (most recent call la

Re: Is 'x' an instance of a new-style class?

2008-09-16 Thread Asun Friere
On Sep 16, 8:05 pm, Hrvoje Niksic <[EMAIL PROTECTED]> wrote: > "Gabriel Genellina" <[EMAIL PROTECTED]> writes: > > In Python you would write isinstance(x, object). > > It will return True for all Python objects (except perhaps those that > fiddle with metaclasses), not only for instances of new-sty

Re: difference between `x in list` and `list.index(x)` for instances of a new-style class

2007-12-30 Thread Gabriel Genellina
On 30 dic, 06:24, Riccardo Murri <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] writes: > > >>   (Pydb) p graph == self.base[27]   > >>   True > >>   (Pydb) p graph in self.base > >>   True > >>   (Pydb) self.base.index(graph) > >>   *** ValueError: list.index(x): x not in list > > Looking at the

Re: difference between `x in list` and `list.index(x)` for instances of a new-style class

2007-12-30 Thread Riccardo Murri
> >>   (Pydb) self.base.index(graph) >>   *** ValueError: list.index(x): x not in list >> >> All graphs are instances of a `Graph` new-style class that implements >> comparison operators `__eq__` and `__ne__`, but no other rich-compare >> stuff. >> >> I&#

Re: difference between `x in list` and `list.index(x)` for instances of a new-style class

2007-12-29 Thread bpgbaires
gt;   True > >   (Pydb) p graph in self.base >   True > > However, I cannot directly get the index of the canonical graph (the > number "27" above was found by manual inspection):: > >   (Pydb) self.base.index(graph) >   *** ValueError: list.index(x): x not in list &g

difference between `x in list` and `list.index(x)` for instances of a new-style class

2007-12-29 Thread Riccardo Murri
ue (Pydb) p graph in self.base True However, I cannot directly get the index of the canonical graph (the number "27" above was found by manual inspection):: (Pydb) self.base.index(graph) *** ValueError: list.index(x): x not in list All graphs are instances of a `Graph

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

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.

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 >

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

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])

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

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

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

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 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 Nigel Rantor
_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 fr

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

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:

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 metho

Re: new style class

2007-11-02 Thread Tim Chase
_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 fr

Re: new style class

2007-11-02 Thread Wildemar Wildenburger
_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

Re: new style class

2007-11-02 Thread gert
> > def escape(v): > > > return v > > > > if __name__ == '__main__': > > > gert = Test() > > > print gert.m1('1') > > > print Test.m2('2') > > > > Why doesn't this new style c

Re: new style class

2007-11-02 Thread gert
: > > 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: > 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') &g

new style class

2007-11-02 Thread gert
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 ? -- http

Re: Subclassing zipfile (new style class)

2007-09-06 Thread Matimus
> import zipfile > class walkZip(zipfile): > pass > > if __name__ == "__main__": > print "Hello World" `zipfile' is the name of the module, not a class. What you probably want is this: [code] import zipfile class WalkZip(zipfile.ZipFile): pass if __name__ == "__main__": print

Re: Subclassing zipfile (new style class)

2007-09-06 Thread Farshid Lashkari
Larry Bates wrote: > import zipfile > class walkZip(zipfile): > pass > > > if __name__ == "__main__": > print "Hello World" > > Traceback (most recent call last): > File "", line 192, in run_nodebug > File "", line 2, in > TypeError: Error when calling the metaclass bases > modu

Re: Subclassing zipfile (new style class)

2007-09-06 Thread Tom Brown
On Thursday 06 September 2007 16:15, Larry Bates wrote: > I'm trying to learn about subclassing new style classes and the first > project I went to do needs to subclass zipfile to add some methods. > > > Why does this: > > import zipfile > class walkZip(zipfile): > pass > > > if __name__ == "_

Subclassing zipfile (new style class)

2007-09-06 Thread Larry Bates
I'm trying to learn about subclassing new style classes and the first project I went to do needs to subclass zipfile to add some methods. Why does this: import zipfile class walkZip(zipfile): pass if __name__ == "__main__": print "Hello World" Traceback (most recent call last):