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

  • Home
  • SEARCH
  • 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 1097147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:23:21+00:00 2026-05-17T00:23:21+00:00

I have a Python script that uses Python version 2.6 syntax (Except error as

  • 0

I have a Python script that uses Python version 2.6 syntax (Except error as value🙂 which version 2.5 complains about. So in my script I have included some code to check for the Python interpreter version before proceeding so that the user doesn’t get hit with a nasty error, however, no matter where I place that code, it doesn’t work. Once it hits the strange syntax it throws the syntax error, disregarding any attempts of mine of version checking.

I know I could simply place a try/except block over the area that the SyntaxError occurs and generate the message there but I am wondering if there is a more “elegant” way. As I am not very keen on placing try/except blocks all over my code to address the version issue. I looked into using an __ init__.py file, but the user won’t be importing/using my code as a package, so I don’t think that route will work, unless I am missing something…

Here is my version checking code:

import sys
def isPythonVersion(version):
    if float(sys.version[:3]) >= version:
        return True
    else:
        return False

if not isPythonVersion(2.6):
    print "You are running Python version", sys.version[:3], ", version 2.6 or 2.7 is required. Please update. Aborting..."
    exit()
  • 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-17T00:23:21+00:00Added an answer on May 17, 2026 at 12:23 am

    Create a wrapper script that checks the version and calls your real script — this gives you a chance to check the version before the interpreter tries to syntax-check the real script.

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

Sidebar

Related Questions

I have a Python script that uses built-in modules but also imports a number
I have a python script that uses threads and makes lots of HTTP requests.
I have a python script that uses plt.show() as it's last instruction. When it
I have a simple Python script that uses a signal handler for Ctl-C. If
I have a simple Python script that uses the socket module to send a
I have the following simple python test script that uses Suds to call a
I have a python script that runs on a cron job. The script uses
I have a C++ app that uses Python to load some scripts. It calls
I have a python script that runs a program, which generates few .exe files
I have a python script that connects to an external host, fetches some data,

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.