Launch file in Notepad
George
gtog at _no___spam_myrealbox.com
Thu May 12 11:10:42 EDT 2005
Bengt Richter wrote:
> On Thu, 12 May 2005 15:41:14 +0200, George <gtog at _no___spam_myrealbox.com> wrote:
>>(By the way, b1 comes from a command line parameter, so the user enters
>>c:\test.txt as command line parameter.)
>
> It should be ok then, unless you have somehow processed the command line parameter and interpreted
> the backslash as an escape. E.g., pargs.py here prints command line args and backslash is
> an ordinary string character as you see in argv[3] below. If it were a tab, you would see
> whitespace instead of the backslash.
Perhaps that's what I did (processing the command line parameter). For
some reason it works now.
> If by "command line" you mean your own programmed input, make sure you use raw_input, not input, e.g.,
I was referring to the user launching my script with a filename as
parameter:
test.py c:\test.txt
Here's my code so far (it removes blank lines from the input file (for
example c:\test.txt), and creates a new file (c:\test_new.txt) to store
the output):
import string
import sys
import os
if len(sys.argv)<=1:
print 'Usage: dbl.py [filename]'
sys.exit()
b1=sys.argv[1]
b2=b1[:-4] + '_new' + b1[-4:]
f1=open(b1,'r')
f2=open(b2,'w')
r1=f1.readlines()
for r in r1:
if string.capwords(r)<>'':
f2.write(r)
f1.close()
f2.close()
print 'Output file: ' + b2
os.system ('start notepad.exe ' + b2)
George
More information about the Python-list
mailing list