In Python, a .py file is called a module . (For example, main.py is called the main module)
In order to avoid module name conflicts, Python has introduced a method of organizing modules by directory, called a package (Package ).
There will be a file under each package directory __init__.py
. This file must exist (it will be automatically created when using pycharm to build a package), it can be empty, or it can have code
1. Use the module
A module defined template is as follows:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" This is a test module """
__author__ = ' Jiangbei '
import sys
def test():
args = sys.argv
if len(args) == 1:
print("hello world!")
if __name__ == "__main__":
test()
Line 1/Line 2: Comments, used for direct execution under Linux and specifying encoding respectively
Line 3: Documentation comments, the first string of any module is considered a documentation comment. According to the prompt of pycharm, it is recommended to use triple quotes (triple)
The fourth line: identify the identity, indicate the author. Of course, like other IDEs, the above lines can be automatically generated when creating new ones by setting them as templates (will be introduced in the pycharm tutorial)
The above are the recommended templates