def write(filename, headers, dcols, data, headerlines=[],
          header_char='H', sldir='.', sep='  ', trajectory=False,
          download=False):
    '''
    Method for writeing Ascii files.

    Note the attribute name at position i in dcols will be associated
    with the column data at index i in data.  Also the number of data
    columns(in data) must equal the number of data attributes (in dcols)
    Also all the lengths of that columns must all be the same.

    Parameters
    ----------
    filename : string
        The file where this data will be written.
    Headers : list
        A list of Header strings or if the file being written is of
        type trajectory, this is a List of strings that contain header
        attributes and their associated values which are seperated by
        a '='.
    dcols : list
        A list of data attributes.
    data : list
        A list of lists (or of numpy arrays).
    headerlines : list, optional
        Additional list of strings of header data, only used in
        trajectory data Types. The default is [].
    header_char : character, optional
        The character that indicates a header lines. The default is 'H'.
    sldir : string, optional
        Where this fill will be written. The default is '.'.
    sep : string, optional
        What seperates the data column attributes. The default is '  '.
    trajectory : boolean, optional
        Boolean of if we are writeing a trajectory type file. The
        default is False.
    download : boolean, optional
        If using iPython notebook, do you want a download link for
        the file you write?
        The default is False.

    '''
    if sldir.endswith(os.sep):
        filename = str(sldir)+str(filename)
    else:
        filename = str(sldir)+os.sep+str(filename)
    tmp=[] #temp variable
    lines=[]#list of the data lines
    lengthList=[]# list of the longest element (data or column name)
                 # in each column

    if os.path.exists(filename):
        print('Warning this method will overwrite '+ filename)
        print('Would you like to continue? (y)es or (n)no?')
        s = input('--> ')
        if s=='Y' or s=='y' or s=='Yes' or s=='yes':
            print('Yes selected')
            print('Continuing as normal')
        else:
            print('No Selected')
            print('Returning None')
            return None

    if len(data)!=len(dcols):
        print('The number of data columns does not equal the number of Data attributes')
        print('returning none')
        return None
    if trajectory:
        sep=' '
    for i in range(len(headers)):
        if not trajectory:
            tmp.append(header_char+' '+headers[i]+'\n')
        else:
            tmp.append(headers[i]+'\n')
    headers=tmp
    tmp=''

    for i in range(len(data)): #Line length stuff
        length=len(dcols[i])
        for j in range(len(data[dcols[i]])): #len(data[i]) throws error as type(data)=dict, not list
            if len(str(data[dcols[i]][j]))>length: #data[i][j] throws error as type(data)=dict, not list
                length=len(str(data[dcols[i]][j]))
        lengthList.append(length)
    print(lengthList)

    tmp=''
    tmp1='9'
    if trajectory:
        tmp='#'
    for i in range(len(dcols)):
        tmp1=dcols[i]
        if not trajectory:
            if len(dcols[i]) < lengthList[i]:
                j=lengthList[i]-len(dcols[i])
                for k in range(j):
                    tmp1+=' '
            tmp+=sep+tmp1
        else:
            tmp+=' '+dcols[i]
    tmp+='\n'
    dcols=tmp
    tmp=''


    for i in range(len(data[0])):
        for j in range(len(data)):
            tmp1=str(data[j][i])
            if len(str(data[j][i])) < lengthList[j]:
                l=lengthList[j]-len(str(data[j][i]))
                for k in range(l):
                    tmp1+=' '
            tmp+=sep+tmp1
        lines.append(tmp+'\n')
        tmp=''

    f=open(filename,'w')
    if not trajectory:
        for i in range(len(headers)):
            f.write(headers[i])
        f.write(dcols)
    else:
        f.write(dcols)
        for i in range(len(headerlines)):
            f.write('# '+headerlines[i]+'\n')
        for i in range(len(headers)):
            f.write(headers[i])
    for i in range(len(lines)):
        f.write(lines[i])

    f.close()
    if download:
        from IPython.display import FileLink, FileLinks
        return FileLink(filename)
    else:
        return None
