Generally when you create files to be imported you must use if __name__ == '__main__' which evaluates to false in case you are importing the file from another file. So your hi.py may look as:

def me(string):
    print(string)

if __name__ == '__main__':
    # Do some local work which should not be reflected while importing this file to another module.
    me('hello')
Answer from ZdaR on Stack Overflow
🌐
Problem Solving with Python
problemsolvingwithpython.com › 07-Functions-and-Modules › 07.05-Calling-Functions-from-Other-Files
Calling Functions from Other Files - Problem Solving with Python
Note that although the file name must contain a .py extension, .py is not used as part of the filename during import. The general syntax to import and call a function from a separate file is below: from function_file import function_name function_name(arguments)
Discussions

How to call a python file with arguments from another python file?
Here you go - https://www.tutorialspoint.com/How-can-I-make-one-Python-file-run-another More on reddit.com
🌐 r/learnpython
2
2
January 9, 2022
python - How do I call a function from another .py file? - Stack Overflow
And if that file have functions, def xyz(): -------- -------- def abc(): -------- -------- In the calling function you just have to type the below lines. ... I don't know if my fail is about python versions. What i do choosing this example is import fn (without extension) and using them directly ... More on stackoverflow.com
🌐 stackoverflow.com
Call function with argument in another Python file - Stack Overflow
Then I call it in another python file named out.py ... Text has no value rn . ... Also it should do this dump_text(get_text('some value')). Otherwise you'll have to save the value into a global and use that. ... In your file 'out.py' you're using variable named test which is not defined, do any of the following way. Either define variable named 'text' and assigned some data (string). from ... More on stackoverflow.com
🌐 stackoverflow.com
August 21, 2020
Call function inside function in another file

This is where arguments in functions are used.

If you want your create_table to be able to be used with different configs, then it needs to accept the config function as an argument.

def create_table(config_func):
    config_func(config_name)
    ...

Or the config itself as dictionary.

def create_table(config):
    table = config['table']
    delimiter = config['delimiter']

create_table({'table': True, 'delimiter': ";"})
More on reddit.com
🌐 r/learnpython
5
1
July 8, 2021
People also ask

How do I call a function defined in another Python file?
Put both files on the same import path (usually the same directory or a package), then use from module import function or import module and call module.function; Python must be able to resolve the module name when you run the entry script.
🌐
golinuxcloud.com
golinuxcloud.com › home › programming › python › python call function from another file
Python Call Function from Another File: Same Folder, Different ...
Why do I get ModuleNotFoundError when importing my own file?
Usually the current working directory or package layout is wrong, the filename does not match the module name, a parent directory is missing from sys.path, or you run a module inside a package without the -m flag so relative imports break.
🌐
golinuxcloud.com
golinuxcloud.com › home › programming › python › python call function from another file
Python Call Function from Another File: Same Folder, Different ...
What does importlib.import_module do?
It is the supported programmatic API around Python’s import machinery: you pass a dotted module name as a string and get a module object back, equivalent to an import statement at runtime without hard-coding the name in source.
🌐
golinuxcloud.com
golinuxcloud.com › home › programming › python › python call function from another file
Python Call Function from Another File: Same Folder, Different ...
🌐
GoLinuxCloud
golinuxcloud.com › home › programming › python › python call function from another file
Python Call Function from Another File: Same Folder, Different Directory (2026)
June 20, 2026 - Calling looks the same as a normal function—arguments are passed at the call site in main.py; the imported function is defined with parameters in the other file. ... Treat your code as a package: a directory that contains modules and is reachable ...
🌐
Reddit
reddit.com › r/learnpython › how to call a python file with arguments from another python file?
r/learnpython on Reddit: How to call a python file with arguments from another python file?
January 9, 2022 -

I have a file that collects data on a website given a URL. Using command line, I call call this file as:

python data_collector.py url

Now, I would like to capture this same functionality, but in another python script. I know I can import the file as a module and use the functions, but is it possible (or even useful) to simply call it in another file as if I were using command line and return the results? If so, is this an efficient manner of doing things?

🌐
Ubc
clouds.eos.ubc.ca › ~phil › docs › problem_solving › 07-Functions-and-Modules › 07.05-Calling-Functions-from-Other-Files.html
Calling Functions from Other Files
The general syntax to import and call multiple functions from the same file is below: from function_file import function_name1, function_name2 function_name1(arguments) function_name2(arguments) An example using this syntax with the myfunctions.py ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-call-function-from-another-file
Python - Call function from another file - GeeksforGeeks
In the above program, functions defined in test.py and calc.py are called in a different file which is file.py.
Published: August 21, 2024
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 63516392 › call-function-with-argument-in-another-python-file
Call function with argument in another Python file - Stack Overflow
August 21, 2020 - Then I call it in another python file named out.py ... Text has no value rn . ... Also it should do this dump_text(get_text('some value')). Otherwise you'll have to save the value into a global and use that. ... In your file 'out.py' you're using variable named test which is not defined, do any of the following way. Either define variable named 'text' and assigned some data (string). from words import * test = 'sample text string' dump_text(text)
🌐
Reddit
reddit.com › r/learnpython › call function inside function in another file
r/learnpython on Reddit: Call function inside function in another file
July 8, 2021 -

Hi

I have two function in functions.py file:

def config(name): 
   if name == "presentation":
      table = True
      delimiter = ";"


def create_table():
...
   name = client.get_bucket()
   config(name)
...

It works. But What I need is only create_table in a functions.py file, and call it in multiple python files with their own config(name) file1.py... file2.py.

I tried this: from functions.create_table import create_table

but the function depends only of config() function inside functions.py

🌐
Codingem
codingem.com › home › how to call functions in python: a complete guide (examples)
How to Call Functions in Python: A Complete Guide (Examples)
November 5, 2022 - If you do this, remember to unpack the dictionary with the double-asterisk **: ... To call a function from another Python file, you need to import the file and call the functions from it.
🌐
Reddit
reddit.com › r/learnpython › how do i call a function from several different .py scripts ?
r/learnpython on Reddit: How do I call a function from several different .py scripts ?
February 1, 2024 -

Say I am making a project and the main program imports a module B which contains functions to extract data from a document file.

Then, the functions in module B will call functions C, D or E depending on the type of file (docx, pdf, txt). The code for these functions is quite long and quite different, so I have written a seperate .py script for each, and imported these into module B

my question is this:

From C, D or E, I might want to call another function F.

Where should I put function F? In module B? In another .py module? Do I need to import it into C, D and E? I'm guessing I can't as that would be a circular import?

thanks for advice .

🌐
Medium
medium.com › @codingcampus › python-call-a-function-from-another-file-c41b9502ce70
Python — call a function from another file | by CodingCampus | Medium
November 23, 2023 - As a Python programmer, you may want to call a function from another file in Python. By doing so, you do not have to rewrite your code or copy it into your existing code base. We will use Python 3.10.4 with Visual Studio Code as our code editor for this guide.
🌐
Finxter
blog.finxter.com › home › learn python blog › how to call a function from another file in python?
How to Call a Function from Another File in Python? - Be on the Right Side of Change
June 2, 2021 - I’ll call my file “myfunctions.py”. ... Save the file. Now to call a function from another file in Python, we simply use “import” followed by the filename of your .py file:
🌐
McNeel Forum
discourse.mcneel.com › scripting
How to call function from another python file - Scripting - McNeel Forum
July 4, 2024 - Hi all, This is probably a dumb question. I’m making a test project through Script Editor in Rhino 8. There are only 2 py files in the same folder. #! python3 # m1.py def main(): print("Hello I'm m1") main() #! python3 # m2.py import m1 def main(): m1.main() main() What m2 does is call m1.main(), and it works well in Script Editor.
🌐
Dive into Python
diveintopython.org › home › learn python programming › functions in python › ways to import functions
Examples of Ways to Import Functions in Python from Another Files
May 3, 2024 - There are several ways to import multiple functions in Python. One way is to define functions in a separate file and then import them into the main script using the import function from file syntax.
🌐
YouTube
youtube.com › watch
How to Call a Function from Another File in Python? - YouTube
Full Tutorial: https://blog.finxter.com/how-to-call-a-function-from-another-file-in-python/Email Academy: https://blog.finxter.com/email-academy/►► Do you wa
Published: June 2, 2021
🌐
Edureka Community
edureka.co › home › community › categories › python › how to call a function from another file in...
How to call a function from another file in Python | Edureka Community
June 24, 2020 - Hi Guys, I have one function in a python file. I want to use this function in a different ... can I call a function from another file in python?
🌐
Tutorials24x7
tutorials24x7.com › python › run-another-python-script-with-arguments-in-python-for-optimal-execution
Run Python scripts with arguments for optimal execution. Learn how.
April 29, 2024 - There are three approaches to run ... script using the subprocess module. Here, you can use the subprocess.run function to execute the called_script.py script from caller_script.py and pass arg1, arg2, and arg3 (arguments) as command-line arguments while calling the script...