[Tutor] annoying directory structure
Dave Angel
davea at davea.name
Fri Apr 10 01:44:27 CEST 2015
On 04/09/2015 06:17 PM, Jim Mooney wrote:
Please put your remarks *after* whatever quoting you do, not before. In
other words, don't top-post.
> Looks like I can work it, but some walk paths are coming out as two strings
> back to back, which I know python concatenates with print, but how do I
> concatenate them without print so I can use them in my script to append to
> the mp4 filenames and have a windows readable path?. i.e., I am getting
> this sort of triplet when I go through the generator. After doing that the
> rest seems easy enough:
>
> A = ('I:\\VIDS\\Learn Python Track\\07. Regular Expressions in
> Python\\Stage '
> '1\\01. Introduction to Regular Expressions\\07. Compiling and Loops',
> [],
> ['Compiling and Loops.mp4', 'Compiling and Loops.srt'])
>
>>> A[0]
>
> ('I:\\VIDS\\Learn Python Track\\07. Regular Expressions in Python\\Stage '
> '1\\01. Introduction to Regular Expressions\\07. Compiling and Loops')
that's not what you'd get if you had done the previous two lines. So
please post some real code, and maybe you'll get some help.
>
> Still two unconcatenated strings
You didn't do anything to concatenate anything, so I'm not sure what
you're talking about.
>
> And why do I still have tuple parentheses for A[0], which should be a
> concatenated string?
>
Nonsense without context. What's your code?
If you're inside a loop on os.walk, the easiest way to make readable
code is to use implicit tuple unpacking.
See https://docs.python.org/3.4/library/os.html#os.walk
for dirpath, dirnames, filenames = os.walk( whatever ):
#Do something here with dirpath and each of the filenames
Once you have a path and a basename you need to combine, you *could* use
+ on the two strings. But it'd be much better to use os.path.join(). See
https://docs.python.org/3/library/os.path.html#os.path.join
--
DaveA
More information about the Tutor
mailing list