Q:

How to avoid printing a new line when the database is empty?

I have an SQL query; when it executes and the database is empty, it gives an empty(), and it prints a new line even after stripping \r,\n.
How can I prevent this?
# Prepare SQL query to get the gerrits from the database.
sql_get = """SELECT gerrit_id
            FROM gerrits.gerrit_submit_table
            where (SI='%s'
            and component='%s' and release_bit = '0' and picked_bit = '0')"""%(SI,component)

#print sql_get
rows = cursor.execute(sql_get)  
gerrits = cursor.fetchall() 
print "gerrits"
print gerrits -->prints ()

print' '.join(item[0] for item in gerrits).rstrip('\r\n') --> #prints a new line even after stripping \r\n

A:

print by itself prints a new line. You can instead see if the line is empty before even calling print
Ex.
if gerrits:
    print ' '.join(item[0] for item in gerrits)

This will only print when gerrits contains data to be printed. Otherwise nothing is printed.
OR
End the print statement with a comma to skip it printing a newline
Ex. 
print 'my text to print',

