[Tutor] Convert my .bat and .vbs to .py

Mark Bystry mabystry at verizon.net
Thu Feb 15 21:10:00 CET 2007


Ahh. Great tip Eric. Thank-you.

Mark


Eric Walstad wrote the following on 2/15/2007 2:58 PM:
> Hey Mark,
> Mark Bystry wrote:
>> sh.copy('C:\testing_it.txt', 'D:\')
> 
> Also have a look at the os.path module.  Because you want these scripts
> to work on both Linux and Windows, using os.path will let you avoid
> writing platform specific code to handle your slashes.
> 
> For example:
> import os
> path_parts_list = ['C:', 'testing_it.txt']
> 
> Now, os.path.join will join those path parts together with whatever is
> appropriate for the OS you are running on:
> 
> os.path.join(path_parts_list)
> 
> This should give you:
> 'c:\testing_it.txt' on Windows and
> 'c:/testing_it.txt' on Linux (which doesn't make sense, but demonstrates
> how os.path can handle your os-specific slashes for you).
> 
> There are lots of helpful path related built-ins:
> <http://docs.python.org/lib/module-os.path.html>
> 


More information about the Tutor mailing list