Не понимаю, почему это не сработает. Я выполняю lstrip () для строки, передаваемой в функцию, и пытаюсь увидеть, начинается ли она с "" ". По какой-то причине он попадает в бесконечный цикл
def find_comment(infile, line):
line_t = line.lstrip()
if not line_t.startswith('"""') and not line_t.startswith('#'):
print (line, end = '')
return line
elif line.lstrip().startswith('"""'):
while True:
if line.rstrip().endswith('"""'):
line = infile.readline()
find_comment(infile, line)
else:
line = infile.readline()
else:
line = infile.readline()
find_comment(infile, line)
И мой вывод:
Enter the file name: test.txt
import re
def count_loc(infile):
Вот верхняя часть файла, который я читаю для справки:
import re
def count_loc(infile):
""" Receives a file and then returns the amount
of actual lines of code by not counting commented
or blank lines """
loc = 0
func_records = {}
for line in infile:
(...)