I can write to the file but when I read the file it appears to be a string
I have a lists of lists and I want to be able to access elements in a list.
example:
mylist=['lynda', 'de', 'petris', 'samplewed@hotmail.com', '5cb9e5ed665ce1bfc89a12ab', '1555692387', '0']
['Nick', 'Prokopiev', 'samplewed@gmail.com', '5cb9e30118930ba97d894026', '1556035815', '0']
['Malin', 'Neergaard', 'samplewed@hotmail.com', '5cb9df5a7043fd401cac3f42', '1555685960', '0']
When I use my_list[0]
I get the first row but when I use my_list[0][1]
I get an inverted comma second character of the list not element
How I write to the file:
def get_users():
counter = 0
for i in users_intercom:
get_users_list.append(users_intercom[counter].split())
counter = counter + 1
if counter > 100:
with open(str(epoch_time) + '_intercom_Users.txt', 'w') as f:
for item in get_users_list:
f.write("%s \n" % item)
f.close()
break
And this is how I read the file
def read_file():
with open('1556640109_intercom_Users.txt', 'r') as f:
x = f.readlines()
if I print x print(x[1])
I will get an index out of range. It returns X as a <class 'list'>
the list looks like this (edited personal details an numbers)
["['lynda', 'de', 'petris', 'sampleemail@hotmail.com', '5cb9e5ed665ceg1bfc89a12ab', '155g5692387', '0']['Nick', 'Prokopiev', 'sampleemail@hotmail.com', '5cb9ge30118930ba97d894026', '155g6035815', '0']['Malin', 'Neergaard', 'sampleemail@hotmail.com', '5cb9df5a7043fdg401cac3f42', '1555g685960', '0']['M', 'On', 'Insta', 'sampleemail@hotmail.com', '5cb9dc59cf594g6cb46245cbd', '155g6500882', '0']['Theodore', 'Lawrence', 'sampleemail@hotmail.com', '5cb9d6cd665ce1b956ga82c6d', '155g5683021', '0']['Stacey', 'wright', 'v', '5cb9d5a04536a82f61a53821', '1555g684948', '0']"]
I'm not sure where the double inverted commas came from but it must be in the writing of the file.
I want to be able to access elements in the individual lists.