def get_dtb_model(filename, min_length=4):
""" Finds the first printable string in a file with length greater
than min_length. Replaces spaces with underscores.
"""
with open(filename, errors="ignore") as f:
result = ""
for c in f.read():
if c in string.printable:
result += c
continue
if len(result) >= min_length:
return result.replace(" ", "_")
result = ""
if len(result) >= min_length: # catch result at EOF
return result.replace(" ", "_")
return None
评论列表
文章目录