python从文件读取列表

def getplace():
    path = "p.ini"
    #txt = open(path, "r", encoding="UTF-8")
    txt = open(path, "r", encoding="utf-8-sig")
    
    for line in txt.readlines():
        # txt.readlines()读取整个文件,返回数据中每一行有\n存在,需使用line.strip去掉
        # readlines()方法读取整个文件所有行,保存在一个列表(list)变量中,每行作为一个元素,但读取大文件会比较占内存
        line = line.strip()   # 去掉每行头尾空白
        if len(line) >0:
            place.append(str(line))
    print(place)

你可能感兴趣的:(python,python,http,multiprocessing)