Raw Strings (I Think)

Mike Driscoll kyosohma at gmail.com
Wed Jul 23 16:11:00 EDT 2008


On Jul 24, 10:02 am, "Lanny" <la... at freshells.ch> wrote:
> I've used glob.glob to get a list of files in a directory
> and now I want to use os.system to execute one of
> those files, the problem is that python automatically
> puts a escape charater infront of the back slashes
> so the os.system gets X:\\####\\####\\ and is useless,
> I think I need to convert my string to a raw string but
> I don't know how.
>
> -- Posted on news://freenews.netfront.net - Complaints to n... at netfront.net --

This works fine for me on Windows XP.

I did this:

glob.glob(r'c:\test')

which gave me something like this:

['c:\\test\\07-24TimeSheet.xls', 'c:\\test\\accts.CSV', 'c:\\test\
\Ataris Aqu\xe1ticos #2.txt', 'c:\\test\\changes.txt', 'c:\\test\
\change_g.txt', 'c:\\test\\config.ini', 'c:\\test\\County.txt', 'c:\
\test\\county1.txt', 'c:\\test\\ctypes-1.0.1.tar.gz', 'c:\\test\
\DAMNATUS_Soundtrack.zip', 'c:\\test\\doodad.1.12.3.doc', 'c:\\test\
\doodad.1.32.3.doc', 'c:\\test\\doodad.22.12.3.doc', 'c:\\test\
\emailMess.xml', 'c:\\test\\Eula.txt', 'c:\\test\\fasta.txt', 'c:\\test
\\Funds.txt', 'c:\\test\\Funds2.txt', 'c:\\test\\Gmane.newsrc', 'c:\
\test\\groups.ini', 'c:\\test\\hammy.doc']

Now, if I use os.system like this, it works:

os.system('notepad %s' % x[1])

This opens notepad with my *.csv file just fine. Windows XP, Python
2.5.2.

Mike



More information about the Python-list mailing list