473,224 Members | 1,624 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,224 software developers and data experts.

Can anyone explain the difference between results of append method

Eclipse
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,20070512_xfer_2_CA.pdf', 'd:\\temp,20070512_xfer_2_CC.pdf', 'd:\\temp,20070512_xfer_2_EA.pdf', 'd:\\temp,20070512_xfer_
2_HL.pdf', 'd:\\temp,4', 'd:\\temp,4dad', 'd:\\temp,aa', 'd:\\temp,access.en-us', 'd:\\temp,autorun.inf', 'd:\\temp,BARBIE_ISLAND_
PRINCESS.m4v', 'd:\\temp,cards1_1(1).xls', 'd:\\temp,excel.en-us', 'd:\\temp,F-7-i386-DVD.iso', 'd:\\temp,infopath.en-us', 'd:\\te
mp,Kristy_Tony.jpg', 'd:\\temp,mny2008usweb.exe', 'd:\\temp,Office 12.nfo', 'd:\\temp,office.en-us', 'd:\\temp,office.ww', 'd:\\te
mp,osetup.dll', 'd:\\temp,OsWalk.Show.txt', 'd:\\temp,outlook.en-us', 'd:\\temp,PB110027.JPG', 'd:\\temp,PB110028.JPG', 'd:\\temp,
PB110029.JPG', 'd:\\temp,powerpoint.en-us', 'd:\\temp,pro.ww', 'd:\\temp,ps3', 'd:\\temp,publisher.en-us', 'd:\\temp,setup.ww', 'd
:\\temp,SIS_CD_DVD copy.jpg', 'd:\\temp,SIS_CD_DVD.psd', 'd:\\temp,Start32.exe', 'd:\\temp,test.txt', 'd:\\temp,Thumbs.db', 'd:\\t
emp,torrents', 'd:\\temp,WebFE', 'd:\\temp,word.en-us', 'd:\\temp,Work', 'd:\\temp,ZbThumbnail.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,20070512_xfer_2_CA.pdf', u'D:\\Temp,20070512_xfer_2_CC.pdf', u'D:\\Temp,20070512_xfer_2_EA.pdf', u'D:\\Temp,20070512_x
fer_2_HL.pdf', u'D:\\Temp,4', u'D:\\Temp,4dad', u'D:\\Temp,aa', u'D:\\Temp,access.en-us', u'D:\\Temp,autorun.inf', u'D:\\Temp,BARB
IE_ISLAND_PRINCESS.m4v', u'D:\\Temp,cards1_1(1).xls', u'D:\\Temp,excel.en-us', u'D:\\Temp,F-7-i386-DVD.iso', u'D:\\Temp,infopath.e
n-us', u'D:\\Temp,Kristy_Tony.jpg', u'D:\\Temp,mny2008usweb.exe', u'D:\\Temp,Office 12.nfo', u'D:\\Temp,office.en-us', u'D:\\Temp,
office.ww', u'D:\\Temp,osetup.dll', u'D:\\Temp,OsWalk.Show.txt', u'D:\\Temp,outlook.en-us', u'D:\\Temp,PB110027.JPG', u'D:\\Temp,P
B110028.JPG', u'D:\\Temp,PB110029.JPG', u'D:\\Temp,powerpoint.en-us', u'D:\\Temp,pro.ww', u'D:\\Temp,ps3', u'D:\\Temp,publisher.en
-us', u'D:\\Temp,setup.ww', u'D:\\Temp,SIS_CD_DVD copy.jpg', u'D:\\Temp,SIS_CD_DVD.psd', u'D:\\Temp,Start32.exe', u'D:\\Temp,test.
txt', u'D:\\Temp,Thumbs.db', u'D:\\Temp,torrents', u'D:\\Temp,WebFE', u'D:\\Temp,word.en-us', u'D:\\Temp,Work', u'D:\\Temp,ZbThumb
nail.info', u'D:\\Temp,[From www.metacafe.com] 754577.4586323.11.flv']

CODE 1:
Expand|Select|Wrap|Line Numbers
  1.  import os 
  2. def print_tree(dir_path):
  3.   outputList = []
  4.   for name in os.listdir(dir_path):
  5.     outputList.append(",".join([dir_path, name]))
  6.     print outputList
  7. print_tree(r"d:\temp")
  8.  
CODE 2:
Expand|Select|Wrap|Line Numbers
  1.  import os
  2. import wx 
  3. def print_tree(dir_path):
  4.   outputList = []
  5.   for name in os.listdir(dir_path):
  6.     outputList.append(",".join([dir_path, name]))
  7. print outputList 
  8.  
  9. def dirchoose():
  10.   #'Gives the user selected path. Use: dirchoose()'
  11.   global _selectedDir , _userCancel #you should define them before
  12.   userPath = 'c:/'
  13.   app = wx.App()
  14.   dialog = wx.DirDialog(None, "Please choose your project directory:",\
  15.   style=1 ,defaultPath=userPath, pos = (5,10))
  16.   if dialog.ShowModal() == wx.ID_OK:
  17.     _selectedDir = dialog.GetPath()
  18.     return _selectedDir
  19.   else:
  20.     app.Close()
  21.     dialog.Destroy()
  22.     return _userCancel
  23.  
  24. print_tree(dirchoose())
  25.  
Jan 4 '08 #1
1 1988
bvdet
2,851 Expert Mod 2GB
Apparently the wx method GetPath() returns a unicode string. os.listdir() will return directory entries in unicode if passed a path in unicode. Try this:
Expand|Select|Wrap|Line Numbers
  1. print_tree(str(dirchoose()))
Jan 4 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Greg Brunet | last post by:
In doing some testing of different but simple algorithms for getting a list of prime numbers, I ended up getting some results that seem a bit contradictory. Given the following test program...
19
by: John Keeling | last post by:
Dear all, I tried the test program below. My interest is to examine timing differences between insert vs. append & reverse for a list. My results on my XP Python 2.3.4 are as follows:...
2
by: Chuck Reed | last post by:
I use ADO.Recordsets constantly to query data from external sources and append the results into tables in Access databases. A number of the queries I deal with bring back in excess of 50,000...
2
by: Mark | last post by:
I have a FE/BD 2002 DB on a XP pro platform. I know this is ugly but it works for me...... A text file is produced from our Oracle WMS. (Average 20k records) A command button deletes all records...
12
by: Tee | last post by:
String Builder & String, what's the difference. and when to use which ? Thanks.
4
by: Bruno Alexandre | last post by:
Hi guys, I'm using the asp:menu component and everything worked great in my machine, but when I upload the files to our Hosting I got this: http://portal.filterqueen.dk/portal2.fq/test.aspx ...
13
by: JohnJSal | last post by:
Can someone explain to me why the first version of this method works, but the second one doesn't? All I've changed (I think) is how the information is nested. The error I'm getting is that the call...
18
by: Jon Slaughter | last post by:
"Instead of just waiting for its time slice to expire, a thread can block each time it initiates a time-consuming activity in another thread until the activity finishes. This is better than...
5
by: Steven D'Aprano | last post by:
After reading an earlier thread about opening and closing lots of files, I thought I'd do a little experiment. Suppose you have a whole lot of files, and you need to open each one, append a...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.