SHARE
TWEET

fileinput - remove lines in file

furas Jul 22nd, 2018 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # keeps lines with char "a"
  2. # line has '\n' so print doesn't have to add own '\n'
  3.  
  4. import fileinput
  5.  
  6. for line in fileinput.input('test.txt', 'w'):
  7.     if 'a' in line:
  8.         print(line, end='')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top