Python Using Different Versions of Python - Compatibility/Dependencies?

  • Thread starter WWGD
  • Start date

WWGD

Science Advisor
Gold Member
4,137
1,726
Hi All,
I am trying to learn versions 2,3 of Python ( long story). Just curious as to the "Dependency/Compatibility" issues between and within versions 2 and 3. Are packages/libraries in 3.x available for 3.x' where x'>x ? How about for version 2? Specifically, at this point, I am trying to do some Web Scraping. If I learn to use it with one version, how likely am I of being able to do the same or similar within an other
 

Borg

Science Advisor
Gold Member
1,809
2,012
I am fairly new to Python also. I chose to go with 3 right away and a lot of examples use 2. However, I haven't had too many issues using version 2 examples with my version 3 code.
 

WWGD

Science Advisor
Gold Member
4,137
1,726
I am fairly new to Python also. I chose to go with 3 right away and a lot of examples use 2. However, I haven't had too many issues using version 2 examples with my version 3 code.
Have you been able to do Web Scraping with more than one version?
 

Borg

Science Advisor
Gold Member
1,809
2,012
Haven't done that. I've been focused on machine learning code.
 

WWGD

Science Advisor
Gold Member
4,137
1,726
Haven't done that. I've been focused on machine learning code.
And you have been able to go back-and-forth between versions?
EDIT: Do you use Graphlab or something else for ML?
 

Borg

Science Advisor
Gold Member
1,809
2,012
I haven't been doing that. I just said that I've had few problems using the version 2 examples in my version 3 environment. BTW, why do you want to use both versions anyway? I could understand if you had a large collection of version 2 code that you built but, if you're as new to Python as I am, you're better off just going with the newer version.
 

WWGD

Science Advisor
Gold Member
4,137
1,726
I haven't been doing that. I just said that I've had few problems using the version 2 examples in my version 3 environment. BTW, why do you want to use both versions anyway? I could understand if you had a large collection of version 2 code that you built but, if you're as new to Python as I am, you're better off just going with the newer version.
I agree, it is just that I have seen jobs that look interesting that require 2 , some require 3. Just covering my bases. I will start with 2 with Anaconda, I guess, in the meantime become familiar with 3 and IDLE. What IDE do you use?
 

Borg

Science Advisor
Gold Member
1,809
2,012
If I saw a job that required version 2, that would tell me that they have a lot of legacy code that they need to maintain. Call me silly but I wouldn't want to be a janitor. :oldtongue:

As for my IDE, I've been coding everything in Jupyter.
 

WWGD

Science Advisor
Gold Member
4,137
1,726
If I saw a job that required version 2, that would tell me that they have a lot of legacy code that they need to maintain. Call me silly but I wouldn't want to be a janitor. :oldtongue:

As for my IDE, I've been coding everything in Jupyter.
Do you have access to Graphlab? SFrames? How do you code, e.g., a regression without them?
 

Borg

Science Advisor
Gold Member
1,809
2,012
Haven't heard of that.
 

WWGD

Science Advisor
Gold Member
4,137
1,726
Haven't heard of that.
So you just code, say a a regression without any additional packages? Sorry if I am being ignorant here, but I have to import other packages before doing any ML
 

Borg

Science Advisor
Gold Member
1,809
2,012
I'm using pip and conda installs to download everything locally. Keep in mind that I'm still learning Python and I'm not dealing with gigantic data sets at this point. My focus is on learning the details of ML algorithms and there's plenty I can do on a laptop for now.
 

WWGD

Science Advisor
Gold Member
4,137
1,726
I'm using pip and conda installs to download everything locally. Keep in mind that I'm still learning Python. I'm not dealing with gigantic data sets at this point. My focus is on learning the details of ML algorithms and there's plenty I can do on a laptop for now.
Ok, I do things in a kind of disorganized way, bottom-up learning from a source, top-down by reading someone else's code and eventually comes together in my brain.
 

WWGD

Science Advisor
Gold Member
4,137
1,726
Sorry, don't mean to drag this too long, but, would you consider any version of Python 3 before the latest, e.g., 3.4 instead of 3.7?
 

Borg

Science Advisor
Gold Member
1,809
2,012
If I needed to. I was using 3.6 for a while.
 
24,312
5,990
Specifically, at this point, I am trying to do some Web Scraping.
I have done web scraping with BeautifulSoup in both Python 2 and Python 3. There isn't much difference between the two. The kind of code you will need to write for web scraping will be pretty much the same in both versions.

 
10,334
3,866
One key difference is the divide operator. In 2 its returns ints if given ints but in 3 it returns floats. You must use the // to integer divides. // is complementary to % for modular math.
 

WWGD

Science Advisor
Gold Member
4,137
1,726
One key difference is the divide operator. In 2 its returns ints if given ints but in 3 it returns floats. You must use the // to integer divides. // is complementary to % for modular math.
Thanks. That also reminds me of the difference between raw input in 2 and input() in 3.
 
10,334
3,866
I would suggest using 3 and not 2 unless the project calls for using 2 for legacy support.
 

WWGD

Science Advisor
Gold Member
4,137
1,726
I would suggest using 3 and not 2 unless the project calls for using 2 for legacy support.
Thanks, but, what then, must one then move on to the next version/generation -- I guess Python 4 -- and so on indefinitely?
 
10,334
3,866
Another was ord() returned the ascii code in 2 whereas in 3 you must use int() i think.
 
10,334
3,866
This is the common issue developers always face ie use the latest or stick with what works. For major changes you have to weight program life with support for version it uses vs upgrading.
 
24,312
5,990
must one then move on to the next version/generation -- I guess Python 4 -- and so on indefinitely?
Eventually, but not on any short time scale. Python 2.7, the last version of Python 2, was first released in 2010; Python 2 itself was first released in 2000; and the Python 2 series is being end of lifed by the core developers in 2020. So you're looking at 10 to 20 years between having to switch versions.
 

FactChecker

Science Advisor
Gold Member
2018 Award
4,722
1,613
This is a philosophical objection I have to Python as a scripting language, versus Perl. The Perl philosophy is "there are many ways to do it" and they try to accept any syntax where they can understand the intent. The Python philosophy seems to be "this is the perfect way to do it and you must comply". That is until the next version comes out and the new philosophy is "this is the new super-duper, perfect way to do it and the old way was TERRIBLE and unacceptable." The Python changes sometimes require rewrites. The changes I needed to make to decades-old Perl scripts were minimal.
 
24,312
5,990
The Python philosophy seems to be "this is the perfect way to do it and you must comply".
This has never been the Python philosophy. The Zen of Python has this:

"There should be one—and preferably only one—obvious way to do it."

Although Tim Peters couldn't resist following that with this:

"Although that way may not be obvious at first unless you're Dutch."

But in any case, nothing requires you to do it the obvious way.

[1] https://en.wikipedia.org/wiki/Zen_of_Python

That is until the next version comes out and the new philosophy is "this is the new super-duper, perfect way to do it and the old way was TERRIBLE and unacceptable."
Within a given Python version (2 or 3), I'm not aware of any change that made a previous way to do it no longer doable. Plenty of changes opened up new ways to do things, but those never invalidated the old ways.

The Python 2 to Python 3 change certainly did break a lot of old ways of doing things, but that was on purpose and the Python devs were quite open about that for years in advance. Also, Python 2 has stayed around and fully supported for 10 years while Python 3 was refined.

The Python changes sometimes require rewrites.
Do you have an example within a single Python version (2 or 3)?
 

Want to reply to this thread?

"Using Different Versions of Python - Compatibility/Dependencies?" You must log in or register to reply here.

Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving
Top