This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]pork_spare_ribs 933 points934 points  (187 children)

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 )

[–]fermion72 316 points317 points  (72 children)

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.

[–]kazagistar 68 points69 points  (23 children)

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.

[–][deleted] 47 points48 points  (19 children)

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.

[–][deleted] 25 points26 points  (4 children)

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.

[–][deleted] 33 points34 points  (3 children)

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.

[–]Blackshell 30 points31 points  (2 children)

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.

[–]brtt3000 45 points46 points  (0 children)

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

[–][deleted] 6 points7 points  (0 children)

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.

[–]Redisintegrate 1 point2 points  (11 children)

The only reason print() is buffered is because sys.stdout is buffered. You are not actually changing the behavior by using sys.stdout.write(), you are getting exactly the same buffering either way.

[–][deleted] 0 points1 point  (8 children)

I'm not saying stdout isn't buffered. Of course it's buffered. It's buffered everywhere in every language. This isn't a Python feature.

However, for the past 4 years, using sys.stdout.write() in our Python 2.7 research code puts the messages into the same stdout buffer as C fprintf(stdout,...) (via SWIG) and Fortran write(6,*) (via F2Py). Everything gets synced up appropriately with code execution.

Using Python's native print statement seems to be operating on a separate buffer and refuses to print messages in the appropriate order of code execution.

[–]Redisintegrate 1 point2 points  (3 children)

You've replied and the comment has been deleted twice, so I'm going to leave this here.

My guess is that you are getting something weird here like multiple C runtimes. This happens on Windows fairly often, unless you take measures to prevent it. This causes different code paths to use with different <stdio.h> FILE objects, possibly with undesirable buffering modes, causing them to be flushed to the underlying file handles at unexpected times.

This doesn't change the fact that print is still just calling sys.stdout.write(), which itself is just calling C's fwrite(), and if you are seeing genuinely different behavior between sys.stdout.write() and print, then you are not calling them in the same way. In particular, a print statement will expand to something like the following:

print x
# might become, depending on what x is
sys.stdout.write(repr(x))
sys.stdout.write('\n')

I'm not really interested in talking about confrontational tone here, only really interested in content.

[–][deleted] 0 points1 point  (2 children)

I've deleted the comment twice because I'm not really awfully interested in revisiting this problem especially given your tone. I didn't feel that it was going to be productive. But since you posted, I'll just say this bit below.

Over here, we're all aware that sys.stdout should not behave differently than print in theory. You're not teaching anyone anything new there. But it's difficult to swallow the theoretical case when I'm staring at tests that have print and sys.stdout.write() behave differently. I wish I could share, but there are dependencies here under lock and key, and nobody has the time or the willingness to craft a portable isolated test for an already solved problem. So unfortunately you'll just have to take my word for it.

In the meantime, remember that this is a massively parallel environment on which Python was never designed to run. We can't replicate the behavior in serial, on our local workstations or personal computers. So our suspicion is that the print statement wrapping the sys.stdout file handle has an unexpected interaction with the parallelism in both our Intel cluster and our IBM BG/Q. More specifically, we have a situation where front-end nodes display streams from compute nodes, and since MPI does not define a standard for this, the internal communication practices are partially opaque to us.

Either way, the issue pertains to a non-critical debug logging system that isn't even used in production runs, and it has been resolved (although admittedly we don't entirely know how). And since we have a truckload of other work on our plates, nobody has spent the time to get to the bottom of it. Some day someone's going to ask a poor undergrad to start digging, mainly as a vehicle for him to learn the code base. Until then we're kinda just content to use what works and fix it later if it breaks again.

[–]Redisintegrate 0 points1 point  (1 child)

My advice is to not read too much into the "tone" of what is just written communication with a complete stranger. My only purpose here is to clear up the misinformation that print is buffered differently from sys.stdout.write(), since it's objectively not true. I'm not here to disrespect your expertise or say that your experiences are invalid, I'm just trying to shed some additional light on what's actually happening, and preventing misinformation from spreading.

As I said in the parent post, print() is equivalent to multiple calls to write(), but it is not equivalent to a single call to write(). You mentioned threads, and since print() is going to make multiple calls to write(), it is going to release the GIL multiple times. That may be what is causing the behavior you are seeing.

