[Tutor] RE: why do i need to surround file names in inputs with quotes?

Joseph Youngquist jyoungqu@journal-courier.com
Mon, 8 Apr 2002 13:27:32 -0400


I'm a newbi too, but I think I read that input is for integers and rawinput
is for strings...might help

Joe Youngquist

-----Original Message-----
From: activepython-admin@listserv.ActiveState.com
[mailto:activepython-admin@listserv.ActiveState.com]On Behalf Of Tom
Churm
Sent: Monday, April 08, 2002 10:57 AM
To: python-help@python.org; activepython@listserv.ActiveState.com;
tutor@python.org
Subject: why do i need to surround file names in inputs with quotes?


hi,

i've found & adapted the following simple python script that copies one text
file to another text file.  the script works o.k., but only when i enter the
name of the text file (both original, and the name of the new text file)
surrounded by "double quotes".

i don't understand why this is.  and worse, i don't know how to change the
script so that the filenames inserted by the user no longer require these
double quotes.

this should be a real easy one, but, being a python newbie, i'd appreciate
any suggestions.

copyText2Text.py follows:
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
import os
thecwd = os.getcwd()
print ""
print "Python Text File Copier"
print ""
print "Current Working Directory: "+thecwd
a = input('Type name of file to copy surrounded by doublequotes')
b = input('Type name of new file surrounded by doublequotes')

#this was my attempt to add the double quotes automatically to the
#names given by the users' input - but it doesn't work!
#is this just a matter of knowing the proper escape characters??
#a = ""+a+""
#b = ""+b+""

fullfile1 = thecwd+"\\"+a

inp = open(fullfile1,"r")

fullfile2 = thecwd+"\\"+b

outp = open(fullfile2,"w")
for line in inp.readlines():
    outp.write(line)
print "Text file '"+fullfile1+"' copied successfully"
print "to"
print fullfile2
inp.close()
outp.close()

_________________________________________________________________
MSN Photos is the easiest way to share and print your photos:
http://photos.msn.com/support/worldwide.aspx

_______________________________________________
ActivePython mailing list
ActivePython@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs