К книге
Приложение к «Python в библиотеке»Arch. 3. spas2.py
9%
Arch. 3. spas2.py
3

#!/bin/env python

# -*- coding: utf-8 -*-

# replacing spaces with dots

import sys, os

path = os.getcwd()

def work():

new_List = [] #

old_List = []

new_List.clear() #

old_List.clear()

print('')

FN = input('Введите имя файла:')

fn1=os.path.join(path, FN)

base=os.path.splitext(FN)[0]

fb2_file=open(fn1,'r')

old_List=fb2_file.readlines()

fb2_file.close()

n = 0

for item in old_List:

, , n += 1

, , s='|'+item

, , s=s.replace('\t',' ')

, , s=s.replace('| ','| . .')

, , s=s.replace(' ',' . .')

, , s = "{0:2d}{1:s}".format(n,s)

, , new_List.append(s)

fn2=os.path.join(path, base)+".txt"

new_file=open(fn2,'w')

for item in new_List:

, , new_file.write(item)

new_file.close()

print('Done')

while True:

work() # Exit => Ctrl + C

Предыдущая главаГлава 3 из 34Следующая глава