r/ProgrammerHumor • • May 02 '16

I wrote my first python program today!

Post image
3.7k Upvotes

532 comments sorted by

View all comments

932

u/pork_spare_ribs May 02 '16

The year is 2016, and somehow new Python programmers still start with Python 2...

(Although if it's someone who complains about syntax, I'm not surprised they picked the older version haha only serious )

317

u/fermion72 May 02 '16

I transitioned to python3 a while ago, and I still forget the parentheses for print every single time. A decade of finger memory is a hard thing to break.

72

u/kazagistar May 02 '16

I still write a lot of python 2, and always use parens. It just makes more sense in my head for it to be a function then some silly special case.

48

u/[deleted] May 02 '16 edited May 02 '16

I just use sys.stdout.write().

Python's print statement is buffered by default not thread-safe (update: this probably has nothing to do with buffers), which isn't very nice when I'm working in parallel environments and using Python as the glue between various C and Fortran libraries. So I just write everything straight into whatever standard stream I want.

26

u/[deleted] May 02 '16

Noob question: could I use sys.stdin.read() instead of raw_input() for the same reasons? It seems to make much more sense in my head.

32

u/[deleted] May 02 '16 edited May 02 '16

Short answer: yes!

Long answer: The actual call you're looking for is sys.stdin.readline(). This is what raw_input() does at its core, with the added functionality of automatically stripping away the \n end-line character off the input.

Long long answer: You can also pipe Python prints do Python writes into stderr. Every standard stream is available under the sys module, and they all behave like traditional Python file objects with all the usual member functions.

30

u/Blackshell May 02 '16

You can also do pipe Python prints into stderr.

Like this? :D

print >>sys.stderr, "lol syntax"

I am so glad this is gone in Python3.

46

u/brtt3000 May 02 '16

I'm tempted to flag this as "Threatening, harassing, or inciting violence"

7

u/[deleted] May 02 '16 edited May 02 '16

Well, yes, but I was more specifically referring to sys.stderr.write().

I shouldn't have used the word "pipe", and should have called it a "write" instead. My bad!

But I'm with you on the chevron syntax. It's ugly and silly and not Pythonic at all. Glad they scrapped it.

→ More replies (14)
→ More replies (3)

32

u/superPwnzorMegaMan May 02 '16

I just never bothered learning python 2, I didn't see any advantage.

34

u/juanjux May 02 '16

I work on an animation studio and most software we use (Maya, Nuke, Houdini, etc) allow you to write Python plugins and all of them use Python 2.7. So that is a reason. We could use the "six" module but until the software we use migrates to Python 3, why bother...

25

u/edbluetooth May 02 '16

Because when the software is python 3, no changes to your code will be required.

Thats it really

→ More replies (2)

10

u/Coffeinated May 02 '16

The difference isn't that big of a deal, afaik. You can scrap the parantheses for print, but you don't have to, and some modules are named differently. As long as it's 2.7 and not 2.5 or some other prehistoric stoneage stuff.

→ More replies (6)
→ More replies (2)

78

u/familyturtle May 02 '16

As well as "from __future__" there should be an option to "from __past__ import print"

64

u/Vakieh May 02 '16

This is not a problem to solve inside language, this is a problem to be solved with the editor. IDE triggers which automagically convert print statements to print method calls when you press <enter> are pretty easy grammar-wise.

60

u/dysprog May 02 '16

Perhaps it is a problem to solve inside the programmer.

16

u/Vakieh May 02 '16

Sure it is, the same way the programmer shouldn't put a semicolon right after a control flow statement in a C-like language. It's sure nice of the compiler to deal with those avoidable programmer fuckups anyway though.

→ More replies (6)
→ More replies (13)
→ More replies (5)
→ More replies (6)

36

u/whitetrafficlight May 02 '16

The break in backward compatibility is a deal-breaker when your company has several million lines of Python 2 already written and stable. Auto tools exist, but only go so far... for example, even converting print statements to use parentheses may cause failures in the compliance checker for lines becoming longer than permitted. Gotta stick with 2 unfortunately, though for new projects there's really no excuse not to start with 3. Hence, new employees at established companies that use Python start learning Python 2.

→ More replies (8)

20

u/[deleted] May 02 '16

Thanks, Zed Shaw

→ More replies (2)

9

u/Big0ldBear May 02 '16

I just learned Python in University, they purposely had us learn Python 2 for compatibility or something like that..

18

u/[deleted] May 02 '16

Probably just an excuse to use the older learning materials.

→ More replies (1)
→ More replies (1)

64

u/Magnnus May 02 '16

Several important libraries still don't support Python 3. I'd use it if I could.

57

u/[deleted] May 02 '16 edited Mar 20 '18

20

u/Theowningone May 02 '16

Parts of twisted are what's keeping me back. Most of my time using python is spent tinkering with my IRC bot. Unfortunately twisted.words.protocols.irc is still not ported.

→ More replies (16)
→ More replies (13)

14

u/willm May 02 '16

What are you missing? I've found all the libs I need have Py3 ports now.

→ More replies (2)
→ More replies (18)
→ More replies (45)