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

Kent Johnson kent37 at tds.net
Thu Feb 15 20:32:37 CET 2007


Mark Bystry wrote:
> Well, immediately I am having problems. Be patient with me.

We will be, you're doing great so far :-)
> 
> This what I have...
> 
> copy_file.py
> ############################################
> 
> import os
> import shutil as sh
> 
> sh.copy('C:\testing_it.txt', 'D:\')

Backslash is an escape character in Python string constants. \t actually 
inserts a tab character in the string.

You have several choices:

'C:/testing_it.txt' - forward slashes work fine too
'C:\\testing_it.txt' - double the \ to make it a literal.
r'C:\testing_it.txt' - 'r' prefix makes it a 'raw' string, backslashes 
are (mostly) treated as literals rather than escapes.

Kent



More information about the Tutor mailing list