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 403231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:11:52+00:00 2026-05-12T17:11:52+00:00

Today I tried using pyPdf 1.12 in a script I was writing that targets

  • 0

Today I tried using pyPdf 1.12 in a script I was writing that targets Python 2.6. When running my script, and even importing pyPdf, I get complaints about deprecated functionality (md5->hashsum, sets). I’d like to contribute a patch to make this work cleanly in 2.6, but I imagine the author does not want to break compatibility for older versions (2.5 and earlier).

Searching Google and Stack Overflow have so far turned up nothing. I feel like I have seen try/except blocks around import statements before that accomplish something similar, but can’t find any examples. Is there a generally accepted best practice for supporting multiple Python versions?

  • 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-12T17:11:52+00:00Added an answer on May 12, 2026 at 5:11 pm

    There are two ways to do this:


    (1) Just like you described: Try something and work around the exception for old versions. For example, you could try to import the json module and import a userland implementation if this fails:

    try:
        import json
    except ImportError:
        import myutils.myjson as json
    

    This is an example from Django (they use this technique often):

    try:
        reversed
    except NameError:
        from django.utils.itercompat import reversed     # Python 2.3 fallback
    

    If the iterator reversed is available, they use it. Otherwise, they import their own implementation from the utils package.


    (2) Explicitely compare the version of the Python interpreter:

    import sys
    if sys.version_info < (2, 6, 0):
        # Do stuff for old version...
    else:
        # Do 2.6+ stuff
    

    sys.version_info is a tuple that can easily be compared with similar version tuples.

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

Sidebar

Related Questions

I tried using PHPDoc for the first time today and quickly ran into a
I tried using actors in a small scala (2.8) app on android (2.1) today
I've tried using du to calculate disk usage today on a single directory. The
Today I was working on a tab navigation for a webpage. I tried the
Today, I ran into this weird problem with a user using Mac OS X.
Today I was listening to the Hanselminutes show about .NET 3.5 SP1...What's inside ,
Today I discovered that my fresh installation of Apache HTTP Server is able to
Today I stumbled about a Problem which seems to be a bug in the
Today when I was in computer organization class, teacher talked about something interesting to
Today I had a discussion with a colleague about nested functions in Javascript: function

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.