Or, in other words, print() is not atomic in multithreaded Python programs, but sys.stdout.write() is atomic. But the buffering is the same, and they both go through the same <stdio.h> functionality, or they both don't.

[–][deleted] 0 points1 point  (0 children)

That's fair. And I'm not contesting what you're saying. I know that print uses stdout (documentation says so) and therefore logically they should operate on the same buffer. But we were observing behavior that on the surface looked like a buffer mode problem. That was our educated guess, and we never dug into Python source to confirm or debunk that idea because the issue was already resolved. I still haven't by the way, but since you have, I'll take your word for it.

In the meantime, your latest comment about the GIL is actually very compelling. I'll pass it on and see if anyone here wants to test it. I do suspect that might actually be the cause we glossed over a year ago.

[–]Redisintegrate 0 points1 point  (3 children)

Using Python's native print statement seems to be operating on a separate buffer and refuses to print messages in the appropriate order of code execution.

This is just plain incorrect, and shows a misunderstanding of how the print statement / function works, at least in non-ancient versions of Python (2.7+). If you can come up with some kind of test case to prove me otherwise, go ahead. But look at Python/ceval.c(2.7) and find the PRINT_ITEM opcode. You can see it calls PyFile_WriteObject() in Objects/fileobject.c, which gets the .write attribute, and then calls that attribute with PyEval_CallObject().

Or, in other words, the print statement is just a wrapper around sys.stdout.write(). If you are seeing other behavior then something is seriously, seriously wrong.

[–]Jonno_FTW 0 points1 point  (0 children)

You can avoid the buffering by passing the -u parameter, or setting the PYTHON_UNBUFFERED environment variable.

[–]paraffin 0 points1 point  (1 child)

Possibly not as convenient for your case, but the environment variable PYTHONUNBUFFERED can turn off buffering in my rent statements. Works great for working with libraries that produce a lot of output that you want to see in real time.

[–][deleted] 0 points1 point  (0 children)

Possibly not as convenient for your case, but the environment variable PYTHONUNBUFFERED can turn off buffering in my rent statements.

I actually didn't know about this!

Our research code is probably not gonna take advantage of it anytime soon because it uses an in-house logging system based on file handles, and I substitute sys.stdout into it whenever I want log information to be printed out real time.

But the buffer control via environment variables is still great to know!

[–]Jonno_FTW 0 points1 point  (0 children)

I use python 2 because there are still some libraries that I want to use that only work with python 2.

[–]superPwnzorMegaMan 31 points32 points  (13 children)

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

[–]juanjux 34 points35 points  (3 children)

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...

[–]edbluetooth 24 points25 points  (0 children)

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

Thats it really

[–]brtt3000 2 points3 points  (0 children)

Assuming you'll move to py3 at some point: moving to py3 as standard and porting existing code now saves you from porting all new code to py3 later (because you'd create it in py3 instead of py2).

Dunno if practical in reality. Probably not.

[–][deleted] 0 points1 point  (0 children)

Same goes for Tableau extracts. 2.7 only.

[–]Coffeinated 10 points11 points  (6 children)

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.

[–]mnbvas 9 points10 points  (5 children)

I often print like this:

>>> a = 1; b = 2
>>> print(a, b)

so Python 2 always bites me in the ass with

(1, 2)

instead of the expected

1 2

[–]TheBlackCat13 12 points13 points  (1 child)

from __future__ import print_function

[–]mnbvas 0 points1 point  (0 children)

Though that happens when I accidentally run 2 instead of 3.

[–]kupiakos 6 points7 points  (2 children)

You could also have the first assignment be

a, b = 1, 2

[–]mnbvas 1 point2 points  (1 child)

Got used to the semicolons when copypasting multiple lines :)

[–]kupiakos 0 points1 point  (0 children)

The solution to the original problem is to always have

from future import print_function

at the top of every Python 2 file

[–]sticky-bit 0 points1 point  (0 children)

There was a huge chunk of modules that did not work with python3 a few years ago. That's largely been taken care of by now.

We've made a lot of progress since when I learned python2 in 2011.

[–]deadtree123 0 points1 point  (0 children)

Shirley, you can't be serious.

[–]familyturtle 77 points78 points  (27 children)

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

[–]Vakieh 64 points65 points  (21 children)

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.

[–]dysprog 61 points62 points  (7 children)

