I am retrieving a file through the below command:
fileName = os.popen('ls -t testfile.txt |head -n1').read()
while printing fileName
, I see n
appended.
I know we can remove n
through replace command, but I want to know why this is happening.
Advertisement
Answer
It is the ls command that append a new-line character to the output, you can figure it out opening a terminal and executing the command you want to run by popen