Control line ending of Print in Python
Question: I've read elsewhere that I can prevent print from going to the next line by
adding a "," to the end of the statement. However, is there a way to control
this conditionally? To sometimes end the line and sometimes not based on
variables?


Answer: One solution without future imports:

    
    
    print "my line of text",
    if print_newline:
        print
    

which is equivalent to:

    
    
    from __future__ import print_function
    print("my line of text", end="\n" if print_newline else "")
    

