I've got this piece of code that I want to write the output to a text file but with the correct format i.e. no brackets, single quotes so it appears as a formatted list.
This is the code:
file = open("env5.txt", "w");
for key in os.environ.keys():
  env = os.environ[key];
  key1 = key;
  list = str([key, env]).replace("'","").replace('[]', '');
  list2 = list[1:-1];
  print(list2);
  file.writelines(list2);
file.close();
This is the original code:
for key in os.environ.keys():
print(key, os.environ[key]);
Many thanks