View Single Post
Posts: 161 | Thanked: 85 times | Joined on Feb 2010
#16
yay!!

again there were typos in the wiki:
Code:
dir_name = "src"

for root, dirs, files in os.walk(dir_name):
        real_dir = root[len(dir_name):]
For who left only "src", the code should look like:
Code:
dir_name = "src"
for root, dirs, files in os.walk(dir_name):
        real_dir = root
what was going on? simply string stripping: root[len(dir_name):] means that you're doing root[3:]. you want to strip the string from the 3rd position to the end: example:
Code:
 a="src"
In [13]: len(a)
Out[13]: 3
In [14]: cacca=[1,2,3,4,5,6,7]
In [15]: cacca[len(a):]
Out[15]: [4, 5, 6, 7]
In [16]: cacca[:len(a)]
Out[16]: [1, 2, 3]
.

final remarks: this is what was meant to be:
Code:
for root, dirs, files in os.walk(dir_name):
        real_dir ="//" + root[len(dir_name):]
the double slashes are also required to fix the pathname.
so I will edit again the wiki. solving this other one.
hope I've help someone in saving time.

Last edited by erniadeldesktop; 2010-09-24 at 18:29. Reason: more fixes
 

The Following User Says Thank You to erniadeldesktop For This Useful Post: