zoukankan      html  css  js  c++  java
  • Python 写入和读取txt数据

    写数据到txt里

    一. 在本地盘符里新建一个txt文本文档,如下图所示

    二.打开PyCharm,新建一个Python File  ,写入以下代码

    import  random
    import string


    #写数据到txt文件里

    all_str = string.ascii_letters + string.digits
    for i in range(1,11):
    account = ''.join(random.sample(all_str,8))+'@163.com'
    password = random.randint(100000,999999)
    x = str(account) +"," + str(password) + " "
    with open("E:\JMETER\account.txt","a") as yy:
    yy.write(x)
    print(u"生成第[%d]个账号"%(i))


    三.运行程序,查看结果

    四.检查盘符的txt文档数据

    读取txt文本文档里的数据

    一.打开txt文本文档

    二.打开PyCharm,创建一个Python File ,写入如下所示代码

    #读取txt文件
    file=open("E:\JMETER\account.txt",'r',encoding='utf-8')
    userlines = file.readlines()
    file.close()

    for line in userlines:
    account = line.split(',')[0]
    password= line.split(',')[1]
    print(account,password)


    三.运行程序,查看结果

     四.检查程序结果和txt文本文档数据



  • 相关阅读:
    打开网页总结
    学期总结
    总结
    Sprint3
    Sprint2团队贡献分
    6.14
    典型用户与场景
    5种创建型模式
    JAVA 将接口的引用指向实现类的对象
    Java里的接口
  • 原文地址:https://www.cnblogs.com/tanchao/p/14020231.html
Copyright © 2011-2022 走看看