def tar(file, filelist, expression='^.+$'):
 tar = tarfile.TarFile(file, 'w')
 try:
  for element in filelist:
   try:
    for file in listdir(element, expression, add_dirs=True):
     tar.add(os.path.join(element, file), file, False)
   except:
    tar.add(element)
 finally:
  tar.close()

def tar ( file , filelist , expression = '^.+$' ) : tar = tarfile . TarFile ( file , 'w' ) try : for element in filelist : try : for file in listdir ( element , expression , add_dirs = True ) : tar . add ( os . path . join ( element , file ) , file , False ) except : tar . add ( element ) finally : tar . close ( )
tars dir into file .