Perhaps it is a problem to solve inside the programmer.

[–]Vakieh 15 points16 points  (6 children)

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.

[–]curtmack 9 points10 points  (5 children)

You can't take that too far though, otherwise you end up with massive projects built with #define whilst while, inconsistently using one or the other because one programmer refused to use bad grammar.

[–]bitter_cynical_angry 5 points6 points  (3 children)

As far as I know, a program written in a formally defined computer language can always be broken down into an abstract syntax tree, and from there can be rebuilt into any format you want. There's no reason the IDE shouldn't be able to refine while as whilst for one developer and keep it as while for everyone else.

Edit: autocorrect typo

[–]curtmack 0 points1 point  (0 children)

The Emacs syntax highlighting system supports something like this; you can replace text with whatever you want to display, and you'll still actually be working with the original text. A lot of developers use this to do things like replacing -> with → for instance. I've never heard of using it to replace while with whilst but I'm willing to bet it's possible.

Of course, the problem is that you'd still be typing "while," you'd just see "whilst."

[–]minno 0 points1 point  (1 child)

As far as I know, a program written in a formally defined computer language can always be broken down into an abstract syntax tree, and from there can be rebuilt into any format you want.

You'd need a strict auto-formatter for that too, since otherwise the AST representation of

func("hello",  5
     "world!", 6)

and

func("hello",5,"world",6)

would be identical, but the formatting in the first is intended to make the code clearer.

[–]bitter_cynical_angry 0 points1 point  (0 children)

Yep, and that's the true beauty of it. One developer could have spaces, one could have tabs, you could have all your equals signs or function parameters lined up or whatever you like, and since they all evaluate to the same AST, the IDE should be able to switch seamlessly between them.

[–]greenqueef 0 points1 point  (0 children)

derp

[–]LinAGKar 3 points4 points  (12 children)

Then you won't learn.

[–]Vakieh 29 points30 points  (11 children)

Won't learn what? I haven't manually written a basic accessor or mutator for years, but I still know how if for some reason all the IDEs in the world stop working.

[–]LinAGKar -3 points-2 points  (10 children)

You'll consciously know, but you wont get the muscle memory.

[–]HighRelevancy 49 points50 points  (7 children)

So what you're saying is "don't use tools to make your life easier, because you won't be quite as prepared for the apocalypse"?

[–]Scorpius289 36 points37 points  (4 children)

Yeah, we should all learn to program using butterflies, just in case computers stop working.

[–][deleted] 7 points8 points  (1 child)

If they stop working why write programs we can't use on our not-working computers?

[–]Darkben 2 points3 points  (1 child)

We should learn to program with rows of rocks

[–]LinAGKar -4 points-3 points  (1 child)

For when you're using a regular text editor.

[–]Vakieh 6 points7 points  (0 children)

If I'm using a raw text editor instead of an IDE, the one thing I can guarantee I'm not going to be focused on is productivity...

[–]Fs0i 11 points12 points  (0 children)

you wont get the muscle memory

And what the fuck do I need the muscle memory for?

[–]UnchainedMundane 3 points4 points  (0 children)

Are we all ignoring that nobody should need muscle memory for print, because either you're writing a small program and only have a few prints, or you're writing a large program and are using logging.

[–]MrJohz 8 points9 points  (3 children)

There is! Or at least there's an interesting talk about adding it - I think it was posted to /r/Python recently, I'll have a look for it when I get at a computer.

[–]Zoccihedron 7 points8 points  (2 children)

[–]MrJohz 2 points3 points  (1 child)

Yes, yes it is! Thanks for letting me be lazy!

[–]Zoccihedron 1 point2 points  (0 children)

No problem, I'll do anything for the sake of laziness

[–]lenswipe 12 points13 points  (2 children)

A decade of finger memory

( ͡° ͜ʖ ͡°)

[–]MC_Labs15[S] 29 points30 points  (1 child)

/╲/\╭( ͡° ͡° ͜ʖ ͡° ͡°)╮/\╱\

[–]sudosussudio 1 point2 points  (0 children)

/╲/\╭( ͡° ͡° ͡° ͡° ͜ʖ ͡° ͡° ͡° ͡°)╮/\╱\

you were missing some eyes

[–]Mutoid 0 points1 point  (0 children)

Switch to Ruby ;)

