Python
Posted on August 10, 2005

I ranted about Java now let me do the same thing for Python. And just to be on the safe side I must say that I’m just learning it.
I got a “Dive into Python” book from the library and all my rants will be bases on information I got from this book.
When I write “boo: xxxx” It means that xxx is an quote from the book and “anal: xxx” is my analysis.
boo: __len__ is called when you call len(instance)
anal: thought the book author tells the everything in python is an object, so why does Python use functional way of getting the length?
boo:
try:
exept Error:
else:
if no exception is raised during the try block else clause is executed afterwards.
anal: if no exception is raised during the try block why should I jump from one location to another instead of simply continuing doing what I was doing in try block?
boo: for tag, (start, end, parseFunc) in self.tagDataMap.Items():
This looks complicated but it’s not.
anal: If it looks complicated it is complicated. Ex: ObjB a = (ObjB)((ObjA) t.getT(x.getV())).meth()).boo();. I don’t want to spend any time three month from now trying to understand what this code is trying to accomplish and how.
boo:
import os
import glob
dir=”\\home\\audio”
filelist = [os.path.join(dir, f)
for f in os.listDir(dir)
if os.path.splittext(f)[1] in “mp3″]
glob.glob(dir+’\\*.mp3′);
anal: glob what an intuitive name, but ok it’s used alot in Unix. But if it’s possible to accomplish same thing with os module why add a glob of synthetic sugar to standard library ;-)?
boo:
def copy(self)
if self.__class__ is UserDict(self.data)
return UserDict(self.data)
import copy
return copy.copy(self)
The copy method of a real dictionary returns a new dictionary that is an exact duplicate of the original.
If self.__class__ is not UserDict, then self must be some subclass of UserDict. UserDict doesn’t know how to make an exact copy of one of its descendants; there could, for instance, be other data attributes defined in the subclass, so you would need to iterate through them and make sure to copy all of them. Luckily, Python comes with a module to do exactly this, and it’s called copy.
anal:
I’m not sure that base class should care about it’s subclasses.
ok enough for now.
Filed Under Uncategorized |
Leave a Comment
If you would like to make a comment, please fill out the form below.