python读取txt去除换行符

def rule_woed_read(file):#"rules/condition1.txt"
    with open(file,"r",encoding='gbk') as f:
        f= f.read().splitlines()
        rule=[]
        for i in f:
            if len(i)>1:rule.append(i)  
    return rule

你可能感兴趣的:(python杂记,python,java,c++)