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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:11:22+00:00 2026-05-23T03:11:22+00:00

First I do know about ‘import’. When I try ‘import’ it doesn’t work. What

  • 0

First I do know about ‘import’. When I try ‘import’ it doesn’t work. What I’m trying to do is split a single module into two parts, one of which is editable by a group and the other of which is not. I want the group to write well-defined ‘retrieval functions’ without the temptation or ability to edit the backend code that runs them (even accidentally). The changes in namespace on an ‘import’ are getting in my way. I’m looking for a macro-style inclusion of File_A’s text within File_B, to be run inline as if it were part of File_B.

This is what I’m doing:

I have some generalized code that is designed to call a list of information retrieval functions in turn, and store the info in a unified way. To do this I add its text name to a list:

DataTypes = ['TypeA','TypeB','TypeC']

… and then define a function that knows how to get each type, and returns a populated object class:

def Get_TypeA:
    # do some stuff to retrieve info
    InfoObj Data
    # Populate Data with the info I got
    return Data

def Get_TypeB:
    # etc. etc.
    return Data
def Get_TypeC:
    # etc. etc.
    return Data

# Backend code below this line, hopefully nobody touches it?
# (But really it would be best if this was in a different file
#  that is harder to mess with and has locked-down permissions.)
class InfoObj:
    # stuff stuff definitions methods etc.

These functions will be edited by people with only a basic knowledge of Python but often bad coding habits, but who need to be able to frequently customize what is gathered and displayed. I already have a backend that checks the list and calls the functions, but I just want to move those definitions into a separate file from the rest of the backend code, but work as if they were right there inline. (i.e. turn the “hopefully nobody touches it” into a “people have to go out of their way to touch it”)

Does Python have this?

When I try using Import, the retrieval functions lose contact with the definition of InfoObj. This happens whether I use ‘import otherFile’ or ‘from otherFile import *’.

EDIT: This is what I’m using to retrieve the various types in a standard way:

THISMODULE = sys.modules[__name__]

for type in DataTypes:
    RetrievalFn = getattr( THISMODULE, 'Get_'+type )
    Data = RetrievalFn()
    StoreInDB(Data)

(though this is boiled down to basics, there are try/except clauses, validation steps to make sure Data was populated correctly and doesn’t contain incorrect types or bad stuff, and code to notify the team if and where something breaks but still process the rest of the items. The goal is that someone making edits does not break the rest of the checks, even if their edits broke one of the checks.)

  • 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-23T03:11:22+00:00Added an answer on May 23, 2026 at 3:11 am

    This can be done with execfile(), but you should consider using some other mechanism for this instead such as polymorphism or plugins.

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

Sidebar

Related Questions

First, yes I know about this question , but I'm looking for a bit
First, I know about this: How would you organize a Subversion repository for in
First of all, I know about the command line parameter, but I don't want
First question on here so please be nice :) I know very little about
First off, I know next to nothing about language theory, and I barely know
first of all let me say that I know about dynamic, no PIA, named
First of all, I do know about the Fisher-Yates shuffle. But lets say for
FIRST: Yes, I know about CONCATENATE and CONTINUEIF, but I might not be smart
First, I know about Clog , and I do not want to implement this
First, let me admit that what I know about HTTPS is pretty rudimentary. I

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.