[vox-tech] python: slicing extensions from file names
Tim Riley
vox-tech@lists.lugod.org
Wed, 30 Jul 2003 09:33:42 -0700
Norm Matloff wrote:
> <snip>
>
> By the way, I can't resist urging all you Perl users out there to switch
> to Python. :-) It's much cleaner and elegant than Perl, and a joy to
> program in.
Python is a joy because its structure encourages the construction of
classes, thereby increasing readability and reusability. Also, its syntax
allows you to put simple "driver" code at the bottom of classes
to easily test your work.
For example, lets say you have a "person" class having the "move" operation.
#!/usr/bin/python
class person:
# Instantiation
# -------------
def __init__( self, first_name, last_name ):
self.first_name = first_name
self.last_name = last_name
self.street_address = ''
self.city = ''
self.state = ''
self.zip_code = ''
def move( self,
street_address,
city,
state,
zip_code ):
self.street_address = street_address
self.city = city
self.state = state
self.zip_code = zip_code
# Test driver
# -----------
if ( __name__ == "__main__" ):
fred = person( 'Fred', 'Jones' )
fred.move( '555 Elm St.', 'Davis', 'CA', '95822' )
I've seen examples of Perl showing class creation, but does it have
this ability to easily test them?
> I have a tutorial at
>
> http://heather.cs.ucdavis.edu/~matloff/python.html
>
> Norm
>
> _______________________________________________
> vox-tech mailing list
> vox-tech@lists.lugod.org
> http://lists.lugod.org/mailman/listinfo/vox-tech