LINUX.ORG.RU

История изменений

Исправление iljuase, (текущая версия) :

#!/usr/bin/python3
a=open('./big_file.txt', 'r')       
file_counter=0
temp_file=open(str(file_counter)+".txt", 'w')
for str_num, string in enumerate(a.readlines()):
    if str_num%500==0 and str_num!=0:
        file_counter+=1
        temp_file.close()                     
        temp_file=open(str(file_counter)+".txt", 'w')
    temp_file.write(string)
temp_file.close()

-------------------------------------------
vodka@vodka-PC:/tmp$ cat ./big_file.txt | wc -l
50000
vodka@vodka-PC:/tmp$ cat 55.txt | wc -l
500
vodka@vodka-PC:/tmp$ ll [0-9]*.txt | wc -l
100

Исходная версия iljuase, :

я у мамки python3-программист

#!/usr/bin/python3
a=open('./big_file.txt', 'r')       
file_counter=0
temp_file=open(str(file_counter)+".txt", 'w')
for str_num, string in enumerate(a.readlines()):
    if str_num%500==0 and str_num!=0:
        file_counter+=1
        temp_file.close()                     
        temp_file=open(str(file_counter)+".txt", 'w')
    temp_file.write(string)
temp_file.close()