Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I read two variables from a txt file that are on the same line? in python [duplicate]

lets say you have a basic txt file with:

USERNAME(var1):PASSWORD(var2):VAR3
USERNAME(var1):PASSWORD(var2):VAR3
... etc...

And I want to be able to read that in my script/code as:

Username = var1
Password = var2
something = var3

And implement that like:

username = var1
password = var2
s.login(var1, var2)

file = open(var3, 'r')

I have been spitting through a lot of code, trying to reverse engineer some things, but it's not quite working out. If someone could shed some light that'd be great.

I need to make these lists myself, so I can use any separator I want (,, ;, : etc).

like image 407
Snowlav Avatar asked Sep 07 '25 13:09

Snowlav


1 Answers

with open('basic.txt') as f:
    for line in f:
        username, password, filename = line.split(':')
        print(username, password, filename)
like image 195
poke Avatar answered Sep 09 '25 04:09

poke