On 04Sep2014 15:01, Joel Goldstick <[email protected]> wrote:
On Thu, Sep 4, 2014 at 8:49 AM, Felisha Lawrence
<[email protected]> wrote:
I have a question regarding strings in python. I have a directory on my
MacBook Bro of about 13 files. I need to alter the file endings in that
directory. The files are on the order of
'swp.113006004000_KLWX_0.0.5_PPI_v2','swp.113006004000_KLWX_0.0.5_PPI_v3'. I
need to remove the characters after the 'v' and replace with v20. All of the
endings of the files are sequential _v2, _v3,_v4, _v5. I need all of these
characters to be the same (i.e. v20). I would like to know which modules are
best to use, and how to use loops to alter them. Any help you can provide
would be great.
Check out the documentation for os.walk and os.rename. The first to
collect you filenames, and the second to rename them.
os.listdir will be far easier than os.walk if it is a single flat directory.
Cheers,
Cameron Simpson <[email protected]>
Knox's box is a 286. Fox in Socks does hacks and tricks
Knox's box is hard to fix. To fix poor Knox's box for kicks.
- David Mar <[email protected]>,
as quoted by John Mackin <[email protected]>
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor