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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T02:33:36+00:00 2026-06-19T02:33:36+00:00

I am working on Python 2.6/2.7 code which contains the following: try: import gmpy

  • 0

I am working on Python 2.6/2.7 code which contains the following:

try:
    import gmpy
    gmpy_imported=True
except ImportError:
    gmpy_imported=False

if gmpy_imported and gmpy.__file__ is None:
    gmpy_imported=False

I can understand the try-except part, which is used to see if gmpy has been installed on the system — and if not, to do whatever. However, I do not understand why the if gmpy.__file__ is None check is necessary; it seems redundant.

Are there any circumstances when importing a package would appear to have succeeded, but the path to the package would in fact be empty? Is this double-check a failsafe against a corrupted installation?

  • 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-06-19T02:33:37+00:00Added an answer on June 19, 2026 at 2:33 am

    There’s no point in this check. If the module/package had been successfully been imported, __file__ would never be none, it’d be the path of the module.

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

Sidebar

Related Questions

I'm working in Python. I have the following code: while not is_suffix(pattern[:k], pattern[:q]): k
i am using python 2.5.2 . The following code not working. def findValue(self, text,
Working with Python in Emacs if I want to add a try/except to a
I currently have a working python code which generates a 2D animation of a
I've been working in Python with an array which contains a one-dimensional list of
I am working on a little python code which parses the response from the
I'm working on some Python code modeled on Apache's MPM prefork server. I am
I'm working on a simple GUI code editor in Python, and I want to
I'm working some code that inserts csv rows into an SQLite database using Python.
At runtime, the Python code gets the name of a submodule to load, which

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.