I have this trivial code:
from sys import argv
script, input_file = argv
def fma(f):
f.readline()
current_file = open(input_file)
fma(current_file)
The contents of the txt file is:
Hello this is a test.\n
I like cheese and macaroni.\n
I love to drink juice.\n
\n
\n
I put the \n chars so you know I hit enter in my text editor.
What I want to accomplish is to get back every single line and every \n character.
The problem is, when running the script I get nothing back. What am I doing wrong and how can I fix it in order to run as I stated above?
Pretty certain what you actually want is f.readlines, not f.readline.
Note that I am using the with context manager to open your file more efficiently (it does the job of closing the file for you). In Python 2.6 and later you don’t need the fancy import statement at the top to use it, but I have a habit of including it for anyone still using older Python.