473,513 Members | 2,677 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

class definition syntax

hi
i have seen some class definitions like

class MyClass(object):
def __init__(self):
....

what does the object keyword inside the braces in MyClass() mean?
Has it got any significance?

thanks in advance
harry
Aug 29 '08 #1
4 929
harryos wrote:
hi
i have seen some class definitions like

class MyClass(object):
def __init__(self):
....

what does the object keyword inside the braces in MyClass() mean?
Has it got any significance?
It indicates a so-called new-style-class. The new style classes have been
available since python2.2:

http://docs.python.org/ref/node33.html

Diez
Aug 29 '08 #2
On Fri, 29 Aug 2008 02:50:57 -0700 (PDT), harryos wrote:
class MyClass(object):
def __init__(self):
....

what does the object keyword inside the braces in MyClass() mean?
Has it got any significance?
It's inheritance. MyClass class inherits from object class.
Check out point 9.5 in the tutorial.

--
Regards,
Wojtek Walczak,
http://tosh.pl/gminick/
Aug 29 '08 #3
harryos wrote:
hi
i have seen some class definitions like

class MyClass(object):
def __init__(self):
....

what does the object keyword inside the braces in MyClass() mean?
Has it got any significance?

thanks in advance
harry
It is a syntax used for 'new type' classes, not so new any more.

If you google that phrase, you get many references.

Here is a tutorial dating back to 2005.
http://www.geocities.com/foetsch/pyt...le_classes.htm
Aug 29 '08 #4
harryos a écrit :
hi
i have seen some class definitions like

class MyClass(object):
def __init__(self):
....

what does the object keyword
It's not a keyword.
inside the braces in MyClass() mean?
Answer is here:

http://docs.python.org/tut/node11.ht...00000000000000
http://docs.python.org/ref/class.html

Has it got any significance?
<ironic>
Nope, why ? It just look better that way...
</ironic>

Harry, this neswgroup is - as you may have noticed by now - very newbie
friendly. But this is not a reason for not reading *at least* the
FineManual's tutorial.
Aug 29 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1281
by: PF | last post by:
Hello, I'm pleased to see activity on this topic as it pains me to write "classmethod" two pages of code after the method definition. However I find the decorators to obfuscate the syntax and lessen the expressivity (ie. they restrain what can be done). All these problems come from the fact that the execution of the...
2
1516
by: Victor Liu | last post by:
hi, why n1 in local::f() is no allowed ? int n0; void function() { int n1; static int n2; class local {
12
3218
by: Bryan Parkoff | last post by:
CMain Class is the base class that is initialized in main function. CA Class is the base class that is initialized in CMain::CMain(). CMain Class is always public while CA Class is always private. I have placed "friend void CA::Run_A(void)" in CMain Class. CMain::Run() function attempts to execute CA::Run_A(), but compiler shows an error...
7
2362
by: Thomas Matthews | last post by:
Hi, I am converting my table and record classes into templates. My issue is the syntax of declaring a friend class within the template. I have searched the C++ FAQ Lite (web), the C++ newsgroups, "Thinking In C++" to no avail. Background ----------
5
1921
by: Xiangliang Meng | last post by:
Hi, all. What are the benefit and the drawback of defining a class embedded inside another class? For example: class List { public:
9
3651
by: Daniel Kay | last post by:
Hello! I have written two template classes which implement the observerpattern in C++. I hope I manage to desribe the problem I have. template<class T> class Observer { /* ... */ }; template<class T> classSubject {
9
2084
by: jerry.upstatenyguy | last post by:
I am really stuck on this. I am trying to write a string array containing a "word" and a "definition" to a class called Entry. Ultimately this will end up in another class called dictionary. No, this is not a homework assignment. In fact it was a question on my class midterm that everyone bombed. Unfortunately we never covered this in...
9
8865
by: Jess | last post by:
Hello, I was told that if I declare a static class constant like this: class A{ static const int x = 10; }; then the above statement is a declaration rather than a definition. As I've *defined* "x"'s value to be 10, isn't above statement a
9
5065
by: gopal | last post by:
Why is ; ~ semi-colon used at the end of class definition ? Thanks JK
7
5756
by: QiongZ | last post by:
Hi, I just recently started studying C++ and basically copied an example in the textbook into VS2008, but it doesn't compile. I tried to modify the code by eliminating all the templates then it compiled no problem. But I can't find the what the problem is with templates? Please help. The main is in test-linked-list.cpp. There are two template...
0
7394
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7123
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5701
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4756
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3248
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3237
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1611
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
811
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
470
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.