0

I've done my due diligence trying to find an answer to this, but haven't had any luck.

Example string:

test = 'CurrentEmail:EMAIL@gmail.com\n' \
       'CurrentTime:TIME\n' \
       'CurrentLocation:LOCATION'

What I am trying to do is define each one of those parameters separately as in:

CurrentEmail = 'EMAIL@gmail.com', CurrentTime = 'TIME', CurrentLocation = 'LOCATION'.

So somehow extracting between the : and the next line, \n all from that same test string.

Thank you very much for your help!

EDIT: I was able to use the following.

new_test = test.splitlines()
for lines in new_test:
if 'CurrentEmail:' in lines:
    CurrentEmail = lines.replace('CurrentEmail:', '')
elif 'CurrentTime' in lines:
    CurrentTime = lines.replace('CurrentTime:', '')
elif 'CurrentLocation:' in lines:
    CurrentLocation = lines.replace('CurrentLocation:', '')
else:
    continue

0 Answers0