append - Python - Opening a Text File and Appending Lines via raw_input -
append - Python - Opening a Text File and Appending Lines via raw_input -
i'm trying add together on code can append lines text file via user input. have far:
from sys import argv os.path import exists print "let's read , write file now!" raw_input ("press come in when ready proceed...") script, from_file, to_file = argv print "let's re-create 1 file , set file!" print "i'm going re-create %s %s!" % (from_file, to_file) in_file = open(from_file) indata = in_file.read() print "the input file picked %d bytes long, cool huh?" % len(indata) print "does output file trying create exist? %r" % exists(to_file) print "ready, nail homecoming continue, ctrl-c or command+c abort." raw_input("press come in when ready proceed...") print "are sure want continue?... blow world up. ctrl-c or command+c abort." raw_input("press come in when ready proceed...") print "last chance... want risk doing off human race?... ctrl-c or command+c abort." raw_input("press come in when ready proceed...") print "alright! i'm doing it!" out_file = open(to_file, 'w') out_file.write(indata) print "oh... still alive. well, have fun new file!" out_file.close() in_file.close() print "let's seek , append line new copied file!" raw_input("press come in when ready proceed...") print "type in file path file want edit!: " filename = raw_input(">") open(filename, "a") myfile: myfile.write(raw_input())
when asked me file path, type (on mac):
/users/ross/desktop/school/intro\ to\ python/lab5/readcopy.txt
it returns me this:
traceback (most recent phone call last): file "/users/ross/desktop/school/intro python/lab5/readcopy.py", line 43, in <module> open(filename, "a") myfile: ioerror: [errno 2] no such file or directory: '/users/ross/desktop/school/intro\\ to\\ python/lab5/readcopy.txt '
any input how can this? also, code right in wanting add together new lines user input?
thanks.
the backslashes not part of filename. rather, exist solely escape characters otherwise meaningful, in case shell. raw_input
not need escaping.
just come in /users/ross/desktop/school/intro python/lab5/readcopy.txt
, or improve utilize relative path.
python append raw-input
Comments
Post a Comment