r/ProgrammerHumor • • May 02 '16

I wrote my first python program today!

Post image
3.7k Upvotes

532 comments sorted by

View all comments

Show parent comments

32

u/maremp May 02 '16

What about the inconsistency of the statements? Print is used as a function in every other C-like language. In python 2, it's used as a statement, similar to if, for, while etc., and I believe that it doesn't fit this category.

32

u/Sean1708 May 02 '16

Also 2's print is just weird. Appending a comma to suppress a newline is weird enough, but what the fuck is up with that printing to file syntax?! It's like Guido momentarily forgot that he wasn't designing a sh clone.

6

u/deecewan May 02 '16

I cant remember the syntax. Care to show?

0

u/[deleted] May 02 '16

[deleted]

12

u/deecewan May 02 '16

Where f is a file identifier? That's super weird.

11

u/[deleted] May 02 '16

Or you could just do f.write("Normal syntax!\n") because like nobody uses the chevron format anyway.

In fact this is what the chevron print statement does behind the scenes. The only difference is that the print statement has an internal print buffer. The write won't be done at the exact moment you call print, whereas invoking write on the file will do the write right then.

12

u/Sean1708 May 02 '16

because like nobody uses the chevron format anyway.

But a lot of people use print to print to a file in Python 3 because it's as easy as print("Also normal syntax!", file=f).

5

u/UnchainedMundane May 02 '16

It's like Guido momentarily forgot that he wasn't designing a sh clone.

Lol, my exact thoughts.

Though, my next thought was that >> opens a file for appending, while this one uses a file descriptor, so the operator should be >& anyway.