Input evaluates the input string that the user enters, which you don't want here. Try using raw_input. mike ------------------- >From the docs:
input([prompt]) Equivalent to eval(raw_input(prompt)). Warning: This function is not safe from user errors! It expects a valid Python expression as input; if the input is not syntactically valid, a SyntaxError will be raised. Other exceptions may be raised if there is an error during evaluation. (On the other hand, sometimes this is exactly what you need when writing a quick script for expert use.) If the readline module was loaded, then input() will use it to provide elaborate line editing and history features. Consider using the raw_input() function for general input from users. -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of Tom Churm Sent: Monday, April 08, 2002 8:58 AM To: [EMAIL PROTECTED]; [EMAIL PROTECTED]; [EMAIL PROTECTED] 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 [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs _______________________________________________ ActivePython mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs