Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1.  
  2. def replace_vars(fname):
  3.     try:
  4.         f = open(fname,'r')
  5.         new_lines = []
  6.         for line in f:
  7.             line_word = []
  8.             word = line.split()
  9.             for w in word:
  10.                 w = w.strip()
  11.                 if w.startswith('?'):
  12.                     w = w[1:]
  13.                     w = w.replace('_', ' ')
  14.                     if w[-1].isalpha == False:
  15.                         punc = w[-1]
  16.                         w = raw_input("Give me a " + w[:-1] + ":")
  17.                         w += punc
  18.                     else:
  19.                         w = raw_input("Give me a " + w + ":")
  20.                    
  21.                 line_word.append(w)
  22.             new_lines.append(line_word)
  23.         for line in new_lines:
  24.             for word in line:
  25.                 print word + " ",
  26.             print '\n',
  27.            
  28.     except IOError:
  29.         print "I could not find a file name" + fname
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement