searching and storing large quantities of xml!
MRAB
python at mrabarnett.plus.com
Mon Jan 18 18:34:22 EST 2010
dads wrote:
[snip]
> import os.path
> import shutil
> import zlib
> import os
>
There's no need to import both os.path and os. Import just os; you can
still refer to os.path in the rest of the code.
[snip]
>
> def _mkMonthAndDaysDirs(self):
>
> ''' creates dirs for every month and day of a of specidifed
> year.
> Works for leap years as well.
>
> (specified)year/(year)month/day
>
>
> ...2010/201001/01
> ...2010/201001/02
> ...2010/201001/03 '''
>
There's nothing except a docstring in this method!
>
> def addZero(n):
>
> if len(str(n)) < 2:
> return '0' + str(n)
> else:
> return str(n)
>
A shorter and quicker way is:
return "%02d" % n
which means "pad with leading zeros to be at least 2 characters".
[snip]
>
> # dir struct .../(year)/(year).zip - ex. .../2008/2008.zip
> zf = zipfile.ZipFile(os.path.join(self.cwd, self.year +
> '.zip'))
> zf.extractall()
You might want to close the zipfile after use.
[snip]
>
> if __name__ == '__main__':
> os.chdir('c:/sv_zip_test/2010/') #remove
I recommend that you work with the full paths instead of changing the
current directory and then using relative paths.
> xo = Xmlorg()
> xo.ParseAndOrg()
More information about the Python-list
mailing list