NFO convert to plain text(txt) python script

infile = open("test",'r')

line = infile.read()

newline = ""
for i in range(0,len(line)):
    c1 = ord(line[i])
    if c1 > 0x7e or c1 < 0x20:
        if c1 == 0x0a or c1 == 0x0d:

infile = open("test",'r')

line = infile.read()

newline = ""
for i in range(0,len(line)):
    c1 = ord(line[i])
    if c1 > 0x7e or c1 < 0x20:
        if c1 == 0x0a or c1 == 0x0d:
            newline += line[i]
        else:
            newline += " "
    else:
        newline += line[i]
print newline

import string
import re

pattern_empty = """^\s*$"""
pattern_head = """^\s+"""
pattern_tail = """\s+$"""
reg_empty = re.compile(pattern_empty,re.MULTILINE)
reg_head = re.compile(pattern_head,re.MULTILINE )
reg_tail = re.compile(pattern_tail,re.MULTILINE)
newline, num = reg_empty.subn("
",newline)
newline, num = reg_head.subn(" ",newline)
newline, num = reg_tail.subn(" ",newline)

print newline
print num

Leave a Reply

Your email address will not be published. Required fields are marked *