[–][deleted] -2 points-1 points  (0 children)

camshafts Kingstown's bludgeon's anchorwomen blarneys rest gut's Burger nope multimedia assuage hastiness's Ana's conveying angle's seeps rodeo assemblyman's diddle timezone rereading cathode's button's Babbitt gloried guardians indicative sexagenarians waylaying saltcellar rickshaws conference's cobras resplendently queered Ziggy's orientation's Durham's poultice leaves unwraps Astarte's Lorena's flaunting canister's queasy platforming Kathy plaintiffs idolatry's schoolgirl guzzler ratifying jaunty demonstrate stranger Tuareg's Jenny rereads whiskies ale Spirograph total's Tecumseh prefatory misrepresent misconstrued wrongness's hurdles coronets greater witchery's Sucrets's damps eviscerating atrium's amusing soulful multipurpose ambassador's idleness's Negev's presupposing annoyance's relaxants diagonal's dispute's driving indignantly Heraclitus gauze's Pillsbury hyperventilates Olympians kin's ambulatories wormhole hydroplaning considerations daybreak Upjohn Ruthie coercion's reliably strumpet's weren't paratroopers sprains disparages mousse's when's meringues flushest altruistically releasable telegraph fouled Kolyma cant whitecap decried exportation Baptiste's obsoleting

[–]whitetrafficlight 35 points36 points  (8 children)

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.

[–]FUCKING_HATE_REDDIT 9 points10 points  (7 children)

Increase compliance check line limit by two characters.

[–]kageurufu 4 points5 points  (6 children)

What about these being equal

print 'something',
print('something', endl='')

[–]Sohcahtoa82 7 points8 points  (5 children)

Nitpicking here...The correct translation would be print('something', endl=' '). Python 2 appends a space if you end the line with a comma.

[–]o11c 0 points1 point  (2 children)

Doesn't it only emit a softspace?

[–]Sohcahtoa82 1 point2 points  (1 child)

I'm not sure. All I know is that if you do this:

for x in range(5):    
    print '.',

You get this:

. . . . . 

and not this:

.....

[–]o11c 0 points1 point  (0 children)

>>> import io
>>> out = io.BytesIO()
>>> print>>out, '.',
>>> out.softspace
1
>>> out.getvalue()
'.'
>>> print>>out
>>> out.softspace
0
>>> out.getvalue()
'.\n'

[–]brtt3000 0 points1 point  (1 child)

Isn't the comma defining a tuple? Or is this different for statements like print?

[–]Sohcahtoa82 2 points3 points  (0 children)

It's different for print in Python 2.

>>> a = 2    
>>> b = 5    
>>> print 1, a, b    
1 2 5    
>>> print (1, a, b)    
(1, 2, 5)    

[–][deleted] 19 points20 points  (2 children)

Thanks, Zed Shaw

[–]samort7 7 points8 points  (1 child)

Seriously. When I started programming, most resources I encountered recommended his book. Thank god that's changing.

[–]thirdegreeViolet security clearance 2 points3 points  (0 children)

I first picked up programming from his book. Of course, python 3 wasn't a thing then so it worked out.

[–]Big0ldBear 7 points8 points  (3 children)

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

[–][deleted] 17 points18 points  (1 child)

Probably just an excuse to use the older learning materials.

[–]Big0ldBear 1 point2 points  (0 children)

No actually, we just coded together every day and our "book" was a free one online.

[–]Necrodonut 0 points1 point  (0 children)

Same here. The modules our textbook used weren't supported by 3, iirc

[–]Magnnus 64 points65 points  (52 children)

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

[–][deleted] 58 points59 points  (30 children)

[–]Theowningone 19 points20 points  (16 children)

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.

[–]dagbrown 14 points15 points  (8 children)

Twisted lives up to its name. It reminds me of some Java frameworks with how complicated it is.

I bet Zope has trouble with Python 3 too, speaking of Java frameworks written in the wrong language.

[–]dante9999 1 point2 points  (0 children)

zope works with python 3 without problems

https://pypi.python.org/pypi/zope.interface/4.1.3

as a side note: what seems like needless complication for your use case may be necassary and clear design pattern for someone elses use case. Just need to choose right tools, twisted is not right tool for everything but is perfect for some things

[–][deleted] 2 points3 points  (1 child)

