Hello everyone,

I have been through the Starting Python thread, and I have archived lots of stuff for further learning !

But there is one little thing for which there is no specific explanation, and looking at Google doesn't help me much.

Why do the classes of many scripts are not written like that:

class NameAClass:
def ...

But instead like this:

class NameAClass(object):
def ...

Here is a post containing one script like that

What does it brings to the code ? What does is the reference behind the object "object" ?
What is the use for that and what kind of problems does it solve ?

Thanks !

This is so because of the history of the python language. In the early versions of python, classes were defined using class A: . Then the implementation of python objects changed, mainly so that users could define subclasses of the builtin types like int, str, dict, list, etc.The 'new style' classes appeared and were defined using class A(object) . The first kind of definition was kept so that old python code could still run. You should always use new style classes in your code (some properties of the old style objects differ from the others)

Like when you want to create class that will create simple dialog and then call it from GUI you have created:

import wx
    class Dialogi(wx.Dialog):
        ...........

Just wanted to add that in python 3.0 every class wil be an newstyle class so you better use those to make sure you can easy porte your code to that version of the language

Thanks all ! That's the kind of little thing, that you can't keep you from thinking about it when your program doesn't work and don't know why ...

Just wanted to add that in python 3.0 every class wil be an newstyle class so you better use those to make sure you can easy porte your code to that version of the language

And that's information that will be useful very quickly, as python 3.0 is coming out !

Because most of the 'traditional' tutorials doesn't write the code like that...

This question has already been answered. Start a new discussion instead.