I have a text file containing a string of ‘0’s and ‘1’s, followed by a space and another string of ‘0’s and ‘1’s of the same length. What would be the easiest way of storing the string before the space and the string after in two different variables?
Let’s say I have a text file called Text.txt. How would I store the first string in the variable ‘encryptedText’ and the second string in the variable ‘key’?
file = open("Text.txt", mode="r")
encryptedText = ""
key = ""
file.close()
What’s in the text file (all on the first line): 01001001010 11000100111
01001001010 should be stored in ‘encryptedText’, and 11000100111 should be stored in ‘key’.
>Solution :
easiest way is to split on space
with open("Text.txt", mode="r") as file:
encryptedtext, key = file.readline().split(' ')