Re: is python Object oriented??
M Kumar wrote: Object oriented languages doesn't allow execution of the code without class objects, what is actually happening when we execute some piece of code, is it bound to any class? Those who have time and consideration can help me There are many kinds of definitions for "object oriented" languages. I have learned some things in the University, and one of them was making distinction between "pure object oriented" languages, and "mixed" languages. Pure object oriented languages does not have programming tools that are non-objects. A good example was SmallTalk, if I remember correctly. Python is not a pure object oriented language, because it has other programming tools, for example functions. However, your question seems to be pedantry. As others would say, "you can do programming in FORTRAN in any language". In other words, it is possible to use Python in a non object-oriented way, but the "good" way of using it is defining classes and making objects... So Python *is* object oriented, if you use it the right way. There might be a definition of "object oriented language" that does not apply to Python, and theoretically, you could say that according to that definition, Python is not object oriented. But practically, it is! Best, Laszlo -- http://mail.python.org/mailman/listinfo/python-list
Re: is python Object oriented??
On Fri, Jan 30, 2009 at 5:15 PM, Chris Rebert wrote: > On Thu, Jan 29, 2009 at 9:56 PM, Hung Vo wrote: > > > I'm new to Python and also wondering about OOP in Python. > > > > I want to justify the above question (is Python Object-Oriented?). > > Does Python follow the concepts/practices of Encapsulation, > > Polymorphism and Interface, which are quite familiar to Java > > programmers? > > If you're looking for a benchmark for object-orientedness, Smalltalk, > not Java, is the canonical language to compare against. I was introduced to OOP via C++/Java, so its quite nature to compare and contrast with the languages you know even they seem not to be original. I definitely will learn about Smalltalk. > > Anyway, to your three-pronged question: > - Yes, Python supports polymorphism. I find it hard to think of an > example of an OO language that doesn't. > > - Python does not support interfaces in the Java sense (although there > are a few third-party libraries that add such support); neither does > Smalltalk. Instead, both Smalltalk and Python use duck-typing to > similar effect. See http://en.wikipedia.org/wiki/Duck_typing Its seem to me that duck typing is a special case of static vs dynamic type debate and clearly Python is a dynamic type philoshopy's follower. > > - Python supports encapsulation. Prefixing an attribute/method with an > underscore indicates that other programmers should treat it as > 'private'. However, unlike B&D languages, Python itself does nothing > to enforce this privacy, leaving it instead to the good judgement of > the programmer, under the philosophy that "We're all consenting adults > here". This allows people to meddle with internals, at their own risk, > if it ends up being absolutely necessary. The enforcement point is > largely academic anyway, as most languages' reflection APIs let you > poke at ostensibly "private" things. I like the flexibility of not being enforced to the encapsulation rules, however, you're right, we do at our own risk and have to tradeoff the flexibility with the secure a static type system like Java provides. P.S. You appear to have posted the same message 3 times(!), which is a > bit annoying for readers. sorry for this annoyance. I dont know why a new post was made whenever i cliked on the topic link. Probably, there's something wrong with google group. on investigating... > > -- > Follow the path of the Iguana... > http://rebertia.com > -- http://mail.python.org/mailman/listinfo/python-list
Re: is python Object oriented??
Michael Torrie schrieb: >> It all depends on implementation, I think even we can make "C" object >> oriented with proper implementation. > > Indeed, any code based on gobject libraries can be object-oriented in > design and function. The Python C API is a good example for well designed and object oriented C code. Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: is python Object oriented??
Veerendra Ganiger wrote: > Python is not purely object oriented programming, because we can write > functions without any class. > You are right, predefined class attributes are available when we write or > execute a piece of python code without defining class, that means it's just > using objects for it's purpose. It does not mean its purely object oriented. To be clear, python does not force you to lay out your code according to some strict object-oriented paradigm. But Python itself is still purely object-oriented, as is your script when parsed. This function without a class that you mentioned, is in fact an object with attributes. You can pass a function around just like any other object. Even calling a function is invoked like so: myfunc.__call__(params) So necessitating that code be inside a class has nothing to do with object-oriented programming. Let's not forget that classes are themselves objects (metaobjects in smalltalk parlance if I recall correctly). Now python does not have any way besides lambda expressions of creating unbound function objects, but in practice this doesn't matter as I can rebind names freely. I can still do: a=myfunc myfunc=some other expression or object > It all depends on implementation, I think even we can make "C" object > oriented with proper implementation. Indeed, any code based on gobject libraries can be object-oriented in design and function. -- http://mail.python.org/mailman/listinfo/python-list
Re: is python Object oriented??
Hung Vo wrote: > I'm new to Python and also wondering about OOP in Python. > > I want to justify the above question (is Python Object-Oriented?). > Does Python follow the concepts/practices of Encapsulation, > Polymorphism and Interface, which are quite familiar to Java > programmers? I'd say that actually Python uses encapsulation extensively throughout the language. Every object in Python has attributes. Thus every object encapsulates (contains) attributes (which are themselves objects). I think the term "encapsulation" is often misinterpreted by some (Java programmers in particular) to mean some kind of enforced black-box methodology. In effect they feel that getters and setters is the definition of encapsulation. This is really not true, especially if you go back to the original OO languages, such as Smalltalk. So if you are asking, does python enforce some kind of bizarre black box access semantics (requiring getters and setters), the answer is an emphatic "no!" Interfaces have nothing to do with OO programming as a matter of a fundamental principle. Interfaces exist in Java to compensate for flaws/features in the language. Particularly the lack of multiple inheritance which is a blessing/curse in Java. Python just doesn't need interfaces. Protocols for communication with an object do not need to be formally enforced. For example the popular database API that most python database libraries use just makes sure it implements certain methods. Thus it doesn't matter if I'm using mysql, postgresql, or oracle. I still call the object's "connect" method. Such a breath of fresh air compared to Java, in my opinion. Such informality can be a bit of a hindrance to some I guess. After this entire thread, it's funny that people are still chiming in saying, "so is it really OOP" after having it explained in so many ways. -- http://mail.python.org/mailman/listinfo/python-list
Re: is python Object oriented??
On 2009-01-30, Chris Rebert wrote: > On Thu, Jan 29, 2009 at 9:56 PM, Hung Vo wrote: > >> I'm new to Python and also wondering about OOP in Python. >> >> I want to justify the above question (is Python Object-Oriented?). >> Does Python follow the concepts/practices of Encapsulation, >> Polymorphism and Interface, which are quite familiar to Java >> programmers? > > If you're looking for a benchmark for object-orientedness, Smalltalk, > not Java, is the canonical language to compare against. As long as one doesn't then conflate message-passingness with object-orientedness. [Not that I'm implying Chris does, but given the OP's comments one worries that he might.] -- Grant Edwards grante Yow! I know things about at TROY DONAHUE that can't visi.comeven be PRINTED!! -- http://mail.python.org/mailman/listinfo/python-list
Re: is python Object oriented??
Python is not purely object oriented programming, because we can write functions without any class. You are right, predefined class attributes are available when we write or execute a piece of python code without defining class, that means it's just using objects for it's purpose. It does not mean its purely object oriented. It all depends on implementation, I think even we can make "C" object oriented with proper implementation. On Thu, Jan 29, 2009 at 7:28 PM, M Kumar wrote: > but still I am not clear of the execution of the code, when we write or > execute a piece of python code without defining class, predefined class > attributes are available (not all but __name__ and __doc__ are available). > does it mean anything to this topic. Is it necessory to have __module__, > __dict__ and __bases__ for a class object in python? > > > On Thu, Jan 29, 2009 at 5:21 PM, Tino Wildenhain wrote: > >> Muriel de Souza Godoi wrote: >> >>> Python offers support for object orientation, but it's not an >>> object-oriented language. >>> I mean, you can code a entire program in Python with no classes. So you >>> use it if you want to. >>> >>> It's not like java, which you must use a class to code a Hello World, but >>> Java isn't fully object-oriented, because it doesn't provide support for >>> multiple inheritance and it has primitive types (multiple interfaces and >>> wrappers to primitive types doesn't count :) ) >>> >>> AFAIK, the unique fully object oriented languagem is Smaltalk. (maybe >>> Simula?), where everything is a class, even the primitive types. >>> >> >> well actually except keywords, everything is an object in python too, >> including of course primitive types (if you say so - practically python >> does not have them). >> >> Regards >> Tino >> > > > > -- > Regards, > > Maneesh KB > > Comat Technologies > > Bangalore > > Mob: 9740-192309 > > > > We work with the underprivileged and in rural India. If you are interested > to be a part of it, please mail or call me. I will be happy to share and > inform - http://www.comat.com > -- regards, Veerendra -- http://mail.python.org/mailman/listinfo/python-list
Re: is python Object oriented??
2009/1/30 Hung Vo : > I want to justify the above question (is Python Object-Oriented?). > Does Python follow the concepts/practices of Encapsulation, > Polymorphism and Interface, which are quite familiar to Java > programmers? It's not the role of the language to follow those concepts, it's the role of the programmer to follow those concepts if the programmer believes OO to be an appropriate paradigm for the task in hand. If the programmer decides that following those concepts is appropriate, Python will offer more than enough support. If the programmer decides that OO is not an appropriate paradigm but wants to follow procedural or functional concepts instead, Python will support that, too. Object orientation is not really a language property at all; it's a design approach. I've written object oriented programs in C, hand-coding the despatch tables, before anybody gave the name "object oriented" to that approach. When people talk about an object oriented language they either mean a language that allows a close mapping between an object oriented design and the actual code (Python does), or they mean a language that *requires* the code to conform to an object oriented design (Python doesn't). So the answer to "Is Python Object-Oriented" is either "yes" or "no", depending on what you're /really/ asking. -- Tim Rowe -- http://mail.python.org/mailman/listinfo/python-list
Re: is python Object oriented??
On Thu, Jan 29, 2009 at 10:25 PM, alex23 wrote: > On Jan 30, 4:15 pm, Chris Rebert wrote: >> - Python does not support interfaces in the Java sense (although there >> are a few third-party libraries that add such support); neither does >> Smalltalk. Instead, both Smalltalk and Python use duck-typing to >> similar effect. Seehttp://en.wikipedia.org/wiki/Duck_typing > > I haven't yet had reason to use them, but do Abstract Base Classes > (introduced in 2.6/3.0) go some way to provide more defined interface > support for Python? My assumption was that was what they'd generally > be used for... Ah, excellent point. I neglected to take ABCs into account. Smalltalk did have those as well. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: is python Object oriented??
On Jan 30, 4:15 pm, Chris Rebert wrote: > - Python does not support interfaces in the Java sense (although there > are a few third-party libraries that add such support); neither does > Smalltalk. Instead, both Smalltalk and Python use duck-typing to > similar effect. Seehttp://en.wikipedia.org/wiki/Duck_typing I haven't yet had reason to use them, but do Abstract Base Classes (introduced in 2.6/3.0) go some way to provide more defined interface support for Python? My assumption was that was what they'd generally be used for... -- http://mail.python.org/mailman/listinfo/python-list
Re: is python Object oriented??
On Thu, Jan 29, 2009 at 9:56 PM, Hung Vo wrote: > I'm new to Python and also wondering about OOP in Python. > > I want to justify the above question (is Python Object-Oriented?). > Does Python follow the concepts/practices of Encapsulation, > Polymorphism and Interface, which are quite familiar to Java > programmers? If you're looking for a benchmark for object-orientedness, Smalltalk, not Java, is the canonical language to compare against. Anyway, to your three-pronged question: - Yes, Python supports polymorphism. I find it hard to think of an example of an OO language that doesn't. - Python does not support interfaces in the Java sense (although there are a few third-party libraries that add such support); neither does Smalltalk. Instead, both Smalltalk and Python use duck-typing to similar effect. See http://en.wikipedia.org/wiki/Duck_typing - Python supports encapsulation. Prefixing an attribute/method with an underscore indicates that other programmers should treat it as 'private'. However, unlike B&D languages, Python itself does nothing to enforce this privacy, leaving it instead to the good judgement of the programmer, under the philosophy that "We're all consenting adults here". This allows people to meddle with internals, at their own risk, if it ends up being absolutely necessary. The enforcement point is largely academic anyway, as most languages' reflection APIs let you poke at ostensibly "private" things. Cheers, Chris P.S. You appear to have posted the same message 3 times(!), which is a bit annoying for readers. -- Follow the path of the Iguana... http://rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: is python Object oriented??
> I'm new to Python and also wondering about OOP in Python. > > I want to justify the above question (is Python Object-Oriented?). > Does Python follow the concepts/practices of Encapsulation, > Polymorphism and Interface, which are quite familiar to Java > programmers? Python does not enforce Encapsulation; but convention is extremely successful here although there's some really loud people in this newsgroup who state otherwise. Python programmers tend to be very well-behaved in this regard and they do not poke into private API's -- unless /they have to/. That's important: /have/ to. If they were not allowed, they'd be unable to use that code. Internally in corporate software this is a complete non-issue: and in any major project it should be a non-issue too. If you follow basic convention (private is preceded by _) then it is extremely clear if you're obeying encapsulation and if someone in your project breaks it without a good reason-- refuse the addition. Python is *extremely* polymorphic. Python does not have any built-in "interface" capability, per se, but there are add-on libraries that can be used to provide interface functionality if you are doing a framework or large program that needs it. Then again "Interface" is a bit questionable as an "OOP Concept"; its used in some implementations of an OOP language, and not used in anothers-- and what it means in one can differ from what it means in another. There's all kinds of other "concepts" of OOP that various people describe, and generally you can do them all in Python. --S -- http://mail.python.org/mailman/listinfo/python-list
Re: is python Object oriented??
On Jan 30, 4:00 pm, Hung Vo wrote: > Does Python follow the concepts/practices of Encapsulation, > Polymorphism and Interface, which are quite familiar to Java > programmers? Well, it has the same _concepts_, but definitely not the same practices/implementations. As they say, Python is not Java :) -- http://mail.python.org/mailman/listinfo/python-list
Re: is python Object oriented??
On Jan 30, 4:19 am, Michael Torrie wrote: > M Kumar wrote: > > but still I am not clear of the execution of the code, when we write or > > execute a piece of python code without defining class, predefined class > > attributes are available (not all but __name__ and __doc__ are available). > > does it mean anything to this topic. Is it necessory to have __module__, > > __dict__ and __bases__ for a class object in python? > > I think you're confused as to what object-oriented means. OO defines > the internals of a language more than a particular programming paradigm. > Obviously python lets you program in a variety of paradigms, including > procedural and event-driven, but it is all very much object-oriented. > So ignore those that say python doesn't force you to use OOP, when in > fact it's unavoidable. It's just that you're not forced to place all > your code in class definitions. You don't need to because your code is > already object-oriented in that you're manipulating objects and their > attributes. > > As others have said, Python is an object-oriented language through and > through, closer to Smalltalk in many ways, the grand-daddy of all OO > languages. > > It appears that you are only really familiar with Java, and that leads > to a number of interesting misconceptions about OO. Java's bizarre OO > requires everything to be in a class, which leads many people to believe > this is what OO should be. In fact Java is a bit odd when it comes to > OO, as there are many things in Java that aren't in fact objects. For > example, primitives are intrinsic types and are not objects. > Furthermore class definitions are not objects either, at least from the > programmer's pov. You can't manipulate them by standard means as you > can in Smalltalk and Python. In Smalltalk and Python a "class" is an > object just as much as an instance of a class is an object which has a > constructor factory method that returns instance objects. Java also has > very strange ways of doing singleton patterns. You have to wrap > singletons in class and define them as "static." I think this was > inherited from C++. > > The most basic object in a python script is the module object which > represents the namespace of the current script. In effect a module > object is a singleton. It has a few attributes, and you can use it to > look up any of the objects it contains, such as functions, objects > (so-called variables), classes, etc. Everything in python is an object. > The statement: > > a = 4 > > defines an integer object "4" and binds a name to it, 'a.' You can even > check to see what methods the object supports by doing: > > >>> dir(4) > > ['__abs__', '__add__', '__and__', '__class__', '__cmp__', '__coerce__', > '__delattr__', '__div__', '__divmod__', '__doc__', '__float__', > '__floordiv__', '__getattribute__', '__getnewargs__', '__hash__', > '__hex__', '__index__', '__init__', '__int__', '__invert__', '__long__', > '__lshift__', '__mod__', '__mul__', '__neg__', '__new__', '__nonzero__', > '__oct__', '__or__', '__pos__', '__pow__', '__radd__', '__rand__', > '__rdiv__', '__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__', > '__rfloordiv__', '__rlshift__', '__rmod__', '__rmul__', '__ror__', > '__rpow__', '__rrshift__', '__rshift__', '__rsub__', '__rtruediv__', > '__rxor__', '__setattr__', '__str__', '__sub__', '__truediv__', '__xor__'] > > dir(a) would return the same thing. As you can see, all the operators > that can be performed with a number object are defined. This little > exercise alone should show you how much more object-oriented Python is > than Java. > > Python's OO capabilities are really exposed when you start extending > built-in types, or doing meta programming where you dynamically alter > classes (and instance objects) on the fly. I'm new to Python and also wondering about OOP in Python. I want to justify the above question (is Python Object-Oriented?). Does Python follow the concepts/practices of Encapsulation, Polymorphism and Interface, which are quite familiar to Java programmers? Cheers, Hung -- http://mail.python.org/mailman/listinfo/python-list
Re: is python Object oriented??
On Jan 30, 4:19 am, Michael Torrie wrote: > M Kumar wrote: > > but still I am not clear of the execution of the code, when we write or > > execute a piece of python code without defining class, predefined class > > attributes are available (not all but __name__ and __doc__ are available). > > does it mean anything to this topic. Is it necessory to have __module__, > > __dict__ and __bases__ for a class object in python? > > I think you're confused as to what object-oriented means. OO defines > the internals of a language more than a particular programming paradigm. > Obviously python lets you program in a variety of paradigms, including > procedural and event-driven, but it is all very much object-oriented. > So ignore those that say python doesn't force you to use OOP, when in > fact it's unavoidable. It's just that you're not forced to place all > your code in class definitions. You don't need to because your code is > already object-oriented in that you're manipulating objects and their > attributes. > > As others have said, Python is an object-oriented language through and > through, closer to Smalltalk in many ways, the grand-daddy of all OO > languages. > > It appears that you are only really familiar with Java, and that leads > to a number of interesting misconceptions about OO. Java's bizarre OO > requires everything to be in a class, which leads many people to believe > this is what OO should be. In fact Java is a bit odd when it comes to > OO, as there are many things in Java that aren't in fact objects. For > example, primitives are intrinsic types and are not objects. > Furthermore class definitions are not objects either, at least from the > programmer's pov. You can't manipulate them by standard means as you > can in Smalltalk and Python. In Smalltalk and Python a "class" is an > object just as much as an instance of a class is an object which has a > constructor factory method that returns instance objects. Java also has > very strange ways of doing singleton patterns. You have to wrap > singletons in class and define them as "static." I think this was > inherited from C++. > > The most basic object in a python script is the module object which > represents the namespace of the current script. In effect a module > object is a singleton. It has a few attributes, and you can use it to > look up any of the objects it contains, such as functions, objects > (so-called variables), classes, etc. Everything in python is an object. > The statement: > > a = 4 > > defines an integer object "4" and binds a name to it, 'a.' You can even > check to see what methods the object supports by doing: > > >>> dir(4) > > ['__abs__', '__add__', '__and__', '__class__', '__cmp__', '__coerce__', > '__delattr__', '__div__', '__divmod__', '__doc__', '__float__', > '__floordiv__', '__getattribute__', '__getnewargs__', '__hash__', > '__hex__', '__index__', '__init__', '__int__', '__invert__', '__long__', > '__lshift__', '__mod__', '__mul__', '__neg__', '__new__', '__nonzero__', > '__oct__', '__or__', '__pos__', '__pow__', '__radd__', '__rand__', > '__rdiv__', '__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__', > '__rfloordiv__', '__rlshift__', '__rmod__', '__rmul__', '__ror__', > '__rpow__', '__rrshift__', '__rshift__', '__rsub__', '__rtruediv__', > '__rxor__', '__setattr__', '__str__', '__sub__', '__truediv__', '__xor__'] > > dir(a) would return the same thing. As you can see, all the operators > that can be performed with a number object are defined. This little > exercise alone should show you how much more object-oriented Python is > than Java. > > Python's OO capabilities are really exposed when you start extending > built-in types, or doing meta programming where you dynamically alter > classes (and instance objects) on the fly. I'm new to Python and also wondering about OOP in Python. I want to justify the above question (is Python Object-Oriented?). Does Python follow the concepts/practices of Encapsulation, Polymorphism and Interface, which are quite familiar to Java programmers? Cheers, Hung -- http://mail.python.org/mailman/listinfo/python-list
Re: is python Object oriented??
On Jan 30, 4:19 am, Michael Torrie wrote: > M Kumar wrote: > > but still I am not clear of the execution of the code, when we write or > > execute a piece of python code without defining class, predefined class > > attributes are available (not all but __name__ and __doc__ are available). > > does it mean anything to this topic. Is it necessory to have __module__, > > __dict__ and __bases__ for a class object in python? > > I think you're confused as to what object-oriented means. OO defines > the internals of a language more than a particular programming paradigm. > Obviously python lets you program in a variety of paradigms, including > procedural and event-driven, but it is all very much object-oriented. > So ignore those that say python doesn't force you to use OOP, when in > fact it's unavoidable. It's just that you're not forced to place all > your code in class definitions. You don't need to because your code is > already object-oriented in that you're manipulating objects and their > attributes. > > As others have said, Python is an object-oriented language through and > through, closer to Smalltalk in many ways, the grand-daddy of all OO > languages. > > It appears that you are only really familiar with Java, and that leads > to a number of interesting misconceptions about OO. Java's bizarre OO > requires everything to be in a class, which leads many people to believe > this is what OO should be. In fact Java is a bit odd when it comes to > OO, as there are many things in Java that aren't in fact objects. For > example, primitives are intrinsic types and are not objects. > Furthermore class definitions are not objects either, at least from the > programmer's pov. You can't manipulate them by standard means as you > can in Smalltalk and Python. In Smalltalk and Python a "class" is an > object just as much as an instance of a class is an object which has a > constructor factory method that returns instance objects. Java also has > very strange ways of doing singleton patterns. You have to wrap > singletons in class and define them as "static." I think this was > inherited from C++. > > The most basic object in a python script is the module object which > represents the namespace of the current script. In effect a module > object is a singleton. It has a few attributes, and you can use it to > look up any of the objects it contains, such as functions, objects > (so-called variables), classes, etc. Everything in python is an object. > The statement: > > a = 4 > > defines an integer object "4" and binds a name to it, 'a.' You can even > check to see what methods the object supports by doing: > > >>> dir(4) > > ['__abs__', '__add__', '__and__', '__class__', '__cmp__', '__coerce__', > '__delattr__', '__div__', '__divmod__', '__doc__', '__float__', > '__floordiv__', '__getattribute__', '__getnewargs__', '__hash__', > '__hex__', '__index__', '__init__', '__int__', '__invert__', '__long__', > '__lshift__', '__mod__', '__mul__', '__neg__', '__new__', '__nonzero__', > '__oct__', '__or__', '__pos__', '__pow__', '__radd__', '__rand__', > '__rdiv__', '__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__', > '__rfloordiv__', '__rlshift__', '__rmod__', '__rmul__', '__ror__', > '__rpow__', '__rrshift__', '__rshift__', '__rsub__', '__rtruediv__', > '__rxor__', '__setattr__', '__str__', '__sub__', '__truediv__', '__xor__'] > > dir(a) would return the same thing. As you can see, all the operators > that can be performed with a number object are defined. This little > exercise alone should show you how much more object-oriented Python is > than Java. > > Python's OO capabilities are really exposed when you start extending > built-in types, or doing meta programming where you dynamically alter > classes (and instance objects) on the fly. I'm new to Python and also wondering about OOP in Python. I want to justify the above question (is Python Object-Oriented?). Does Python follow the concepts/practices of Encapsulation, Polymorphism and Interface, which are quite familiar to Java programmers? Cheers, Hung -- http://mail.python.org/mailman/listinfo/python-list
Re: is python Object oriented??
On Thu, Jan 29, 2009 at 7:31 PM, Steven D'Aprano wrote: > On Thu, 29 Jan 2009 02:25:57 -0800, Chris Rebert wrote: > >> In addition to methods, Python has functions, which are not associated >> with a class > > Yes they are. > (lambda: None).__class__ > > > The function type itself has a class: > (lambda: None).__class__.__class__ > I think we're now quibbling over the interpretation of "associated". My intention was to contrast how methods and classmethods are stored and accessed through the class they are defined in (or grafted onto), whereas plain functions are not (instance/class variables that happen to hold functions notwithstanding). Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: is python Object oriented??
On Thu, 29 Jan 2009 02:25:57 -0800, Chris Rebert wrote: > In addition to methods, Python has functions, which are not associated > with a class Yes they are. >>> (lambda: None).__class__ The function type itself has a class: >>> (lambda: None).__class__.__class__ -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: is python Object oriented??
MC writes: > Hi! > > Il se trouve que Chris Rebert a formulé : > > Python has functions, which are not associated with a class > > functions are methods of builtin... No, because ‘builtin’ is not a class. -- \ “The shortest distance between two points is under | `\ construction.” —Noelie Alito | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: is python Object oriented??
On 29 Jan., 11:21, Gary Herron wrote: > Python *is* object-oriented, but it is not (as your definition suggests) > object-fascist. I'd put it more mildly. Python is object oriented. The orientation is there but the fanatism is gone. Kay -- http://mail.python.org/mailman/listinfo/python-list
Re: is python Object oriented??
M Kumar wrote: Object oriented languages doesn't allow execution of the code without class objects, what is actually happening when we execute some piece of code, is it bound to any class? Those who have time and consideration can help me My take.. Python is a language. Programs written in Python create and manipulate information objects. (But programs are not objects themselves.) So, Python is a language for describing object-based information processing. Every Python object is an instance of some class. Every class, being an object itself, is an instance of some metaclass. (The 'type' metaclass is an instance of itself.) Every class (in Py3) is also a subclasses of the base class 'object'. I think 'object-orient language' is a somewhat misleading abbreviation since 'object-orientedness' is a potential property of the an abstract computation system a language works, with rather than a property of a language itself. Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: is python Object oriented??
M Kumar wrote: > but still I am not clear of the execution of the code, when we write or > execute a piece of python code without defining class, predefined class > attributes are available (not all but __name__ and __doc__ are available). > does it mean anything to this topic. Is it necessory to have __module__, > __dict__ and __bases__ for a class object in python? I think you're confused as to what object-oriented means. OO defines the internals of a language more than a particular programming paradigm. Obviously python lets you program in a variety of paradigms, including procedural and event-driven, but it is all very much object-oriented. So ignore those that say python doesn't force you to use OOP, when in fact it's unavoidable. It's just that you're not forced to place all your code in class definitions. You don't need to because your code is already object-oriented in that you're manipulating objects and their attributes. As others have said, Python is an object-oriented language through and through, closer to Smalltalk in many ways, the grand-daddy of all OO languages. It appears that you are only really familiar with Java, and that leads to a number of interesting misconceptions about OO. Java's bizarre OO requires everything to be in a class, which leads many people to believe this is what OO should be. In fact Java is a bit odd when it comes to OO, as there are many things in Java that aren't in fact objects. For example, primitives are intrinsic types and are not objects. Furthermore class definitions are not objects either, at least from the programmer's pov. You can't manipulate them by standard means as you can in Smalltalk and Python. In Smalltalk and Python a "class" is an object just as much as an instance of a class is an object which has a constructor factory method that returns instance objects. Java also has very strange ways of doing singleton patterns. You have to wrap singletons in class and define them as "static." I think this was inherited from C++. The most basic object in a python script is the module object which represents the namespace of the current script. In effect a module object is a singleton. It has a few attributes, and you can use it to look up any of the objects it contains, such as functions, objects (so-called variables), classes, etc. Everything in python is an object. The statement: a = 4 defines an integer object "4" and binds a name to it, 'a.' You can even check to see what methods the object supports by doing: >>> dir(4) ['__abs__', '__add__', '__and__', '__class__', '__cmp__', '__coerce__', '__delattr__', '__div__', '__divmod__', '__doc__', '__float__', '__floordiv__', '__getattribute__', '__getnewargs__', '__hash__', '__hex__', '__index__', '__init__', '__int__', '__invert__', '__long__', '__lshift__', '__mod__', '__mul__', '__neg__', '__new__', '__nonzero__', '__oct__', '__or__', '__pos__', '__pow__', '__radd__', '__rand__', '__rdiv__', '__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__', '__rfloordiv__', '__rlshift__', '__rmod__', '__rmul__', '__ror__', '__rpow__', '__rrshift__', '__rshift__', '__rsub__', '__rtruediv__', '__rxor__', '__setattr__', '__str__', '__sub__', '__truediv__', '__xor__'] dir(a) would return the same thing. As you can see, all the operators that can be performed with a number object are defined. This little exercise alone should show you how much more object-oriented Python is than Java. Python's OO capabilities are really exposed when you start extending built-in types, or doing meta programming where you dynamically alter classes (and instance objects) on the fly. -- http://mail.python.org/mailman/listinfo/python-list
Re: is python Object oriented??
MC a écrit : Hi! Il se trouve que Chris Rebert a formulé : Python has functions, which are not associated with a class functions are methods of builtin... Please check your facts. Python functions are not "methods" of anything (and not even necessarily attributes of a module - think about nested functions...). -- http://mail.python.org/mailman/listinfo/python-list
Re: is python Object oriented??
On Thu, Jan 29, 2009 at 5:58 AM, M Kumar wrote: > but still I am not clear of the execution of the code, when we write or > execute a piece of python code without defining class, predefined class > attributes are available (not all but __name__ and __doc__ are available). > does it mean anything to this topic. Is it necessory to have __module__, > __dict__ and __bases__ for a class object in python? I think there's some confusion on what you're asking; Python enables you to write object oriented software if you choose to. It also enables you to write procedural software if you choose to. There's other paradigms it supports too, to varying degrees. Its a tool that allows you to use it as you wish, instead of saying that a paradigm is the Right Way to do it. When you are writing object oriented software, you generally define classes. Class can inherit from other classes: if they do then the __bases__ attribute is set on the class itself to indicate which classes it inherits from. All Python code is within a module -- as a module is simply a file. For classes, functions and methods, the __module__ attribute simply points to which module it was defined in. The __dict__ of a class represents the dictionary of attributes that are "in" or "on" that class (approximately). But those are all implementation details. You don't have to set any of them or worry about any of them generally. You just: class MyClass: def __init__(self, bar): self.value = bar def foo(self): return self.value You don't have to set any class attributes to work with classes. -- http://mail.python.org/mailman/listinfo/python-list
Re: is python Object oriented??
On Jan 29, 7:21 am, Gary Herron wrote: > Python *is* object-oriented, but it is not (as your definition suggests) > object-fascist. I'm a python-nazi. No python for you! -- http://mail.python.org/mailman/listinfo/python-list
Re: is python Object oriented??
but still I am not clear of the execution of the code, when we write or execute a piece of python code without defining class, predefined class attributes are available (not all but __name__ and __doc__ are available). does it mean anything to this topic. Is it necessory to have __module__, __dict__ and __bases__ for a class object in python? On Thu, Jan 29, 2009 at 5:21 PM, Tino Wildenhain wrote: > Muriel de Souza Godoi wrote: > >> Python offers support for object orientation, but it's not an >> object-oriented language. >> I mean, you can code a entire program in Python with no classes. So you >> use it if you want to. >> >> It's not like java, which you must use a class to code a Hello World, but >> Java isn't fully object-oriented, because it doesn't provide support for >> multiple inheritance and it has primitive types (multiple interfaces and >> wrappers to primitive types doesn't count :) ) >> >> AFAIK, the unique fully object oriented languagem is Smaltalk. (maybe >> Simula?), where everything is a class, even the primitive types. >> > > well actually except keywords, everything is an object in python too, > including of course primitive types (if you say so - practically python > does not have them). > > Regards > Tino > -- Regards, Maneesh KB Comat Technologies Bangalore Mob: 9740-192309 We work with the underprivileged and in rural India. If you are interested to be a part of it, please mail or call me. I will be happy to share and inform - http://www.comat.com -- http://mail.python.org/mailman/listinfo/python-list
Re: is python Object oriented??
M Kumar wrote: > Object oriented languages doesn't allow execution of the code without > class objects, what is actually happening when we execute some piece of > code, is it bound to any class? > Those who have time and consideration can help me a) This is a purely theoretical consideration. You asked whether "python is a pure object oriented language", but this will inevitably lead to obscure discussions about what you mean rather than what Python is. b) You seem to believe that a "pure" object oriented language must do everything using classes. Since many problems are just as easy (or easier) to solve with a procedural approach, Python takes the view that it should be easy to provide such solutions as well. c) import this The Zen of Python, by Tim Peters [...] practicality beats purity [...] We aren't big on purity in the Python world ;-) regards Steve -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: is python Object oriented??
Hi! Il se trouve que Chris Rebert a formulé : Python has functions, which are not associated with a class functions are methods of builtin... -- @-salutations Michel Claveau -- http://mail.python.org/mailman/listinfo/python-list
Re: is python Object oriented??
Muriel de Souza Godoi wrote: Python offers support for object orientation, but it's not an object-oriented language. I mean, you can code a entire program in Python with no classes. So you use it if you want to. It's not like java, which you must use a class to code a Hello World, but Java isn't fully object-oriented, because it doesn't provide support for multiple inheritance and it has primitive types (multiple interfaces and wrappers to primitive types doesn't count :) ) AFAIK, the unique fully object oriented languagem is Smaltalk. (maybe Simula?), where everything is a class, even the primitive types. well actually except keywords, everything is an object in python too, including of course primitive types (if you say so - practically python does not have them). Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: is python Object oriented??
Python offers support for object orientation, but it's not an object-oriented language. I mean, you can code a entire program in Python with no classes. So you use it if you want to. It's not like java, which you must use a class to code a Hello World, but Java isn't fully object-oriented, because it doesn't provide support for multiple inheritance and it has primitive types (multiple interfaces and wrappers to primitive types doesn't count :) ) AFAIK, the unique fully object oriented languagem is Smaltalk. (maybe Simula?), where everything is a class, even the primitive types. An excellent reference book for that is: Sebesta, Robert W. (2002): *Concepts of Programming Languages (Fifth Edition).* Addison-Wesley Publishing Cheers, -- Muriel de Souza Godoi State University of Maringá Brazil -- http://mail.python.org/mailman/listinfo/python-list
Re: is python Object oriented??
(answering to the OP) M Kumar wrote: Object oriented languages doesn't allow execution of the code without class objects, Chapter and verse, please ? Nothing in the (very few) "axioms" of OOP mentions "classes". You don't need classes to have an OOPL (ever heard about prototype-based languages ?). OOP is - as the name imply - about *objects*. what is actually happening when we execute some piece of code, Top-level code ? or the body of a def statement ? is it bound to any class? Why should it be ? -- http://mail.python.org/mailman/listinfo/python-list
Re: is python Object oriented??
On Thu, Jan 29, 2009 at 2:01 AM, M Kumar wrote: > Object oriented languages doesn't allow execution of the code without class > objects, what is actually happening when we execute some piece of code, is > it bound to any class? That's not really the standard definition of object-oriented (c.f. Wikipedia), but by your definition (which seems Java/Ruby-centric, IMHO), Python would not be object-oriented. In addition to methods, Python has functions, which are not associated with a class and let you write code in a procedural style, thus failing your criterion. Python also has the top-level module scope, in which the code isn't even part of a method or function at all and thus certainly is not associated with a class, again not satisfying your criterion. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: is python Object oriented??
M Kumar wrote: > Object oriented languages doesn't allow execution of the code without > class objects, what is actually happening when we execute some piece > of code, is it bound to any class? > Those who have time and consideration can help me > Python *is* object-oriented, but it is not (as your definition suggests) object-fascist. We use objects to great effect in Python, when it is natural to do so, but the language does not force it on us. Gary Herron > -- > Regards, > > Maneesh KB > > Comat Technologies > > Bangalore > > Mob: 9740-192309 > > > > We work with the underprivileged and in rural India. If you are > interested to be a part of it, please mail or call me. I will be happy > to share and inform - http://www.comat.com > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
is python Object oriented??
Object oriented languages doesn't allow execution of the code without class objects, what is actually happening when we execute some piece of code, is it bound to any class? Those who have time and consideration can help me -- Regards, Maneesh KB Comat Technologies Bangalore Mob: 9740-192309 We work with the underprivileged and in rural India. If you are interested to be a part of it, please mail or call me. I will be happy to share and inform - http://www.comat.com -- http://mail.python.org/mailman/listinfo/python-list