So I wrote the following code:
import appuifw
def get_data_from_file():
fp = open('c:\\names.txt', 'r')
li = fp.readlines()
fp.close()
compList = []
for item in li:
item = item.decode("utf-8")
compList.append(item)
return compList
L = get_data_from_file()
index = appuifw.selection_list(choices=L , search_field=1)
Yes, it works. Note that you must decode each line to unicode (utf-8). (
item = item.decode("utf-8"))But wait, what are those small boxes beside each name? I guess it's the newline character ('\n') after each line. So I need to replace '\n' with a blank ''.
Here is the modified get_data_from_file()
def get_data_from_file():
fp = open('c:\\names.txt', 'r')
li = fp.readlines()
fp.close()
compList = []
for item in li:
item = item.replace('\n', '')
item = item.replace('\r', '')
item = item.decode("utf-8")
compList.append(item)
return compList
Now it looks fine!
Next to-do is to grab the file from a remote URL and store it in mobile phone memory, then display the list.


0 comments:
Post a Comment