×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    22

    add file from glob to listbox

    hi guys, very quick question.

    how can i add files from a glob command to a listbox?

    Code:
    fileList = []
    
    os.chdir("c:\\Nokia\\Images")
    for file in glob.glob("*.jpg"):
    	fileList.append(file)
    
    listbox = appuifw.Listbox(fileList, file_handler)
    this is the code. when i run it, i get an error saying the argument is of the wrong type. if i put a random string in fileList and comment out the append, then it displays fine.

    i thought glob gave out a list of filenames as strings, so why doesn't this work?

    many thanks

    docGroup14

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    386

    Re: add file from glob to listbox

    Listbox requires that the strings you're giving to it are unicode. This should fix it:

    Code:
    listbox = appuifw.Listbox(map(unicode, fileList), file_handler)
    -- ADDED --

    I'm not sure now but glob probably returns the filenames encoded with utf-8. That means that you will get errors with the above code if the filenames contain non ascii charcters like umlauts.

    In this case, this will be better:

    Code:
    listbox = appuifw.Listbox([x.decode('utf8') for x in fileList], file_handler)

  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    22

    Re: add file from glob to listbox

    thanks very much for the help mate.

    why is it that although it is encoded as utf-8, it cannot be displayed?

    if i use decode will i then get unicode?

    and im guessing map(unicode, fileList) will convert all fileList items into unicode?

    thanks for the help again, am desperately trying to get my head around the quirks of python!

    docGroup14

Similar Threads

  1. Replies: 5
    Last Post: 2008-06-03, 06:32
  2. Problem to add data into .mmp file in carbide
    By ankushbabrekar in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 3
    Last Post: 2007-02-03, 11:46
  3. Problem when trying to add a JAR file to a MIDP project
    By mcvicara in forum Mobile Java Tools & SDKs
    Replies: 0
    Last Post: 2007-01-09, 12:43
  4. ListBox Errors
    By javadi82 in forum Symbian User Interface
    Replies: 7
    Last Post: 2006-11-08, 13:29
  5. ListBox and resource file
    By tplinet in forum Symbian User Interface
    Replies: 1
    Last Post: 2003-04-02, 16:12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×