Launch file in Notepad

Brian van den Broek bvande at po-box.mcgill.ca
Thu May 12 18:20:13 EDT 2005


Fredrik Lundh said unto the world upon 2005-05-12 13:52:
> Brian van den Broek wrote:
> 
> 
>>>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.
> 
> 
> that's slightly misleading: on the API level, most functions can handle
> both kinds of slashes.  functions like open(), os.remove(), shutil.copy()
> etc. handles either case just fine.  and in most cases, this is handled
> on the Win API level (or in the C library), not by Python.
> 
> however, in this case, the user passes a string to os.system().  that
> string is passed *as is* to the command shell (which, in this case,
> passes it on to notepad.exe as is).
> 
> </F>

Thanks to Fredrik and everyone else who contributed to the thread to 
correct my mistake.

Best to all,

Brian vdB




More information about the Python-list mailing list