On Tue, May 5, 2009 at 22:16, Jaap Karssenberg
<jaap.karssenb...@gmail.com> wrote:
> untested example script:
>
> #!/usr/bin/python
> import sys
> dir = sys.argv[1]
> for root, dirs, files:

# The above line should be:
for root, dirs, files in os.walk(dir):

>   for file in files:
>      if file.endswith(".t2t"):
>         fh = open(root+'/'+file)
>         for i in range(4):
>            fh.readline() # skip 4 lines of headers
>         for line in fh:
>            sys.stdout.write(line)
>
# Mixing readline and "for line in fh" is AFAIK not recommended
# because of internal buffering issues.  More reliable:

        flines = iter(open(root+'/'+file))
        for i in range(4):
           flines.next() # skip 4 lines of headers
        for line in flines:
           sys.stdout.write(line)

# Or better yet (doesn't assume 4 lines):

        flines = iter(open(root+'/'+file))
        for line if flines:  # skip headers
           if line.strip() == "":
               break
        for line in flines:
           sys.stdout.write(line)

> This script would write all content to the terminal, so you can redirect it
> into a single file.
>

-- 
Beni <c...@users.sf.net>

_______________________________________________
Mailing list: https://launchpad.net/~zim-wiki
Post to     : zim-wiki@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zim-wiki
More help   : https://help.launchpad.net/ListHelp

Reply via email to