def write ( filename , headers , dcols , data , headerlines = [ ] , header_char = 'H' , sldir = '.' , sep = '  ' , trajectory = False , download = False ) : if sldir . endswith ( os . sep ) : filename = str ( sldir ) + str ( filename ) else : filename = str ( sldir ) + os . sep + str ( filename ) tmp = [ ] lines = [ ] lengthList = [ ] if os . path . exists ( filename ) : print ( 'Warning this method will overwrite ' + filename ) print ( 'Would you like to continue? (y)es or (n)no?' ) s = input ( '--> ' ) if s == 'Y' or s == 'y' or s == 'Yes' or s == 'yes' : print ( 'Yes selected' ) print ( 'Continuing as normal' ) else : print ( 'No Selected' ) print ( 'Returning None' ) return None if len ( data ) != len ( dcols ) : print ( 'The number of data columns does not equal the number of Data attributes' ) print ( 'returning none' ) return None if trajectory : sep = ' ' for i in range ( len ( headers ) ) : if not trajectory : tmp . append ( header_char + ' ' + headers [ i ] + '\n' ) else : tmp . append ( headers [ i ] + '\n' ) headers = tmp tmp = '' for i in range ( len ( data ) ) : length = len ( dcols [ i ] ) for j in range ( len ( data [ dcols [ i ] ] ) ) : if len ( str ( data [ dcols [ i ] ] [ j ] ) ) > length : length = len ( str ( data [ dcols [ i ] ] [ j ] ) ) lengthList . append ( length ) print ( lengthList ) tmp = '' tmp1 = '9' if trajectory : tmp = '#' for i in range ( len ( dcols ) ) : tmp1 = dcols [ i ] if not trajectory : if len ( dcols [ i ] ) < lengthList [ i ] : j = lengthList [ i ] - len ( dcols [ i ] ) for k in range ( j ) : tmp1 += ' ' tmp += sep + tmp1 else : tmp += ' ' + dcols [ i ] tmp += '\n' dcols = tmp tmp = '' for i in range ( len ( data [ 0 ] ) ) : for j in range ( len ( data ) ) : tmp1 = str ( data [ j ] [ i ] ) if len ( str ( data [ j ] [ i ] ) ) < lengthList [ j ] : l = lengthList [ j ] - len ( str ( data [ j ] [ i ] ) ) for k in range ( l ) : tmp1 += ' ' tmp += sep + tmp1 lines . append ( tmp + '\n' ) tmp = '' f = open ( filename , 'w' ) if not trajectory : for i in range ( len ( headers ) ) : f . write ( headers [ i ] ) f . write ( dcols ) else : f . write ( dcols ) for i in range ( len ( headerlines ) ) : f . write ( '# ' + headerlines [ i ] + '\n' ) for i in range ( len ( headers ) ) : f . write ( headers [ i ] ) for i in range ( len ( lines ) ) : f . write ( lines [ i ] ) f . close ( ) if download : from IPython . display import FileLink , FileLinks return FileLink ( filename ) else : return None
Method for writeing Ascii files.

    Note the attribute name at position i in dcols will be associated
    with the column data at index i in data.  Also the number of data
    columns(in data) must equal the number of data attributes (in dcols)
    Also all the lengths of that columns must all be the same.

    Parameters
    ----------
    filename : string
        The file where this data will be written.
    Headers : list
        A list of Header strings or if the file being written is of
        type trajectory, this is a List of strings that contain header
        attributes and their associated values which are seperated by
        a '='.
    dcols : list
        A list of data attributes.
    data : list
        A list of lists (or of numpy arrays).
    headerlines : list, optional
        Additional list of strings of header data, only used in
        trajectory data Types. The default is [].
    header_char : character, optional
        The character that indicates a header lines. The default is 'H'.
    sldir : string, optional
        Where this fill will be written. The default is '.'.
    sep : string, optional
        What seperates the data column attributes. The default is '  '.
    trajectory : boolean, optional
        Boolean of if we are writeing a trajectory type file. The
        default is False.
    download : boolean, optional
        If using iPython notebook, do you want a download link for
        the file you write?
        The default is False.