[Tutor] Short Version, New guy looking for some tips, Revisited.
Rich Krauter
rmkrauter at yahoo.com
Sat Feb 7 16:56:11 EST 2004
On Sat, 2004-02-07 at 16:26, Joshua Banks wrote:
> Am I asking for a simple example. Nothing more than that.
Why don't you just take a stab at it? It doesn't have to be perfect. You
should see how many dumb ideas I've posted in attempt to just take a
stab at trying to solve something. Big deal. That's the whole point of
the mailing list.
Here's a quick example. It's bad and inflexible and very limited and
likely to die very badly in many common situations, but maybe it'll get
you started.
<bad example>
# requires python 2.3
import tarfile
import sys
import os,os.path
if __name__ == '__main__':
fname = 'test.tar'
ext = '.gz'
archive = '%s%s'%(fname,ext)
if os.path.exists(archive):
print 'gunzip-ing %s'%archive
os.system('gunzip %s'%(archive))
tar = tarfile.open(fname,'a')
for f in sys.argv[1:]:
print 'adding %s to %s ...'%(f,fname)
tar.add(f)
tar.close()
if os.path.exists(fname):
print 'gzip-ing %s'%fname
os.system('gzip %s'%fname)
</bad example>
Rich
More information about the Tutor
mailing list