f.write vs print >> f

print does things file.write doesn’t, allowing you to skip string formatting for some basic things.

It inserts spaces between arguments and appends the line terminator.

print "a", "b" # prints something like "a b\n"

It calls the __str__ or __repr__ special methods of an object to convert it to a string.

print 1 # prints something like "1\n"

You would have to manually do these things if you used file.write instead of print.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)