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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:28:38+00:00 2026-06-14T20:28:38+00:00

I am trying to write a program that finds exceptions in a users program

  • 0

I am trying to write a program that finds exceptions in a users program

I have a file called test.py which is :

try:
    # some code to get the name of the calling program
    #Then the code is like "import filename.py" , for example the next line
    import sample.py  # this is what should happen when the file name is got

    execfile("test.py")   # to run this file

catch:
      # catching some exceptions here

now if I assume the user has a file say sample.py which looks like

import test.py

def __main__():
     4/0  # sample exception

I am new to python programming , but I know that python treats all programs as modules , so essentially I envision the program flow to be

1) when the user runs sample.py , the control flow goes to test.py which then gets the name of the calling program and imports it in the try block.

2) the flow then goes back to sample.py and ideally I would like the exception to be encountered and caught

3) but when the control comes back to sample.py it gies back to test.py causing an recursive loop

my question is two fold

1) Is there a way to get the name of a program that has imported your module. also is there a way to get the name of a program that is in the same workspace ( same folder)

2) The reason I have this control flow is I would like the user not to open my program (test.py) , but no matter how I see it , if my module is just imported into his program it will run like a recursive loop , Any suggestions to modify my design to make it work , maybe a third script to get it together?

I am using python 2.7

The strange design pattern is because I do not want the user to write any code to run my program , the max he should be writing is just importing my program

  • 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-14T20:28:40+00:00Added an answer on June 14, 2026 at 8:28 pm

    Okay, so two routes:

    First of all, __name__ contains the name of the module that you have been imported from.

    Secondly, my personal suggestion is distributing a test.pyc or something and asking the person to run that .pyc so that they do not know the contents of test.py

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

Sidebar

Related Questions

I'm trying to write a program that finds strings in a character array and
I'm trying to write a program that finds the respective values latLng for an
So I'm trying to write a program that finds the union, intersection, and determining
I'm trying to write a program that will take an HTML file and make
I'm trying to write a very simple program in C++ that finds the modulus
I have a program that I am trying to write that one row of
I am trying to write a small java program that will accept a file
I'm very new to Python and trying to write a program that parses some
I'm trying to write a program that would find the minimum spanning tree. But
I am trying to write a prolog program that can find the tiles that

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.