Python Regex Script sort and print to new document -
so trying write code scan .txt file bunch of jumble in between ids. want find specific strings, create new line before them, , print new document. currently, code looks this:
from__future__import print_function import re ndoc = raw_input("enter name of new document")".txt" log = open("c:python27\ndoc.txt", 'w') file = raw_input("enter file sorted") xfile = open(file) line in xfile: l=line.strip() n=re.sub("(\b)(?=((mth|eng|scn|hst)[|]))","\n",line) if len(n) > 0: nl=split.("\n") item in nl: print(item)
when run this, eroor [errno2] no such file or directory: 'xxx' xxx = whatever input variable "file."
i'm not sure cause pretty sure entering files in directory.
also, on side note, code create new file , print open('filename', 'w') line?
you have ".txt"
trows error syntaxerror: invalid syntax
should use +".txt"
. same file
variable.
>>> ndoc = raw_input("enter name of new document")".txt" syntaxerror: invalid syntax >>> ndoc = raw_input("enter name of new document") + ".txt" enter name of new documentsomefile >>> ndoc 'somefile.txt' >>>
Comments
Post a Comment