0

How would I loop through a text file and store a value. If I take a line from a text file, hello@aol.com:Password1, How would I store email as hello@aol.com , and password as Password1 ?

file = open("TEST.txt", "r")

for line in file:
    print(line)
Nithin
  • 1,065
  • 8
  • 15
  • 4
    What have you tried that didn't work ? Hint: python strings have quite a few useful methods... – bruno desthuilliers May 22 '19 at 12:56
  • 1
    Possible duplicate of [How can I split and parse a string in Python?](https://stackoverflow.com/questions/5749195/how-can-i-split-and-parse-a-string-in-python) – Faruq May 22 '19 at 14:00

1 Answers1

0

This is a useful way to "open files":

with open('TEST.txt', 'r') as f:
    f.readlines()

to split strings, you could use the split method:

'hello@aol.com:Password1'.split(':')

(the split method takes "what to split by" as an optional parameter)

As Bruno commented, you should take a look at string methods

ron_g
  • 1,474
  • 2
  • 21
  • 39