Launch file in Notepad

Brian van den Broek bvande at po-box.mcgill.ca
Thu May 12 09:54:44 EDT 2005


George said unto the world upon 2005-05-12 09:41:
> Newbie question:
> 
> I'm trying to lauch Notepad from Python to open a textfile:
> 
> import os
> b1="c:\test.txt"
> os.system('notepad.exe ' + b1)
> 
> However, the t of test is escaped by the \, resulting in Notepad trying 
> to open "c: est.txt".
> 
> How do I solve this?

There are several ways, but the preferred solution is to switch the 
slash direction: "c:/test.txt". Python's smart enough to notice its 
running on Windows and do the right thing with the slash. (Other 
choice include using raw strings: r"c:\test.txt", and explicitly 
escaping the backslash: "c:\\test.txt".)

Best,

Brian vdB




More information about the Python-list mailing list