Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 643405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:16:44+00:00 2026-05-13T21:16:44+00:00

I’d like to make it as general as possible – e.g. handle as many

  • 0

I’d like to make it as general as possible – e.g. handle as many versions as possible.

Since version 3 is not backwards compatible with version 2, I want to make sure that I use the right print statement.

Please let me know if you have questions and feel free to share related knowledge having to do with dynamic logic based on what (e.g. libraries) is available.

Suppose I have a script that will run under version 1.x, or 2.x, or 3.x only.

Or a script which requires a library A or a library B.

Thanks!

EDIT:

Now … when it comes to Python (unlike .Net) some libraries like SciPy, Google App Engine keep you glued to particular version. On Linux, Mac Os you can switch between different Python installs on command line. This is why I want to avoid confusion – I want to remember which script is for which version of Python and what libraries it needs. I would rather have it fail in a human-readable way.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T21:16:45+00:00Added an answer on May 13, 2026 at 9:16 pm
    • If you want to maintain a codebase that works with Python 2 and 3, you wouldn’t try to make code that will run in both, which will be awkward and ugly and bugprone, you would write in Python 2 and use 2to3 to convert. (You can also write in Python 3 and use 3to2 to convert, but I believe that tool is less mature.) 2to3 is not perfect, but making Python 2 code that can be converted by it makes tons more sense than making Python 2 code that will run in a Python 3 interpretter. Edit: This was common wisdom in 2010, but turned out not to be the case. The thing to do is write a polyglot. 2to3 did not end up being all that useful

    • Another option is Cython, a Python-like language that can be used to create C extension modules. Cython modules can be used with Python 2 and 3.

    • When you support multiple versions of Python, it is generally better to directly check for the capability you want rather than to check a version number. Checking version numbers directly is fragile and indirect.

      For example, if I wanted code that would work with Python pre-2.5, I would say:

      try: 
          any
      except NameError:
          def any(iterable):
              for item in iterable:
                  if item:
                      return True
              return False
      

      (note that this is prettymuch the only reason to catch NameError). Similarly, library availability would be checked by catching ImportError. Edit: There is a tons of tooling for abstracting this away by now.

    • If you want a script to remember what version it is from, like you say, don’t bother trying to support multiple versions at all. Put the proper version number binary in the shebang line and run the script based on that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I've got a string that has curly quotes in it. I'd like to replace
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have some data like this: 1 2 3 4 5 9 2 6
I have a JSP page retrieving data and when single or double quotes are
I have text I am displaying in SIlverlight that is coming from a CMS
I used javascript for loading a picture on my website depending on which small
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.