Paul McNett wrote:
> Brian Snipes wrote:
>
>> I am trying to learn the Dabo and Python by doing small apps. I was
>> asked by a user yesterday how to get a list of files from a network dir
>> into csv ( just used 'dir' and redirected output to text file ). I
>> thought, "Hmm... this would make a good small Dabo app. Popup file
>> chooser, pull list of files, save to text file. Simple." So, here I go
>> making it happen and run into the first issue: I can pull choose the
>> folder and get a list of the files but they are apparently in unicode ?
>> I put the file list as output to a textbox and here is what it looks
>> like (partial):
>>
>> [u'[', u'u', u"'", u'[', u"'", u',', u' ', u'u', u"'", u'u', u"'", u',',
>> u' ', u'u', u'"', u"'", u'"', u',', u' ', u'u', u"'", u'[', u"'", u',',
>> u' ', u'u', u'"', u"'", u'"', u',', u' ', u'u', u"'", u',', u"'", u',',
>> u' ', u'u', u"'", u' ', u"'", u',', u' ', u'u', u"'", u'u', u"'", u',',
>> u' ', u'u', u'"', u"'", u'"', u',', u' ', u'u', u"'", u'u', u"'", u',',
>> u' ', u'u', u'"', u"'", u'"', u',', u' ', u'u', u"'", u',', u"'", u',',
>> u' ', u'u', u"'", u' ', u"'", u',', u' ', u'u', u"'", u'u', u"'", u',',
>> u' ', u'u', u"'", u'"', u"'", u',', u' ', u'u', u'"', u"'", u'"', u',',
>> u' ', u'u', u"'", u'"', u"'", u',', u' ', u'u', u"'", u',', u"'", u',',
>> u' ', u'u', u"'", u' ', u"'", u',', u' ', u'u', u"'", u'u', u"'", u',',
>> u' ', u'u', u'"', u"'", u'"', u',', u' ', u'u', u"'", u' ', u"'", u',',
>> u' ', u'u', u'"', u"'", u'"', u',', u' ', u'u', u"'", u',', u"'", u',',
>> u' ', u'u', u"'", u' ', u"'", u',', u' ', u'u', u"'", u'u', u"'", u',',
>> u' ', u'u', u'"', u"'", u'"', u',', u' ', u'u', u"'", u'D', u"'", u',',
>> u' ', u'u', u'"', u"'", u'"', u',', u' ', u'u', u"'", u',', u"'", u',',
>> u' ', u'u', u"'", u' ', u"'", u',', u' ', u'u', u"'", u'u', u"'", u',',
>> u' ', u'u', u'"', u"'", u'"', u',', u' ', u'u', u"'", u'a', u"'", u',',
>> u' ', u'u', u'"', u"'", u'"', u',', u' ', u'u', u"'", u',', u"'", u',',
>> u' ', u'u', u"'", u' ', u"'", u',', u' ', u'u', u"'",
>>
>> Here is my onHit for the Choose Path button:
>>
>> def onHit(self, evt):
>> import os
>> fpath = dabo.ui.getFolder(message="Choose a folder", defaultPath="",
>> wildcard="*")
>> self.Form.lblPath.Caption = fpath
>> if fpath:
>> fdlist = os.listdir(fpath)
>> fdlist.sort()
>> flist = [ elem for elem in fdlist if os.path.isfile(elem) ]
>> self.Form.txtBox.Value = flist
>>
>> How can I get this into a format that is usable to me?
>>
>
> I don't know what is going on with your output. Try this test:
>
> import os
> import dabo
> dabo.ui.loadUI("wx")
>
> app = dabo.dApp(MainFormClass=None)
> app.setup()
>
> fpath = dabo.ui.getFolder(message="Choose a folder", defaultPath="",
> wildcard="*")
> print fpath
> if fpath:
> fdlist = os.listdir(fpath)
> fdlist.sort()
> flist = [ elem for elem in fdlist if os.path.isfile(elem) ]
> print flist
>
> Yes, they are unicode strings, but the output is recognizable. I picked
> /home/pmcnett:
>
> [EMAIL PROTECTED]:~$ python test.py
> Dabo Info Log: Tue Nov 14 21:27:57 2006: 0 database connection
> definition(s) loaded.
> Dabo Info Log: Tue Nov 14 21:27:57 2006: User interface already set to
> 'wx', so dApp didn't touch it.
> Dabo Info Log: Tue Nov 14 21:27:57 2006: wxPython Version: 2.6.3.3 wxGTK
> (unicode) (gtk2)
> /home/pmcnett
> [u'.ICEauthority', u'.Xauthority', u'.bash_aliases', u'.bash_history',
> u'.bash_logout', u'.bash_profile', u'.bashrc', u'.dmrc', u'.esd_auth',
> u'.fonts.cache-1', u'.fonts.conf', u'.gksu.lock', u'.gtkrc-1.2-gnome2',
> u'.lesshst', u'.recently-used', u'.recently-used.xbel',
> u'.sudo_as_admin_successful', u'.viminfo', u'.vimrc',
> u'.xsession-errors', u'dabo.pth', u'dmp32.reg', u'dmp32.zip',
> u'test.py', u'test.py~', u'testCancelButton.py',
> u'testCancelButton.py~', u'wx.pth', u'xfer.zip']
>
>
>
Tried that and it looked fine. I think I've found the problem and
solution. I was using a TextBox control for the output and should have
been using an EditBox. The TextBox accepted a list and put it into the
format that I pasted. The EditBox puts on the console "Error message:
String or Unicode type required" which led me to converting it to string
and I will split and use os.path.join with the elements to get the list
I really need.
Thanks for the guidance.
Brian
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users