I have a array which has 5 values and I want to write it in a text file with 1st value starting from 1st col and second value from 7th col and 3rd value from 10th column of a single line.. is there any way to formate that array and write it in to a file ? Can anyone pls guide me on how to do it..?
Id 1st arrange the list in order you wish, then:
The best was is to use json, which is structured text and can be read by many applications (including yours)
and also by ant text editor.
to save, it's simple:
import json
with open(filename, 'w') as jout:
json.dump(listname, jout)
You may have to install json
to read back in:
import json
with open(filename) as jin:
listname = json.load(jin)
[/code]
After the with statement (next line), the 4 white space indentation is missing.
with open(filename, 'w') as jout:
# code inside the context manager
# code outside the context manager
# the context manager is closing the file automatically when
# leaving the context block
# is also called, when the program gets an KeyboardInterrupt
This is a result of the changed editor.
They were there before copy!
code fixed