G'day all
Can anyone explain the difference in the results to me as I don't understand why specifying the directory name in two different ways could give a different answer.
In CODE 1 below i specified the directory path in the code.
In CODE 2 below i specified the directory path through a wxPython dialog.
When I run CODE 1 I get the following:
['d:\\temp,20070 512_xfer_2_CA.p df', 'd:\\temp,20070 512_xfer_2_CC.p df', 'd:\\temp,20070 512_xfer_2_EA.p df', 'd:\\temp,20070 512_xfer_
2_HL.pdf', 'd:\\temp,4', 'd:\\temp,4dad' , 'd:\\temp,aa', 'd:\\temp,acces s.en-us', 'd:\\temp,autor un.inf', 'd:\\temp,BARBI E_ISLAND_
PRINCESS.m4v', 'd:\\temp,cards 1_1(1).xls', 'd:\\temp,excel .en-us', 'd:\\temp,F-7-i386-DVD.iso', 'd:\\temp,infop ath.en-us', 'd:\\te
mp,Kristy_Tony. jpg', 'd:\\temp,mny20 08usweb.exe', 'd:\\temp,Offic e 12.nfo', 'd:\\temp,offic e.en-us', 'd:\\temp,offic e.ww', 'd:\\te
mp,osetup.dll', 'd:\\temp,OsWal k.Show.txt', 'd:\\temp,outlo ok.en-us', 'd:\\temp,PB110 027.JPG', 'd:\\temp,PB110 028.JPG', 'd:\\temp,
PB110029.JPG', 'd:\\temp,power point.en-us', 'd:\\temp,pro.w w', 'd:\\temp,ps3', 'd:\\temp,publi sher.en-us', 'd:\\temp,setup .ww', 'd
:\\temp,SIS_CD_ DVD copy.jpg', 'd:\\temp,SIS_C D_DVD.psd', 'd:\\temp,Start 32.exe', 'd:\\temp,test. txt', 'd:\\temp,Thumb s.db', 'd:\\t
emp,torrents', 'd:\\temp,WebFE ', 'd:\\temp,word. en-us', 'd:\\temp,Work' , 'd:\\temp,ZbThu mbnail.info', 'd:\\temp,[From www.metacafe
.com] 754577.4586323. 11.flv']
When I run CODE 2 I get the following: (notice the u in front of all the list items)
[u'D:\\Temp,2007 0512_xfer_2_CA. pdf', u'D:\\Temp,2007 0512_xfer_2_CC. pdf', u'D:\\Temp,2007 0512_xfer_2_EA. pdf', u'D:\\Temp,2007 0512_x
fer_2_HL.pdf', u'D:\\Temp,4', u'D:\\Temp,4dad ', u'D:\\Temp,aa', u'D:\\Temp,acce ss.en-us', u'D:\\Temp,auto run.inf', u'D:\\Temp,BARB
IE_ISLAND_PRINC ESS.m4v', u'D:\\Temp,card s1_1(1).xls', u'D:\\Temp,exce l.en-us', u'D:\\Temp,F-7-i386-DVD.iso', u'D:\\Temp,info path.e
n-us', u'D:\\Temp,Kris ty_Tony.jpg', u'D:\\Temp,mny2 008usweb.exe', u'D:\\Temp,Offi ce 12.nfo', u'D:\\Temp,offi ce.en-us', u'D:\\Temp,
office.ww', u'D:\\Temp,oset up.dll', u'D:\\Temp,OsWa lk.Show.txt', u'D:\\Temp,outl ook.en-us', u'D:\\Temp,PB11 0027.JPG', u'D:\\Temp,P
B110028.JPG', u'D:\\Temp,PB11 0029.JPG', u'D:\\Temp,powe rpoint.en-us', u'D:\\Temp,pro. ww', u'D:\\Temp,ps3' , u'D:\\Temp,publ isher.en
-us', u'D:\\Temp,setu p.ww', u'D:\\Temp,SIS_ CD_DVD copy.jpg', u'D:\\Temp,SIS_ CD_DVD.psd', u'D:\\Temp,Star t32.exe', u'D:\\Temp,test .
txt', u'D:\\Temp,Thum bs.db', u'D:\\Temp,torr ents', u'D:\\Temp,WebF E', u'D:\\Temp,word .en-us', u'D:\\Temp,Work ', u'D:\\Temp,ZbTh umb
nail.info', u'D:\\Temp,[From www.metacafe.co m] 754577.4586323. 11.flv']
CODE 1:
[CODE=python] import os
def print_tree(dir_ path):
outputList = []
for name in os.listdir(dir_ path):
outputList.appe nd(",".join([dir_path, name]))
print outputList
print_tree(r"d: \temp")
[/CODE]
CODE 2:
[CODE=python] import os
import wx
def print_tree(dir_ path):
outputList = []
for name in os.listdir(dir_ path):
outputList.appe nd(",".join([dir_path, name]))
print outputList
def dirchoose():
#'Gives the user selected path. Use: dirchoose()'
global _selectedDir , _userCancel #you should define them before
userPath = 'c:/'
app = wx.App()
dialog = wx.DirDialog(No ne, "Please choose your project directory:",\
style=1 ,defaultPath=us erPath, pos = (5,10))
if dialog.ShowModa l() == wx.ID_OK:
_selectedDir = dialog.GetPath( )
return _selectedDir
else:
app.Close()
dialog.Destroy( )
return _userCancel
print_tree(dirc hoose())
[/CODE]
Can anyone explain the difference in the results to me as I don't understand why specifying the directory name in two different ways could give a different answer.
In CODE 1 below i specified the directory path in the code.
In CODE 2 below i specified the directory path through a wxPython dialog.
When I run CODE 1 I get the following:
['d:\\temp,20070 512_xfer_2_CA.p df', 'd:\\temp,20070 512_xfer_2_CC.p df', 'd:\\temp,20070 512_xfer_2_EA.p df', 'd:\\temp,20070 512_xfer_
2_HL.pdf', 'd:\\temp,4', 'd:\\temp,4dad' , 'd:\\temp,aa', 'd:\\temp,acces s.en-us', 'd:\\temp,autor un.inf', 'd:\\temp,BARBI E_ISLAND_
PRINCESS.m4v', 'd:\\temp,cards 1_1(1).xls', 'd:\\temp,excel .en-us', 'd:\\temp,F-7-i386-DVD.iso', 'd:\\temp,infop ath.en-us', 'd:\\te
mp,Kristy_Tony. jpg', 'd:\\temp,mny20 08usweb.exe', 'd:\\temp,Offic e 12.nfo', 'd:\\temp,offic e.en-us', 'd:\\temp,offic e.ww', 'd:\\te
mp,osetup.dll', 'd:\\temp,OsWal k.Show.txt', 'd:\\temp,outlo ok.en-us', 'd:\\temp,PB110 027.JPG', 'd:\\temp,PB110 028.JPG', 'd:\\temp,
PB110029.JPG', 'd:\\temp,power point.en-us', 'd:\\temp,pro.w w', 'd:\\temp,ps3', 'd:\\temp,publi sher.en-us', 'd:\\temp,setup .ww', 'd
:\\temp,SIS_CD_ DVD copy.jpg', 'd:\\temp,SIS_C D_DVD.psd', 'd:\\temp,Start 32.exe', 'd:\\temp,test. txt', 'd:\\temp,Thumb s.db', 'd:\\t
emp,torrents', 'd:\\temp,WebFE ', 'd:\\temp,word. en-us', 'd:\\temp,Work' , 'd:\\temp,ZbThu mbnail.info', 'd:\\temp,[From www.metacafe
.com] 754577.4586323. 11.flv']
When I run CODE 2 I get the following: (notice the u in front of all the list items)
[u'D:\\Temp,2007 0512_xfer_2_CA. pdf', u'D:\\Temp,2007 0512_xfer_2_CC. pdf', u'D:\\Temp,2007 0512_xfer_2_EA. pdf', u'D:\\Temp,2007 0512_x
fer_2_HL.pdf', u'D:\\Temp,4', u'D:\\Temp,4dad ', u'D:\\Temp,aa', u'D:\\Temp,acce ss.en-us', u'D:\\Temp,auto run.inf', u'D:\\Temp,BARB
IE_ISLAND_PRINC ESS.m4v', u'D:\\Temp,card s1_1(1).xls', u'D:\\Temp,exce l.en-us', u'D:\\Temp,F-7-i386-DVD.iso', u'D:\\Temp,info path.e
n-us', u'D:\\Temp,Kris ty_Tony.jpg', u'D:\\Temp,mny2 008usweb.exe', u'D:\\Temp,Offi ce 12.nfo', u'D:\\Temp,offi ce.en-us', u'D:\\Temp,
office.ww', u'D:\\Temp,oset up.dll', u'D:\\Temp,OsWa lk.Show.txt', u'D:\\Temp,outl ook.en-us', u'D:\\Temp,PB11 0027.JPG', u'D:\\Temp,P
B110028.JPG', u'D:\\Temp,PB11 0029.JPG', u'D:\\Temp,powe rpoint.en-us', u'D:\\Temp,pro. ww', u'D:\\Temp,ps3' , u'D:\\Temp,publ isher.en
-us', u'D:\\Temp,setu p.ww', u'D:\\Temp,SIS_ CD_DVD copy.jpg', u'D:\\Temp,SIS_ CD_DVD.psd', u'D:\\Temp,Star t32.exe', u'D:\\Temp,test .
txt', u'D:\\Temp,Thum bs.db', u'D:\\Temp,torr ents', u'D:\\Temp,WebF E', u'D:\\Temp,word .en-us', u'D:\\Temp,Work ', u'D:\\Temp,ZbTh umb
nail.info', u'D:\\Temp,[From www.metacafe.co m] 754577.4586323. 11.flv']
CODE 1:
[CODE=python] import os
def print_tree(dir_ path):
outputList = []
for name in os.listdir(dir_ path):
outputList.appe nd(",".join([dir_path, name]))
print outputList
print_tree(r"d: \temp")
[/CODE]
CODE 2:
[CODE=python] import os
import wx
def print_tree(dir_ path):
outputList = []
for name in os.listdir(dir_ path):
outputList.appe nd(",".join([dir_path, name]))
print outputList
def dirchoose():
#'Gives the user selected path. Use: dirchoose()'
global _selectedDir , _userCancel #you should define them before
userPath = 'c:/'
app = wx.App()
dialog = wx.DirDialog(No ne, "Please choose your project directory:",\
style=1 ,defaultPath=us erPath, pos = (5,10))
if dialog.ShowModa l() == wx.ID_OK:
_selectedDir = dialog.GetPath( )
return _selectedDir
else:
app.Close()
dialog.Destroy( )
return _userCancel
print_tree(dirc hoose())
[/CODE]
Comment