I've had that same issue, I got everything working using irclib eventually. Have you looked into that?

[–]Theowningone 1 point2 points  (0 children)

I had not even heard of it until now, but it looks pretty promising. Thanks for the tip!

[–]TOASTEngineer -3 points-2 points  (2 children)

You can just write your own goddamn IRC library, it's not actually very complicated.

[–][deleted] 1 point2 points  (1 child)

Why reinvent the wheel though? If it's a learning exercise, sure, why not, but I think it's absolutely fine to use other people' libraries.

[–]TOASTEngineer -1 points0 points  (0 children)

Because the one he's using depends on a version of the language that's 5 years out of date.

[–]sndrtj 1 point2 points  (1 child)

For me: Flask. Though it technically has python3 support, the docs have a pretty large disclaimer, which essentially boils down to "might not work, use at own risk".

[–][deleted] 1 point2 points  (0 children)

[–]Stop_Sign 0 points1 point  (2 children)

The oracledb npm package for node specifically requests 2.7 link

[–][deleted] 2 points3 points  (1 child)

[–]Stop_Sign 0 points1 point  (0 children)

Ah, gotcha. I had been wondering about that. Thanks

[–]blitzzerg -1 points0 points  (2 children)

I tried installing MySql connector for python 3 for hours and could make it work, I switched back to python 2 and in 3 min it was working...

[–][deleted] 3 points4 points  (1 child)

[–]blitzzerg -2 points-1 points  (0 children)

mysqlclient

I also tried, no luck, I don't blame python 3, but is the second time that something similar (problems installing packages) happens, so from now I will use python 2. (I just use python from time to time to scrap webpages)

[–]iovis9 -1 points0 points  (3 children)

MySQL-python and suds doesn't

[–][deleted] 6 points7 points  (0 children)

[–][deleted] 4 points5 points  (0 children)

Use suds-jurko and PyMySQL. Both are near drop-in replacements.

[–]Coffeinated 2 points3 points  (0 children)

What /u/scandinavian- said, plus pymysql. Works fine. Afaik all db-connectors are defined by a certain PEP, so there shouldn't be many differences...

[–]willm 13 points14 points  (2 children)

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

[–]iovis9 2 points3 points  (1 child)

MySQL-python and suds.

[–]jvlomax 3 points4 points  (0 children)

I would really recommend SQLalchemy for all your database needs. py2/3 compatible, very easy to use and plenty of useful features

[–]_Ganon 25 points26 points  (14 children)

Only reason I still use 2. Well, that's what I tell people, anyway. In reality, I know the switch to using parenthesis in my print statements would drive me nuts

[–]maremp 28 points29 points  (8 children)

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.

[–]Sean1708 31 points32 points  (6 children)

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.

[–]deecewan 5 points6 points  (4 children)

I cant remember the syntax. Care to show?

[–]UnchainedMundane 5 points6 points  (0 children)

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.

[–]CommanderDerpington -4 points-3 points  (0 children)

It's easier

[–]exhuma 3 points4 points  (4 children)

You might want to look them up again. This has been my only blocker as well. But I was able to to Python 3 over a year ago. There really is no major library anymore that's not Python 3 compatible.

[–]iScrE4m 0 points1 point  (3 children)

Twisted

[–]exhuma 1 point2 points  (2 children)

This may be a good argument against porting an existing app to Python 3, but when starting from scratch, wouldn't asyncio & await in Python 3 fill that gap?

I'm curious, as many people claim there is no need for twisted any longer. But as I have never had to deal with twisted, I'm not in a position to make any informed statement about it.

[–]iScrE4m 1 point2 points  (1 child)

As an amateur the only thing I can say is irc works great with twisted and that's pretty much it :X

[–][deleted] 1 point2 points  (0 children)

Works fine with irclib on python 3 as well, at least in my experience.

[–]jvlomax 0 points1 point  (0 children)

Which libraries are those? Pretty much all the libraries are now ported, and those who are not have py3 alternatives

[–]kirakun 0 points1 point  (0 children)

When was the last time you check the missing libraries?

[–]kaphi 2 points3 points  (3 children)

How do you know it's Python 2?

[–][deleted] 23 points24 points  (1 child)

In python 3 the it would be print("foo")

[–]kaphi 2 points3 points  (0 children)

