Python 将文本转换为 列表

将文本转换为 列表

原文件:

#cat file-name
thirdwx.qlogo.cn
thirdwx.qlogo.cn
thirdqq.qlogo.cn
tva3.sinaimg.cn
tva1.sinaimg.cn

处理脚本:

import os, sys, json
# BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
print(BASE_DIR)
sys.path.append(BASE_DIR)

domain_list = []
with open(BASE_DIR + "/%s" % "file-name", "rb") as domains:
    for z in domains:
        z = bytes.decode(z).strip()
        domain_list.append(z)
print(domain_list)
posted @ 2021-11-09 14:35  叨客厨子  阅读(749)  评论(0编辑  收藏  举报