filmov
tv
How to Import a Python Function from Another File

Показать описание
Learn how to import a Python function from a different file than the one where your main application is coded.
This is a standard practice that allows defining common functions in a single file or module that can then be used by multiple Python programs using the import statement.
In this CodeFatherTech Python tutorial, we will also see the difference between "import {module}" and "from {module} import {function}".
And finally, we will use the Python sys module to add the absolute path where our functions file is located to the Python path.
---------- CHAPTERS ----------
(00:00:00) Create a sample Python program to explain the concepts related to Python import.
(00:01:16) Refactor the initial code using a function.
(00:02:30) Create a new Python file that will contain all the functions used by our program.
(00:03:00) Show how to use the Python import statement.
(00:04:25) Show how to use from ... import to import a specific Python function from another file.
(00:05:40) Import functions from a different file that is not in the same directory as your Python program.
Also, after watching this tutorial let's build a cool game together in Python to keep improving your Python knowledge:
Enjoy this tutorial and learn how to import a Python function from another file!
Claudio
#PythonProgramming #PythonTutorial #PythonForBeginners #CodeFatherTech
This is a standard practice that allows defining common functions in a single file or module that can then be used by multiple Python programs using the import statement.
In this CodeFatherTech Python tutorial, we will also see the difference between "import {module}" and "from {module} import {function}".
And finally, we will use the Python sys module to add the absolute path where our functions file is located to the Python path.
---------- CHAPTERS ----------
(00:00:00) Create a sample Python program to explain the concepts related to Python import.
(00:01:16) Refactor the initial code using a function.
(00:02:30) Create a new Python file that will contain all the functions used by our program.
(00:03:00) Show how to use the Python import statement.
(00:04:25) Show how to use from ... import to import a specific Python function from another file.
(00:05:40) Import functions from a different file that is not in the same directory as your Python program.
Also, after watching this tutorial let's build a cool game together in Python to keep improving your Python knowledge:
Enjoy this tutorial and learn how to import a Python function from another file!
Claudio
#PythonProgramming #PythonTutorial #PythonForBeginners #CodeFatherTech
Комментарии