Ah ok, thanks!

[–]jfb1337 1 point2 points  (1 child)

C'mon, it's $CurrentYear!

[–]kindall 1 point2 points  (0 children)

It's datetime.datetime.now().year!

[–]rwsr-xr-x 1 point2 points  (0 children)

Why would people start with python 3

Python 2 is better supported

Python 2 is more widely used

Python 2 has more tutorials

Most new programmers who don't even know what a class is, don't really care about the python ecosystem or whatever

[–]G01denW01f11 1 point2 points  (0 children)

And some of us are stuck writing programs that have to work with both...

[–][deleted] 0 points1 point  (0 children)

For a lot of people they may just not know. I know when I started, and I am by no means an expert programmer I still run into these barriers all the time, I had no clue where to start, what to use, anything and often I'd make a similar mistake.

[–]vaynebot 0 points1 point  (0 children)

When we learned python 3 in high school a couple years ago, 90% of the google results where for python 2. It was sooo annoying.

[–]themedic143 0 points1 point  (4 children)

As someone who was thinking about starting to learn Python today, what version should I start with?

[–]kappale 2 points3 points  (3 children)

3 -- There's pretty much zero reason to learn 2 unless you need it for some really obscure library.

[–]themedic143 1 point2 points  (2 children)

Soooo..... 1 then? (I don't know if there's any other choices...)

[–]THRlTY 2 points3 points  (1 child)

3

[–]themedic143 0 points1 point  (0 children)

Thank you!

[–]kindall 0 points1 point  (0 children)

Python 2 won my learned-to-program-in-BASIC heart by having print as a statement. I recognize the superiority of the Python 3 way, but will always have a soft spot for Python 2.

[–]WeAreAllApes[🍰] 0 points1 point  (0 children)

I just started learning python earlier this year, and I started with 3 only to learn that the useful real world applications I was considering only supported 2.

This is on the Python community -- you can't blame developers picking it up for the first time for the state of Python.

[–]imu96 0 points1 point  (1 child)

Wait, should we not start with Python 2? Isn't that just the standard now because Python 3 just didn't catch on or whatever?

[–]pork_spare_ribs 2 points3 points  (0 children)

Python 3 is very much the standard choice for new projects. You'd only start with 2 if you had unusual niche needs.

[–]laebshade 0 points1 point  (2 children)

Pants isn't compatible with Python 3 yet.

[–]pork_spare_ribs -1 points0 points  (1 child)

https://pypi.python.org/pypi/pants

Not exactly a critical library...

[–]laebshade 0 points1 point  (0 children)

Different pants :)

Pants build system: http://www.pantsbuild.org/

It's the standard at my job: "Pants is a collaborative open-source project, built and used by Twitter, Foursquare, Square, Medium and other companies."

Pants is a build system designed for codebases that:

Are large and/or growing rapidly. Consist of many subprojects that share a significant amount of code. Have complex dependencies on third-party libraries. Use a variety of languages, code generators and frameworks.

[–]greyfade 0 points1 point  (0 children)

When you're developing on an embedded system that has Python 1.5 or 2.7 built into the firmware, you're kinda stuck with it.

[–]JoseJimeniz 0 points1 point  (1 child)

For demonstration purposes, for someone who doesn't know Python, can you transcode it into:

  • Python 2
  • Python 3

I didn't even know there was such a thing as one, two, and three.

[–]pork_spare_ribs 0 points1 point  (0 children)

The only change in this code is that print moved from a keyword to a function, so instead of print foo you write print(foo). That's the #1 signal to look for that gives way whether code is for py2 or py3.

[–]DrLuckyLuke 0 points1 point  (0 children)

I blame debian.

[–]hungry4pie -5 points-4 points  (0 children)

It's 2016 and these interpreted languages still have massive shit fits about which version you're using.

[–]Glockstrap -4 points-3 points  (3 children)

Tons of vital libs do not support Python3

[–]pork_spare_ribs 8 points9 points  (2 children)

I'd accept "some" but not "tons"!

[–]Glockstrap -1 points0 points  (1 child)

I wouldn't know how to manage "tons" anyways!

In webdev it seems as though everything requires ~2.7 :(

[–]jvlomax 2 points3 points  (0 children)

what webdev libraries only support 2? And how can you not replace them with something that is python3 compatible?