Trying to figure out why these unexpected newlines are being printed in a simple script. All I want to do in this script is read in a file, and print the contents of each line.
The code is like this:
#!/usr/bin/python
import sys
# This script should just iterate over a file and echo the contents of each line
f=open(sys.argv[1],'r')
for line in f:
line.rstrip('\n')
print "Line 1 is: " + line
f.close()
The input file is just 2 lines:
#cat users
root
dontexist
#
When I run the script with this input file, there are extra newlines in the output:
#./test.py users
Line 1 is: root
Line 1 is: dontexist
#
What am I missing? Thanks all.