Re: is python Object oriented??

2009-02-01 Thread Hung Vo
On Feb 2, 4:10 am, Stephen Hansen  wrote:
> Anyway, it doesn't matter. We're losing the point here. The point is
> that language support for private access, by disallowing user access
> to private data, provides an unambiguous information hiding mechanism
> which encourages encapsulation. Python's approach, however, which is
> only a naming convention rather than a language feature, merely TRUSTS
> the programmer not to break encapsulation. And sure, if we're all good
> programmers, everything will go well and we'll end up with an
> organized application. But the danger is still there: at any given
> time, we COULD break encapsulation!
>
>
> I was long-winded the last time I responded to this point so no one probably 
> read it :)

Yes, we read it. You made good points!!

Cheers,
Hung
--
http://mail.python.org/mailman/listinfo/python-list


Re: is python Object oriented??

2009-01-30 Thread Hung Vo
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??

2009-01-29 Thread Hung Vo
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??

2009-01-29 Thread Hung Vo
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??

2009-01-29 Thread Hung Vo
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: How to read all files in a directory

2005-11-07 Thread Hung Vo

Hello Larry,
 
Thanks a lot for your response. It helps me a lot. 
 
I used your suggestion and got an error:
    path=r'C:\datafiles\'    ^SyntaxError: EOL while scanning single-quoted string
Then, I changed just a little bit and it works fine.
I set path='C:\\datafiles\\' instead of path=r'C:\datafiles\'
Again Larry, I appreciate your suggestion
 
Hung Vo.Larry Bates <[EMAIL PROTECTED]> wrote:
Not tested:import globimport ospath=r'C:\datafiles\'for fileName in glob.glob(os.path.join(path,'*.DAT')):dataFile=open(fileName, 'r').readlines().. Continue yur code here.-Larry Bateshungbichvo wrote:> Dear All,> > My python application is small. It reads data from a file.> My code is:> fileName = '900128.DAT'> dataFile = open(fileName, 'r').readlines()> I have to run 100 input files .DAT. Each time I run application, I have > to change code fileName to a new one. For example, fileName > = 'NewFile.DAT'.> I do not know how I can process all file with extension .DAT in a > specific directory once only.> > Any suggestion will be appreciated,> > Thank you.> > > 
		 Yahoo! FareChase - Search multiple travel sites in one click.

 

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