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)


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM