I’ve got a Python script that prints out a file to the shell:
print open(lPath).read()
If I pass in the path to a file with the following contents (no brackets, they’re just here so newlines are visible):
> One
> Two
>
I get the following output:
> One
> Two
>
>
Where’s that extra newline coming from? I’m running the script with bash on an Ubuntu system.
Use
printadds a newline. If you end theprintstatement with a comma, it’ll add a space instead.You can use
If you don’t need any of the special features of
print.If you switch to Python 3, or use
from __future__ import print_functionon Python 2.6+, you can use theendargument to stop theprintfunction from adding a newline.