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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:33:32+00:00 2026-06-12T07:33:32+00:00

How can i pass many variables to a function in a different file? I

  • 0

How can i pass many variables to a function in a different file?

I noticed that some files only have functions (they are grouped in individual files). For example, one file to control install (that has function for new installs, update installs, etc…) , other to grant access (create new user, delete user, update user).And those functions receive a quite amount of vars , as an example:

access_tool.add_user(cur,con,env,family,iserver,version,login,
                           password,prefix,proxyUser,proxyPass,
                           proxyServer,user,pass)

So, the access_tool( the file ) and the function ( get_add_info ) receives those vars from another file, and those vars are dynamic (results from database query). How can I pass those values to a function in a different file elegantly?

Example:

We have 2 important files:

  1. a.properties – Which contains database info and credentials
  2. mainfile.py – Main file, called to execute functions for example:
    • add-user ENV newuser newuserpass

The add-user calls a function from the file access_tool.py called add_user.

What mainfile.py does is (for this example of user creation ) depending on the environment sent through the input, it will do a query into the database to select the X servers to add the user and it will store the result into the vars ( to be used into a array loop ):

cur,con,env,family,iserver,version,login,password,prefix,proxyUser,proxyPass,proxyServer

So, those vars will receive from loop, 5 , 10 or more servers to add. The only variables that is static is newuser, and newuserpass (wich receives from the input )

The only problem I have is to make a decision about how I can pass (or share ) the variables to a function on another file.

Some people from work suggest that i keep all of then at the same file, and instead of having many files for each class, just have one file with all the classes.

  • 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-12T07:33:33+00:00Added an answer on June 12, 2026 at 7:33 am

    The concept of files in Python is vague. The phrase ‘variable from a file` doesn’t mean anything. You must be aware of how these vars are instantiated and what is their scope.

    Values in Python do not live in files, they live in memory, and are pointed to by variables.

    For functions that take a lot of parameters, it is common to use named arguments:

    def fun(**args):
      param1 = args.get('param1', 'default_value')
      param2 = ... # etc
    
    fun(param1='val1', param2 = 'val2')
    

    Which might be the elegance you are looking for 🙂

    So your code may look like this:

    def main():
      #initialization 
      import access_tool
      con = database_connection()
      servers = query_database_for_servers()
    
      for server in servers:
        #assume server is a dict of values
        access_tool.add_user ( **server )
    

    And your add_user function may be modified like this:

    def add_user ( **params ):
       # connect to params['server'] using params['env']
       # and add user with other params[]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way that I can pass arguments in selector? example: I have
I'd like to do some stuffs before main function. I have multiple source files.
I'm building a search page that will have many different search parameters that the
I have a function with many input parameters, and I need a function that
In JSF 2 you can pass around ids, Strings other things that can be
I know you can pass arguments through the RunWorkerAsync function call when you first
I know that I can pass a string as the second parameter to the
During a search you can pass some data to search manager by using the
If I have a auto_ptr I can pass it for a reference?Like: auto_ptr<MyClass>Class(new MyClass);
I know from here that I can pass an ignore option in the jQuery.validate

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.