I am working through Learn Python the Hard Way using Power Shell and NotePad++.
I have gotten to the part where I am using .readline()
and I noticed the first character of the first argument in my function gets deleted or overwritten with a space. I know there already is a question that sort of seems to answer this question (Python .readline()) but as I am completely new to Python and Powershell I have no idea how to fiddle around and change settings in either of the two.
The script I wrote to execute (called new 1.py
) goes like this:
from sys import argv
script, input_filename = argv
def foo (arg1,arg2,arg3):
print arg1,arg2,arg3.readline()
def bar (arg1, arg2, arg3):
print arg2,arg1,arg3.readline()
open_input_file=open(input_filename)
foo ("Text1",1,open_input_file)
foo ("Text2",2,open_input_file)
bar ("Text3",3,open_input_file)
bar ("Text4","4",open_input_file)
With a test1.py
file containing the text:
Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
My output was as follows:
$ python "new 1.py" test1.py
ext1 1 ☐ Line 1
ext2 2 Line 2
Text3 Line 3
Text4 Line 4
The output that I expected is:
$ python "new 1.py" test1.py
Text1 1 Line 1
Text2 2 Line 2
3 Text3 Line 3
4 Text4 Line 4
Could someone please explain how to get .readline()
to read the line without erasing or overwriting the first character (with a space)? And why is there a white box in front of the capital L
in the output?