hnc-eduard/HNC/Ladders/files.py

33 lines
822 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import os
def list_levels():
files = os.listdir(path='.')
result = []
for file in files:
if file.lower().endswith('.txt'):
result.append(file)
return result
def load(file):
# 1. Загрузить весь файл в строку
f = open(file, 'r')
s = f.read()
# 2. Заменить все пробелы и переводы строки на "ничего"
s = s.replace(' ', '')
s = s.replace('\n', '')
# 3. Из полученной строки создать массив, используя разделитель ","
a = s.split(',')
# a - массив строк, в которых хранятся числа
b = []
for x in a:
b.append(int(x))
# b - массив чисел из а
f.close()
return b