Hi guys
How can i create a list with 2 array?
I've tried with
without success.Code:list = [array1,array2]![]()
Hi guys
How can i create a list with 2 array?
I've tried with
without success.Code:list = [array1,array2]![]()
Do you mean create an array that contains the two arrays? You can do that like you said. What do you mean by "without success"?
Do you mean create an array that has the elements of the two arrays? You simply add the two arrays:Code:>>> a=[1,2,3] >>> b=["a","b","c"] >>> c=[a,b] c [[1, 2, 3], ['a', 'b', 'c']]
Code:>>> a=[1,2,3] >>> b=["a","b","c"] >>> c=a+b >>> c [1, 2, 3, 'a', 'b', 'c']
I would like to create a double-item listbox with 2 arrays.
Well that's different. You should have said that from the start. Read the PyS60 Library Reference, the section about Listbox, to see how you can do it (basically you just call the Listbox constructor with an array of 2 tuples). And you can check out this article.
I've readed the article and the pdf but i can not understand how to create a list with the two arrays.![]()
You don't actually create a Listbox with 2 arrays. You create it with one array that contains the 2 arrays (in the form of tuples). For example:
Code:array1 = (u"Item1", u"Description1") array2 = (u"Item2", u"Description2") #Now make one array that contains the two myarray = [array1, array2] #Make the listbox appuifw.Listbox(myarray, lambda:None)
My code is:
This is the error:Code:inb = inbox.Inbox() sms_ids = inb.sms_messages() mittente = [] msgs = [] for id in sms_ids: msgs.append(inb.content(id)) mittente.append(inb.address(id)) items = [msgs, mittente] appuifw.Listbox(items,lambda:None)
Code:appuifw.Listbox(items,lambda:None) SymbianError: [Errno -6] KErrArgument
That's because your arrays are lists, not tuples (like I said before). You have to use msgs=tuple(msgs) and the same for mittente before using them to create the Listbox.
Now i've this error:
Code:ValueError: tuple must include 2 or 3 elements
That's because a tuple used in a double-line Listbox can only have 2 items as Unicode strings (that's why it's called double-item) or 3 items as Unicode strings and an Icon object.
If you want to add several entries in your Listbox (I guess you have quite a few messages in your inbox), simply make a tuple for each message, with its content and address. Then put all those tuples in one list and use it to create the Listbox.
I would use the double-item listbox like as the http://wiki.forum.nokia.com/index.ph...to_use_Listbox
where in the first line there are the sms and in the second line the sender of the sms.
Exactly. And for each SMS you need to have a tuple. Each tuple has two elements: the content of the SMS and the sender of the SMS. Then put those tuples in one list and make the Listbox with it.
Code:tuple1 = (u"Message1", u"Sender1") tuple2 = (u"Message2", u"Sender2") ... mylist = [tuple1, tuple2,...] appuifw.Listbox(mylist, lambda:None)
Ok, but if you do not know the number of text messages in advance how do you know how many tuples you should use?
The number of messages you have is the same as the number of indexes returned by the sms_messages method. But you don't need that. Make an empty array and append the tuples to it as you create them.
Code:mylist = [] for id in sms_ids: mylist.append((inb.content(id), inb.address(id)))
Code:items = [mylist] appuifw.Listbox(items,lambda:None)Edit:Code:appuifw.Listbox(items,lambda:None) SymbianError: [Errno -6] KErrArgument
Now with this code works fine!
Thanks bogdan!Code:items = [mylist[0],mylist[1]]
Last edited by ikaroweb80; 2009-05-14 at 20:28. Reason: solved.