繁体   English   中英

基于txt文件使用Python对数据进行排序

[英]Sort data using Python based on txt file

我拥有一个包含多行的 txt 文件每一行都将作为下一行

username1:password1
username2:password2
...
...
...
usernamexx:passwordxx

我想要一个 python 代码,它一次读取文件行,其中打印下一个

user=username1
pass=password1

user=username2
pass=password2

user=username3
pass=password3
...
...
...
user=usernamexx
pass=passwordxx
with open("xxx.txt", "r", encoding="u8") as fp:
    for line_data in fp:
        user, pwd = fp.strip().split(":")
        print(f"user={user}\npass={pwd}\n")

with open("xxx.txt") as f:
for line  in f.readlines():
   #print(line)
   values = line.split(":")
   user = values[0]
   pasw = values[1]
   print(f"user={user}\npass={pasw}\n")
f.close() #Close the file when you're done.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM