Skip to content

Python call function from another file without import

  • by

Without any import module calling function from another file is not possible in Python. But what you can do is, import a module, and call a function of a submodule of that module. Like this:

import tmpapp
def kakikomi(request):
    f = tmpapp.forms.KakikomiForm()

Python call function from another file without import

Simple example code Call function from another file without import clause.

some_module.py

# Somewhere in some_module.py
def print_args(*argv):
for v in argv:
print("some_module", v)

main.py

import some_module


def foo():
f = some_module.print_args("Hello")


foo()

Output:

Python call function from another file without import

Do comment if you have any doubts or suggestions on this Python function topic.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Your email address will not be published. Required fields are marked *