Python beginner, for the guide package tangled a lot of time, summed up sharing, continuous progress ~
Two ways to guide the Python package:
1.1 from Package. Module Import method name, directly using method name () when invoked
1.2 from package. Module Import class name, which is invoked directly using the class name (). Method name (), that is, the method is called directly through the object
2.1 Import package. The module name is called when the absolute path is added , package. Module. Method Name ()
2.2 Import package. The module name is called when the absolute path is added, the package. Module. Class name (). Method Name ()
There are function1 function2 methods in the test, Class_1 and class_2 are class definitions, and the methods in Function1 and function2 are called separately in the following:
#import导包
Import test.function_2
Import Test.class_1
Def func_1 ():
Print ("Function 1")
Test.function_2.func_2 ()
Test.class_1.test_class_1 (). Class_func_1 ()
#from Import Guide Package
From test.function_2 import func_2
From Test.class_1 import class_func_1
Def func_1 ():
Print ("Function 1")
Func_2 ()
Test_class_1 (). Class_func_1 ()
If you want to call methods between classes, you can also inherit
From test.class_2 import test_class_2 #导包
Class Test_class_1 (test_class_2): #继承
def class_func_1 (self):
Print ("Function of Class 1")
Test_class_2 (). class_func_2 () #对象. Method
Python Guide Pack Learning Summary