saving textScrollList in a file


#1

I want to save a textScrollList in a file and later open that file in a textScrollList.
How can I do it in python?
What should be the format of the saved file?


#2

Do you mean you just want to save the list of items in a file, or something more than that?
I usually find json is a convenient way to save simple data structures to files.

David


#3

I just want to save the list and retrieve it later and open in a textScrollList.


#4

Yep. Well json should work.


# data and filepath
data = ['item1', 'item2', 'item3']
filepath = 'X:/dataStore/dataList.json'

# write to file
import json
dataFile = open(filePath, 'w')
dataFile.write(json.dumps(data))

# read back from file
data = json.load(open(filePath))

David


#5

Thanks djx. Its done.