-1

I own a txt file that contains many lines Each line will be as the next

email1:password1
email2:password2
...
...
...
emailxx:passwordxx

I want a python code that reads the file line at a time Where the next is printed

email=username1
pass=password1

email=username2
pass=password2

email=username3
pass=password3
...
...
...
email=usernamexx
pass=passwordxx
4

3 回答 3

1

尝试以下操作:

with open('path/to/file.txt','r') as f:
    values = f.readline().split(":")
    print(f"email={values[0]}")
    print(f"pass={values[1]}\n")
于 2020-03-30T16:10:07.470 回答
0

谢谢我修好了

with open("xxx.txt") as f:
for line  in f.readlines():
   #print(line)
   values = line.split(":")
   email = values[0]
   pasw = values[1]
   print(f"user={email}\npass={pasw}\n")
于 2020-03-30T16:19:52.140 回答
-1

open 函数为您提供一个文件对象,并具有从文件中读取行的方法。

with open(filepath) as f:
    for line  in f.readlines():
       print(line)
       info = line.strip(":"))
       output = f"email={info[0]}\npass={info[2]}"
       print(output) 
f.close() #Close the file when you're done.
于 2020-03-30T16:06:58.343 回答