hey,

here is what I do with plugin_wiki (usually for automated reports, but
here is a simplified sample):


    header = ['First_Name', 'Last_Name', 'Age', 'Description']
    data = \
    '''fred,Flintstone,32,always gets into trouble,
       Barney,Rubble,33,is always willing to help Fred
       Mr,Slate,31,good businees man but not a people person
       Dino,dinosaur,3,looks like he should be a dog
       Pebbles,Flintstone,2,Great kid but does not talk much'''


    if isinstance(data,str):
        rows = [row.strip().split(',')  for row in data.splitlines()]
    if header is not None:
        nHeader = []
        for h in header:
            nHeader.append('**{0}**'.format(h))
        markminTable = table_lists2Markmin([nHeader] + rows)
    else:
        markminTable = table_lists2Markmin([header] + rows)
    print markminTable


# here is the function that makes a markmin table (sorry if the
formatting looks bad here):

def table_lists2Markmin(rows):
    tableRows = deque()
    for tRows in [([[sStr for sStr in item] for item in map(None,
                           *[item.split('\n') for item in row])]) for
row in rows]:
        for tableRow in tRows:
            tableRows.append('{0}'.format(' |
'.join([string.join(string.strip(item),
                                                                  '')
for item in tableRow])))
    return '-------\n{0}\n-------'.format(string.join(tableRows,'\n'))


Usually the string "data" (it can be a list or a table as well) gets
passed to a function that will make use (not shown here be it has too
many lines) of anything we have in markmin by doing something like
below.

data = \
    '''fred,Flintstone,32,always gets into trouble,
       Barney,Rubble,33,is always willing to help Fred
       Mr,Slate,31,good business man and this is his {0}
       Dino,dinosaur,3,looks like he should be a dog
       Pebbles,Flintstone,2,Great kid but does not talk much
'''.format(mmObj.mLink('favorite link','http:/www.google.com'))


makes automating Markmin tables easy through automation and decorating
the fileds as well.

hope it helps,
Mart :)

On Mar 3, 4:30 pm, Anthony <[email protected]> wrote:
> On Thursday, March 3, 2011 4:26:19 PM UTC-5, Anthony wrote:
>
> > On Thursday, March 3, 2011 4:19:06 PM UTC-5, pbreit wrote:
>
> >> Yeah, I got kind of lost, too. The thing that threw me off were "trs[] ="
> >> and "tables[] =". The = sign is for assignment, not adding or appending.
> >> Each "trs[] =" is re-assigning the whole variable each time, overwriting
> >> anything that was already there (if I'm not mistaken).
>
> > Actually, I think that simply raises a syntax error.
>
> I think
>
> trs[:] = something
>
> would overwrite trs, as long as 'something' is an iterable.

Reply via email to