Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Percent sign at the end of the output of python script [closed]

Why is a percent sign at the end of the output of the python script?

$ echo "TEST TEST" | trim
TESTTEST%

#!/usr/bin/env python
import sys

if __name__ == "__main__":
    for line in sys.stdin:
        sys.stdout.write(''.join(line.split()))
like image 340
user2502106 Avatar asked Oct 18 '25 19:10

user2502106


1 Answers

The % you see there might actually be your shell prompt, and not part of your program output. You're not writing a new line after your output, so the shell prompt appears at the very end of the output of the last command.

Possible solutions:

  1. Use print instead of sys.stdout.write
  2. Append a newline to the end of the output with + "\n"
  3. Add a print() to the end of your program
like image 143
Greg Hewgill Avatar answered Oct 20 '25 13:10

Greg Hewgill



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!