David
David

Reputation: 223

Meaning of >> in print statement

I was wondering what does print >> dbfile, key mean in python. What is the >> supposed to do?

Upvotes: 17

Views: 3619

Answers (3)

Josh Lee
Josh Lee

Reputation: 177895

See “The print statement” in the Python language reference. The object indicated must have a write method.

Upvotes: 1

Greg Hewgill
Greg Hewgill

Reputation: 994897

It should be noted that the >> syntax is specific to Python 2.x. In Python 3.x, that syntax goes away and code needs to be changed as follows:

print >>f, "Hello world"           # Python 2.x

print("Hello world", file=f)       # Python 3.x

Upvotes: 16

James
James

Reputation: 25553

This redirects print to a file (in this case, dbfile).

the >> is just a special syntax used for this.

Upvotes: 9

Related Questions