pythonfilevarreadlineseparator

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


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).


Solution

  • with open('basic.txt') as f:
        for line in f:
            username, password, filename = line.split(':')
            print(username, password, filename)