original_docstring:  Split tabs of a single XLS file into multiple CSV files.
          Returns list of file paths.
          
docstring: Split tabs of a single XLS file into multiple CSV files.
  Returns list of file paths.
docstring_tokens: Split tabs of a single XLS file into multiple CSV files . Returns list of file paths .
code: def _splitxls(stream, filename, destpath="/tmp", destfilename=None, tabs=0, header_line=0):
          """ Split tabs of a single XLS file into multiple CSV files.
          Returns list of file paths.
          """
  
          if isinstance(tabs, int):
              tabs = (tabs,)
  
          def _getNewFilename(i):
              suffix = "_tab%s.csv" % i
              fn, __ext = os.path.splitext(destfilename or filename)
              return fn + suffix 
  
          def _loopOsheets():
              """ Loop over XLS file sheets """
              if filename.endswith("zip"):
                  with zipfile.ZipFile(stream, "r") as cnt:
                      with xlrd.open_workbook(file_contents=cnt.read(cnt.namelist()[0])) as xlsSRC:
                          for sindex in (tabs or xrange(xlsSRC.nsheets)):
                              yield sindex, xlsSRC.sheet_by_index(sindex)
              else:
                  with xlrd.open_workbook(file_contents=stream.read()) as xlsSRC:
                      for sindex in (tabs or xrange(xlsSRC.nsheets)):
                          yield sindex, xlsSRC.sheet_by_index(sindex)
  
          newcsvpaths = {}
          for sindex, sheet in _loopOsheets():
              newcsvpath = os.path.join(destpath, _getNewFilename(sindex))
              with open(newcsvpath, "w") as destcsv:
                  mysreader = SheetReader(sheet, header_line=header_line)
                  csvwriter = csv.DictWriter(destcsv, fieldnames=mysreader.header)
                  csvwriter.writeheader()
                  for r in mysreader():
                      csvwriter.writerow(r)
              newcsvpaths["tab%s" % sindex] = newcsvpath
  
          return newcsvpaths
code_tokens: def _splitxls ( stream , filename , destpath = "/tmp" , destfilename = None , tabs = 0 , header_line = 0 ) : if isinstance ( tabs , int ) : tabs = ( tabs , ) def _getNewFilename ( i ) : suffix = "_tab%s.csv" % i fn , __ext = os . path . splitext ( destfilename or filename ) return fn + suffix def _loopOsheets ( ) : """ Loop over XLS file sheets """ if filename . endswith ( "zip" ) : with zipfile . ZipFile ( stream , "r" ) as cnt : with xlrd . open_workbook ( file_contents = cnt . read ( cnt . namelist ( ) [ 0 ] ) ) as xlsSRC : for sindex in ( tabs or xrange ( xlsSRC . nsheets ) ) : yield sindex , xlsSRC . sheet_by_index ( sindex ) else : with xlrd . open_workbook ( file_contents = stream . read ( ) ) as xlsSRC : for sindex in ( tabs or xrange ( xlsSRC . nsheets ) ) : yield sindex , xlsSRC . sheet_by_index ( sindex ) newcsvpaths = { } for sindex , sheet in _loopOsheets ( ) : newcsvpath = os . path . join ( destpath , _getNewFilename ( sindex ) ) with open ( newcsvpath , "w" ) as destcsv : mysreader = SheetReader ( sheet , header_line = header_line ) csvwriter = csv . DictWriter ( destcsv , fieldnames = mysreader . header ) csvwriter . writeheader ( ) for r in mysreader ( ) : csvwriter . writerow ( r ) newcsvpaths [ "tab%s" % sindex ] = newcsvpath return newcsvpaths
short_docstring: Split tabs of a single XLS file into multiple CSV files.
short_docstring_tokens: Split tabs of a single XLS file into multiple CSV files .
comment: """ Split tabs of a single XLS file into multiple CSV files.
          Returns list of file paths.
          """$SEP$""" Loop over XLS file sheets """