Exemple #1
0
def main(filename, lines, line_num, current, results):

    if current.startswith(pattern):
        new_filename = current.rpartition('"')[0].rpartition('"')[2]

        dict_from_file = tw.read_file(new_filename, results=list())
        results.append(dict_from_file)
    return
Exemple #2
0
def main(filename, lines, line_num, current, results):
    if current.startswith(start_pattern):
        nline = 0
        for line in lines:

            nline += 1
            if nline < line_num:
                continue
            if line.startswith(end_pattern):
                break

        block_contents = list()
        tw.read_file(filename,
                     start_line=line_num+1,
                     end_line=nline-1,
                     results=block_contents)

        results.append({"type": storage_str, "value": block_contents})
        return nline+1
'''
Usage example for txt_wrangler.

A text file is read and the contents are stored within a Python dictionary.
Once the dictionary is retrieved, it is printed.
'''

import txt_wrangler as tw
import os

# Defines path to the modules to be used
tw.files_relative_to = r'data'
tw.modules_folders = r'modules'
main_file = r'main.txt'

# Defines path to the main file to analyse as well as the modules path
os.chdir(__file__.rpartition(os.sep)[0])

# Reads the file using text_wrangler
contents_dictionary = tw.read_file(main_file)
import json
print json.dumps(contents_dictionary, indent=4)