🐍 Can be run in command prompt.
Create a folder and add a blank __init__.py file in it. This is how a package is created. A package can have a sub-package. Add another folder inside a package and add a blank __init__.py file in it. This is how you create a subpackage.
Add .py file in the package and write a function in the file. Now you can access this function by importing the function from the package in any of your program.
from package_one.subpackage_one import package_subprogram
package_program.main_report()
package_subprogram.sub_report()
print("Hey I am function inside package_program program in package_one package")
print("Hey I am function inside subpackage_program program in subpackage_one package")
Run program.py in command prompt.
Create a folder and add a blank __init__.py file in it. This is how a package is created. A package can have a sub-package. Add another folder inside a package and add a blank __init__.py file in it. This is how you create a subpackage.
Add .py file in the package and write a function in the file. Now you can access this function by importing the function from the package in any of your program.
program.py
from package_one import package_programfrom package_one.subpackage_one import package_subprogram
package_program.main_report()
package_subprogram.sub_report()
package_program.py - Save this file in package_one package/directory
def main_report():print("Hey I am function inside package_program program in package_one package")
subpackage_program.py - Save this file in subpackage_one sub-package/sub-directory
def main_report():print("Hey I am function inside subpackage_program program in subpackage_one package")
Run program.py in command prompt.
Comments
Post a Comment